diff --git a/apps/desktop/src/window/DesktopApplicationMenu.test.ts b/apps/desktop/src/window/DesktopApplicationMenu.test.ts index 612ec441ba99b..9d4e26f64d515 100644 --- a/apps/desktop/src/window/DesktopApplicationMenu.test.ts +++ b/apps/desktop/src/window/DesktopApplicationMenu.test.ts @@ -83,7 +83,7 @@ const layerDesktopWindow = (selectedAction: Deferred.Deferred) => createMain: Effect.die("unexpected createMain"), ensureMain: Effect.die("unexpected ensureMain"), revealOrCreateMain: Effect.die("unexpected revealOrCreateMain"), - activate: Effect.void, + activate: Deferred.succeed(selectedAction, "activate").pipe(Effect.asVoid), createMainIfBackendReady: Effect.void, showConnectingSplash: Effect.void, handleBackendReady: () => Effect.void, @@ -205,6 +205,30 @@ describe("DesktopApplicationMenu", () => { }), ); + it.effect("reopens the main window from File > Open Window on macOS", () => + Effect.gen(function* () { + const selectedAction = yield* Deferred.make(); + const applicationMenuTemplate = + yield* Deferred.make(); + + yield* configureMenu(selectedAction, applicationMenuTemplate, { platform: "darwin" }); + + const fileMenu = (yield* Deferred.await(applicationMenuTemplate)).find( + (item) => item.label === "File", + ); + if (!Array.isArray(fileMenu?.submenu)) { + throw new Error("Expected File menu submenu to be an array."); + } + const openWindow = fileMenu.submenu.find((item) => item.label === "Open Window"); + if (typeof openWindow?.click !== "function") { + throw new Error("Expected Open Window menu item to have a click handler."); + } + + openWindow.click({} as Electron.MenuItem, undefined, {} as KeyboardEvent); + assert.equal(yield* Deferred.await(selectedAction), "activate"); + }), + ); + it.effect("never binds Cmd/Ctrl+W to closing the window", () => Effect.gen(function* () { for (const platform of ["darwin", "linux", "win32"] as const) { diff --git a/apps/desktop/src/window/DesktopApplicationMenu.ts b/apps/desktop/src/window/DesktopApplicationMenu.ts index 44d2c234f8358..f2a6b6307e5a2 100644 --- a/apps/desktop/src/window/DesktopApplicationMenu.ts +++ b/apps/desktop/src/window/DesktopApplicationMenu.ts @@ -64,6 +64,11 @@ const runMainContentsCommand = Effect.fn("desktop.menu.runMainContentsCommand")( yield* desktopWindow.runMainContentsCommand(command); }); +const activateMainWindow = Effect.gen(function* () { + const desktopWindow = yield* DesktopWindow.DesktopWindow; + yield* desktopWindow.activate; +}).pipe(Effect.withSpan("desktop.menu.activateMainWindow")); + const checkForUpdatesFromMenu = Effect.gen(function* () { const updates = yield* DesktopUpdates.DesktopUpdates; const electronDialog = yield* ElectronDialog.ElectronDialog; @@ -191,7 +196,12 @@ export const make = Effect.gen(function* () { label: "File", submenu: [ ...(environment.platform === "darwin" - ? [] + ? [ + { + label: "Open Window", + click: () => runMenuEffect("open-window", activateMainWindow), + }, + ] : [ { label: "Settings...",