diff --git a/src/app/app-menu.ts b/src/app/app-menu.ts index e30e2144..c4aed9e5 100644 --- a/src/app/app-menu.ts +++ b/src/app/app-menu.ts @@ -6,6 +6,7 @@ import { shell, } from 'electron'; +import { apiName } from '../common/api-interface'; import { isLinux, isMac, isWindowsOS } from '../common/env'; import { i18n, LocaleType } from '../common/i18n'; import { logger } from '../common/logger'; @@ -25,7 +26,13 @@ import { updateAlwaysOnTop, } from './window-actions'; import { ICustomBrowserWindow, windowHandler } from './window-handler'; -import { reloadWindow, windowExists, zoomIn, zoomOut } from './window-utils'; +import { + reloadWindow, + resetZoomLevel, + windowExists, + zoomIn, + zoomOut, +} from './window-utils'; export const menuSections = { about: 'about', @@ -57,6 +64,7 @@ const macAccelerator = { ...{ zoomIn: 'CommandOrControl+Plus', zoomOut: 'CommandOrControl+-', + resetZoom: 'CommandOrControl+0', }, }; @@ -338,6 +346,11 @@ export class AppMenu { : isWindowsOS || isLinux ? windowsAccelerator.zoomOut : ''; + const resetZoomAccelerator = isMac + ? macAccelerator.resetZoom + : isWindowsOS || isLinux + ? windowsAccelerator.resetZoom + : ''; return { label: i18n.t('View')(), submenu: [ @@ -350,10 +363,12 @@ export class AppMenu { label: i18n.t('Reload')(), }, this.buildSeparator(), - this.assignRoleOrLabel({ - role: 'resetZoom', - label: i18n.t('Actual Size')(), - }), + this.zoomMenuBuilder( + resetZoomAccelerator, + 'Actual Size', + resetZoomLevel, + 'resetZoom', + ), this.zoomMenuBuilder(zoomInAccelerator, 'Zoom In', zoomIn, 'zoomIn'), this.zoomMenuBuilder( zoomOutAccelerator, @@ -597,7 +612,17 @@ export class AppMenu { return; } if (devToolsEnabled) { - focusedWindow.webContents.toggleDevTools(); + if ( + (focusedWindow as ICustomBrowserWindow).winName === + apiName.mainWindowName + ) { + const mainWebContents = windowHandler.getMainWebContents(); + if (mainWebContents && !mainWebContents.isDestroyed()) { + mainWebContents.toggleDevTools(); + } + } else { + focusedWindow.webContents.toggleDevTools(); + } return; } }, @@ -716,16 +741,12 @@ export class AppMenu { accelerator: string, label: string, action: () => void, - role: MenuItemConstructorOptions['role'], + _role: MenuItemConstructorOptions['role'], ): MenuItemConstructorOptions { - if (windowHandler.isMana) { - return { - accelerator, - label: i18n.t(label)(), - click: (_item, focusedWindow) => (focusedWindow ? action() : null), - }; - } else { - return this.assignRoleOrLabel({ role, label: i18n.t(label)() }); - } + return { + accelerator, + label: i18n.t(label)(), + click: (_item, focusedWindow) => (focusedWindow ? action() : null), + }; } } diff --git a/src/app/main-api-handler.ts b/src/app/main-api-handler.ts index 8a70890c..9e0b509e 100644 --- a/src/app/main-api-handler.ts +++ b/src/app/main-api-handler.ts @@ -301,9 +301,10 @@ ipcMain.on( break; case apiCmds.setZoomLevel: if (typeof arg.zoomLevel === 'number') { - windowHandler - .getMainWindow() - ?.webContents.setZoomFactor(arg.zoomLevel as number); + const mainWebContents = windowHandler.getMainWebContents(); + if (mainWebContents && !mainWebContents.isDestroyed()) { + mainWebContents.setZoomFactor(arg.zoomLevel as number); + } } break; case apiCmds.autoUpdate: diff --git a/src/app/window-utils.ts b/src/app/window-utils.ts index 852630b4..8fe3acbb 100644 --- a/src/app/window-utils.ts +++ b/src/app/window-utils.ts @@ -779,7 +779,7 @@ export const zoomIn = () => { if ( (focusedWindow as ICustomBrowserWindow).winName === apiName.mainWindowName ) { - const mainWebContents = windowHandler.mainWebContents; + const mainWebContents = windowHandler.getMainWebContents(); if (mainWebContents && !mainWebContents.isDestroyed()) { webContents = mainWebContents; } @@ -830,7 +830,7 @@ export const zoomOut = () => { if ( (focusedWindow as ICustomBrowserWindow).winName === apiName.mainWindowName ) { - const mainWebContents = windowHandler.mainWebContents; + const mainWebContents = windowHandler.getMainWebContents(); if (mainWebContents && !mainWebContents.isDestroyed()) { webContents = mainWebContents; } @@ -875,7 +875,7 @@ export const resetZoomLevel = () => { if ( (focusedWindow as ICustomBrowserWindow).winName === apiName.mainWindowName ) { - const mainWebContents = windowHandler.mainWebContents; + const mainWebContents = windowHandler.getMainWebContents(); if (mainWebContents && !mainWebContents.isDestroyed()) { webContents = mainWebContents; }