1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

Check only webcontent type === 'window' instead of using webContents.getFocusedWebContents(), as other webview can capture focus

Signed-off-by: Hung-Han (Henry) Chen <chenhungh@gmail.com>
This commit is contained in:
Hung-Han (Henry) Chen 2021-09-02 12:17:29 +03:00
parent 56c35da046
commit 8eb12cb659
No known key found for this signature in database
GPG Key ID: 54B44603D251B788
2 changed files with 22 additions and 4 deletions

View File

@ -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(() => {

View File

@ -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);
});
}