Skip to content
26 changes: 25 additions & 1 deletion apps/desktop/src/window/DesktopApplicationMenu.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ const layerDesktopWindow = (selectedAction: Deferred.Deferred<string>) =>
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,
Expand Down Expand Up @@ -267,6 +267,30 @@ describe("DesktopApplicationMenu", () => {
}),
);

it.effect("reopens the main window from File > Open Window on macOS", () =>
Effect.gen(function* () {
const selectedAction = yield* Deferred.make<string>();
const applicationMenuTemplate =
yield* Deferred.make<readonly Electron.MenuItemConstructorOptions[]>();

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) {
Expand Down
12 changes: 11 additions & 1 deletion apps/desktop/src/window/DesktopApplicationMenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,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;
Expand Down Expand Up @@ -246,7 +251,12 @@ export const make = Effect.gen(function* () {
label: m(msg("File", { $context: "menu bar title" })),
submenu: [
...(environment.platform === "darwin"
? []
? [
{
label: "Open Window",
click: () => runMenuEffect("open-window", activateMainWindow),
},
]
: [
{
label: m(msg("Settings...")),
Expand Down
Loading