From 6ff170349e1a20d95e564bd4bffdad843a78f4f2 Mon Sep 17 00:00:00 2001 From: teyepe Date: Fri, 2 Oct 2026 21:34:31 +0100 Subject: [PATCH] fix(desktop): keep New and Open commands enabled without active windows --- apps/desktop/src/main/app/App.ts | 40 ++++++++++++---------- apps/desktop/src/main/commands/Commands.ts | 2 -- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/apps/desktop/src/main/app/App.ts b/apps/desktop/src/main/app/App.ts index f717e49b..e4c42774 100644 --- a/apps/desktop/src/main/app/App.ts +++ b/apps/desktop/src/main/app/App.ts @@ -556,14 +556,10 @@ export class App { }, document: { create: async () => { - if (!window) return; - - await this.#createWorkspaceFromWindow(window); + await this.#createWorkspaceFromWindow(window ?? null); }, open: async () => { - if (!window) return; - - await this.#openWorkspaceFromWindow(window); + await this.#openWorkspaceFromWindow(window ?? null); }, canSave: () => document !== null || @@ -712,7 +708,7 @@ export class App { } } - async #createWorkspaceFromWindow(opener: Window): Promise { + async #createWorkspaceFromWindow(opener: Window | null): Promise { try { const session = await this.#workspaces.createUntitled(); this.#openWorkspaceWindow(opener, session); @@ -722,7 +718,7 @@ export class App { } } - async #openWorkspaceFromWindow(opener: Window): Promise { + async #openWorkspaceFromWindow(opener: Window | null): Promise { let openPath: string | null; try { openPath = await this.#nativeDialogs.openFont(opener); @@ -741,19 +737,21 @@ export class App { * * @returns whether a workspace window now shows the file. */ - async #openPathFromWindow(opener: Window, sourcePath: string): Promise { - const openerIsLauncher = this.#workspaces.getForBrowserWindow(opener.window) === null; - if (openerIsLauncher) this.#replacedLaunchers.add(opener); + async #openPathFromWindow(opener: Window | null, sourcePath: string): Promise { + const openerIsLauncher = opener + ? this.#workspaces.getForBrowserWindow(opener.window) === null + : false; + if (openerIsLauncher && opener) this.#replacedLaunchers.add(opener); try { const session = await this.#workspaces.openPath(sourcePath); - if (this.#focusExistingWorkspaceWindow(opener, session)) return true; + if (opener && this.#focusExistingWorkspaceWindow(opener, session)) return true; this.#openWorkspaceWindow(opener, session); return true; } catch (error) { this.#log.warn("open document failed", error); - if (openerIsLauncher) this.#restoreLauncherRecents(opener); + if (openerIsLauncher && opener) this.#restoreLauncherRecents(opener); await this.#nativeDialogs.showOpenFailure(opener, this.applicationName); return false; } @@ -803,27 +801,31 @@ export class App { } } - #focusExistingWorkspaceWindow(opener: Window, session: FontSessionHost): boolean { + #focusExistingWorkspaceWindow(opener: Window | null, session: FontSessionHost): boolean { const existingWindow = session.activeWindow(); if (!existingWindow) return false; existingWindow.focus(); - if (this.#workspaces.getForBrowserWindow(opener.window) === null) { + if (opener && this.#workspaces.getForBrowserWindow(opener.window) === null) { this.#closeReplacedLauncher(opener); } return true; } - #openWorkspaceWindow(opener: Window, session: FontSessionHost): void { - const closeOpener = this.#workspaces.getForBrowserWindow(opener.window) === null; + #openWorkspaceWindow(opener: Window | null, session: FontSessionHost): void { + const closeOpener = opener + ? this.#workspaces.getForBrowserWindow(opener.window) === null + : false; - const bounds = screen.getDisplayMatching(opener.window.getBounds()).workArea; + const bounds = opener + ? screen.getDisplayMatching(opener.window.getBounds()).workArea + : screen.getPrimaryDisplay().workArea; const workspaceWindow = this.#createWindow(false, bounds); this.#workspaces.attachWindow(session.workspaceId, workspaceWindow); this.#loadWorkspace(workspaceWindow); - if (closeOpener) this.#closeReplacedLauncher(opener); + if (closeOpener && opener) this.#closeReplacedLauncher(opener); } #closeReplacedLauncher(launcher: Window): void { diff --git a/apps/desktop/src/main/commands/Commands.ts b/apps/desktop/src/main/commands/Commands.ts index c342114b..00ce10ee 100644 --- a/apps/desktop/src/main/commands/Commands.ts +++ b/apps/desktop/src/main/commands/Commands.ts @@ -136,13 +136,11 @@ const fileCommands: Command[] = [ { id: "file.new", label: "New Font", - enabled: (ctx) => ctx.windows.active() !== null, run: (ctx) => ctx.document.create(), }, { id: "file.open", label: "Open…", - enabled: (ctx) => ctx.windows.active() !== null, run: (ctx) => ctx.document.open(), }, {