From 5387b200e6d348ea8e3b47082c99d768b60f2a8d Mon Sep 17 00:00:00 2001 From: Sebastian Malton Date: Wed, 26 Jan 2022 14:45:32 -0500 Subject: [PATCH] Revert top bar changes, switch to nativeWindowOpen=true Signed-off-by: Sebastian Malton --- .../init-ipc-main-handlers.ts | 7 ++-- src/main/window-manager.ts | 5 ++- .../components/layout/top-bar/top-bar.tsx | 32 +++++++++++-------- 3 files changed, 25 insertions(+), 19 deletions(-) diff --git a/src/main/initializers/init-ipc-main-handlers/init-ipc-main-handlers.ts b/src/main/initializers/init-ipc-main-handlers/init-ipc-main-handlers.ts index c48d807f7f..2986d3319e 100644 --- a/src/main/initializers/init-ipc-main-handlers/init-ipc-main-handlers.ts +++ b/src/main/initializers/init-ipc-main-handlers/init-ipc-main-handlers.ts @@ -150,13 +150,12 @@ export const initIpcMainHandlers = ({ electronMenuItems, directoryForLensLocalSt ipcMainOn(windowOpenAppMenuAsContextMenuChannel, async (event) => { const menu = Menu.buildFromTemplate(getAppMenu(WindowManager.getInstance(), electronMenuItems.get())); - const options = { + + menu.popup({ ...BrowserWindow.fromWebContents(event.sender), // Center of the topbar menu icon x: 20, y: 20, - } as Electron.PopupOptions; - - menu.popup(options); + }); }); }; diff --git a/src/main/window-manager.ts b/src/main/window-manager.ts index 0880f392dc..903c9d8525 100644 --- a/src/main/window-manager.ts +++ b/src/main/window-manager.ts @@ -74,6 +74,7 @@ export class WindowManager extends Singleton { nodeIntegrationInSubFrames: true, webviewTag: true, contextIsolation: false, + nativeWindowOpen: true, }, }); this.windowState.manage(this.mainWindow); @@ -131,7 +132,8 @@ export class WindowManager extends Singleton { // Always disable Node.js integration for all webviews webPreferences.nodeIntegration = false; - }).setWindowOpenHandler((details) => { + }) + .setWindowOpenHandler((details) => { shell.openExternal(details.url); return { action: "deny" }; @@ -247,6 +249,7 @@ export class WindowManager extends Singleton { nodeIntegration: true, contextIsolation: false, nodeIntegrationInSubFrames: true, + nativeWindowOpen: true, }, }); await this.splashWindow.loadURL("static://splash.html"); diff --git a/src/renderer/components/layout/top-bar/top-bar.tsx b/src/renderer/components/layout/top-bar/top-bar.tsx index 73dc39c6b4..dc801a5424 100644 --- a/src/renderer/components/layout/top-bar/top-bar.tsx +++ b/src/renderer/components/layout/top-bar/top-bar.tsx @@ -20,7 +20,6 @@ import { withInjectables } from "@ogre-tools/injectable-react"; import type { TopBarRegistration } from "./top-bar-registration"; import { emitOpenAppMenuAsContextMenu, requestWindowAction } from "../../../ipc"; import { WindowAction } from "../../../../common/ipc/window"; -import { useToggle } from "../../../hooks"; interface Props extends React.HTMLAttributes {} @@ -40,16 +39,10 @@ ipcRendererOn("history:can-go-forward", (event, state: boolean) => { }); const NonInjectedTopBar = (({ items, children, ...rest }: Props & Dependencies) => { - const [isAppContextMenuOpen, toggleIsAppContextMenuOpen] = useToggle(false); const elem = useRef(); - const toggleAppContextMenu = () => { - toggleIsAppContextMenuOpen(); - - if (!isAppContextMenuOpen) { - // This is done when the current value is false as that is the rising edge - emitOpenAppMenuAsContextMenu(); - } + const openAppContextMenu = () => { + emitOpenAppMenuAsContextMenu(); }; const goHome = () => { @@ -92,8 +85,12 @@ const NonInjectedTopBar = (({ items, children, ...rest }: Props & Dependencies)
{(isWindows || isLinux) && (
-
- +
+ + + + +
)} @@ -125,12 +122,19 @@ const NonInjectedTopBar = (({ items, children, ...rest }: Props & Dependencies) {(isWindows || isLinux) && (
-
+ + + +
- + + +
- + + +
)}