From 8eb12cb659b7eca2d5cfbd3abd027302534bd1ee Mon Sep 17 00:00:00 2001 From: "Hung-Han (Henry) Chen" Date: Thu, 2 Sep 2021 12:17:29 +0300 Subject: [PATCH] Check only webcontent type === 'window' instead of using webContents.getFocusedWebContents(), as other webview can capture focus Signed-off-by: Hung-Han (Henry) Chen --- src/renderer/components/layout/topbar.tsx | 4 ++-- .../remote-helpers/history-updater.ts | 22 +++++++++++++++++-- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/renderer/components/layout/topbar.tsx b/src/renderer/components/layout/topbar.tsx index 2b1c49267a..404a4fec7d 100644 --- a/src/renderer/components/layout/topbar.tsx +++ b/src/renderer/components/layout/topbar.tsx @@ -69,11 +69,11 @@ export const TopBar = observer(({ children, ...rest }: Props) => { }; const goBack = () => { - webContents.getFocusedWebContents()?.goBack(); + webContents.getAllWebContents().find((webContent) => webContent.getType() === "window")?.goBack(); }; const goForward = () => { - webContents.getFocusedWebContents()?.goForward(); + webContents.getAllWebContents().find((webContent) => webContent.getType() === "window")?.goForward(); }; useEffect(() => { diff --git a/src/renderer/remote-helpers/history-updater.ts b/src/renderer/remote-helpers/history-updater.ts index 3a8c9bfc04..77f26496dc 100644 --- a/src/renderer/remote-helpers/history-updater.ts +++ b/src/renderer/remote-helpers/history-updater.ts @@ -26,7 +26,25 @@ import { navigation } from "../navigation"; export function watchHistoryState() { return reaction(() => navigation.location, () => { - broadcastMessage("history:can-go-back", webContents.getFocusedWebContents()?.canGoBack()); - broadcastMessage("history:can-go-forward", webContents.getFocusedWebContents()?.canGoForward()); + const getAllWebContents = webContents.getAllWebContents(); + + const canGoBack = getAllWebContents.some((webContent) => { + if (webContent.getType() === "window") { + return webContent.canGoBack(); + } + + return false; + }); + + const canGoForward = getAllWebContents.some((webContent) => { + if (webContent.getType() === "window") { + return webContent.canGoForward(); + } + + return false; + }); + + broadcastMessage("history:can-go-back", canGoBack); + broadcastMessage("history:can-go-forward", canGoForward); }); }