fix window type errors

This commit is contained in:
sawka 2024-10-04 15:07:30 -07:00
parent b4582fcaff
commit 4f6c2c7379

View File

@ -11,6 +11,16 @@ type AppMenuCallbacks = {
relaunchBrowserWindows: () => Promise<void>; relaunchBrowserWindows: () => Promise<void>;
}; };
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 { function getAppMenu(callbacks: AppMenuCallbacks): Electron.Menu {
const fileMenu: Electron.MenuItemConstructorOptions[] = [ const fileMenu: Electron.MenuItemConstructorOptions[] = [
{ {
@ -30,7 +40,7 @@ function getAppMenu(callbacks: AppMenuCallbacks): Electron.Menu {
{ {
label: "About Wave Terminal", label: "About Wave Terminal",
click: (_, window) => { 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", label: "Actual Size",
accelerator: "CommandOrControl+0", accelerator: "CommandOrControl+0",
click: (_, window) => { click: (_, window) => {
window.webContents.setZoomFactor(1); getWindowWebContents(window)?.setZoomFactor(1);
}, },
}, },
{ {
label: "Zoom In", label: "Zoom In",
accelerator: "CommandOrControl+=", accelerator: "CommandOrControl+=",
click: (_, window) => { 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)", label: "Zoom In (hidden)",
accelerator: "CommandOrControl+Shift+=", accelerator: "CommandOrControl+Shift+=",
click: (_, window) => { 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, visible: false,
acceleratorWorksWhenHidden: true, acceleratorWorksWhenHidden: true,
@ -145,7 +163,11 @@ function getAppMenu(callbacks: AppMenuCallbacks): Electron.Menu {
label: "Zoom Out", label: "Zoom Out",
accelerator: "CommandOrControl+-", accelerator: "CommandOrControl+-",
click: (_, window) => { click: (_, window) => {
window.webContents.setZoomFactor(window.webContents.getZoomFactor() - 0.2); const wc = getWindowWebContents(window);
if (wc == null) {
return;
}
wc.setZoomFactor(wc.getZoomFactor() - 0.2);
}, },
}, },
{ {