From 4f6c2c7379045862f972d4c1d53df5ede4d4dea2 Mon Sep 17 00:00:00 2001 From: sawka Date: Fri, 4 Oct 2024 15:07:30 -0700 Subject: [PATCH] fix window type errors --- emain/menu.ts | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/emain/menu.ts b/emain/menu.ts index 646162b3d..e5406a8de 100644 --- a/emain/menu.ts +++ b/emain/menu.ts @@ -11,6 +11,16 @@ type AppMenuCallbacks = { relaunchBrowserWindows: () => Promise; }; +function getWindowWebContents(window: electron.BaseWindow): electron.WebContents { + if (window == null) { + return null; + } + if (window instanceof electron.BrowserWindow) { + return window.webContents; + } + return null; +} + function getAppMenu(callbacks: AppMenuCallbacks): Electron.Menu { const fileMenu: Electron.MenuItemConstructorOptions[] = [ { @@ -30,7 +40,7 @@ function getAppMenu(callbacks: AppMenuCallbacks): Electron.Menu { { label: "About Wave Terminal", click: (_, window) => { - window?.webContents.send("menu-item-about"); + getWindowWebContents(window)?.send("menu-item-about"); }, }, { @@ -122,21 +132,29 @@ function getAppMenu(callbacks: AppMenuCallbacks): Electron.Menu { label: "Actual Size", accelerator: "CommandOrControl+0", click: (_, window) => { - window.webContents.setZoomFactor(1); + getWindowWebContents(window)?.setZoomFactor(1); }, }, { label: "Zoom In", accelerator: "CommandOrControl+=", click: (_, window) => { - window.webContents.setZoomFactor(window.webContents.getZoomFactor() + 0.2); + const wc = getWindowWebContents(window); + if (wc == null) { + return; + } + wc.setZoomFactor(wc.getZoomFactor() + 0.2); }, }, { label: "Zoom In (hidden)", accelerator: "CommandOrControl+Shift+=", click: (_, window) => { - window.webContents.setZoomFactor(window.webContents.getZoomFactor() + 0.2); + const wc = getWindowWebContents(window); + if (wc == null) { + return; + } + wc.setZoomFactor(wc.getZoomFactor() + 0.2); }, visible: false, acceleratorWorksWhenHidden: true, @@ -145,7 +163,11 @@ function getAppMenu(callbacks: AppMenuCallbacks): Electron.Menu { label: "Zoom Out", accelerator: "CommandOrControl+-", click: (_, window) => { - window.webContents.setZoomFactor(window.webContents.getZoomFactor() - 0.2); + const wc = getWindowWebContents(window); + if (wc == null) { + return; + } + wc.setZoomFactor(wc.getZoomFactor() - 0.2); }, }, {