Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -83,7 +83,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 @@ -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<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 @@ -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;
Expand Down Expand Up @@ -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...",
Expand Down
Loading