fix: menu should allow focused BaseWindow where possible (#43439)

fix: menu should allow focused BaseWindow

Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com>
Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>
This commit is contained in:
trop[bot] 2024-08-22 18:33:44 -05:00 committed by GitHub
parent 557d5c901a
commit a373ab027b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 25 additions and 19 deletions

View file

@ -1,4 +1,4 @@
import { app, BrowserWindow, session, webContents, WebContents, MenuItemConstructorOptions } from 'electron/main';
import { app, BaseWindow, BrowserWindow, session, webContents, WebContents, MenuItemConstructorOptions } from 'electron/main';
const isMac = process.platform === 'darwin';
const isWindows = process.platform === 'win32';
@ -13,7 +13,7 @@ interface Role {
label: string;
accelerator?: string;
checked?: boolean;
windowMethod?: ((window: BrowserWindow) => void);
windowMethod?: ((window: BaseWindow) => void);
webContentsMethod?: ((webContents: WebContents) => void);
appMethod?: () => void;
registerAccelerator?: boolean;
@ -53,8 +53,10 @@ export const roleList: Record<RoleId, Role> = {
label: 'Force Reload',
accelerator: 'Shift+CmdOrCtrl+R',
nonNativeMacOSRole: true,
windowMethod: (window: BrowserWindow) => {
window.webContents.reloadIgnoringCache();
windowMethod: (window: BaseWindow) => {
if (window instanceof BrowserWindow) {
window.webContents.reloadIgnoringCache();
}
}
},
front: {
@ -110,7 +112,11 @@ export const roleList: Record<RoleId, Role> = {
label: 'Reload',
accelerator: 'CmdOrCtrl+R',
nonNativeMacOSRole: true,
windowMethod: w => w.reload()
windowMethod: (w: BaseWindow) => {
if (w instanceof BrowserWindow) {
w.reload();
}
}
},
resetzoom: {
label: 'Actual Size',
@ -164,7 +170,7 @@ export const roleList: Record<RoleId, Role> = {
togglefullscreen: {
label: 'Toggle Full Screen',
accelerator: isMac ? 'Control+Command+F' : 'F11',
windowMethod: (window: BrowserWindow) => {
windowMethod: (window: BaseWindow) => {
window.setFullScreen(!window.isFullScreen());
}
},
@ -361,7 +367,7 @@ export function getDefaultSubmenu (role: RoleId) {
return submenu;
}
export function execute (role: RoleId, focusedWindow: BrowserWindow, focusedWebContents: WebContents) {
export function execute (role: RoleId, focusedWindow: BaseWindow, focusedWebContents: WebContents) {
if (!canExecuteRole(role)) return false;
const { appMethod, webContentsMethod, windowMethod } = roleList[role];