Main's menu template is MenuItemConstructorOptions[], so the local
WindowMenuItem interface (role?: string, submenu: Array<{role: string}>)
no longer satisfies it and tsc rejects the pushed item. Derive the type
from MenuItemConstructorOptions instead: role comes from Electron's own
role union (which includes 'windowMenu'), and submenu items are full
MenuItemConstructorOptions so the click-only Close item fits.
Also carry main's #65457 behaviour into the extracted template: the
non-macOS Close item is click-only with registerAccelerator: false, not
role: 'close' (which would claim CommandOrControl+W before the
before-input-event run that routes terminal-focused Ctrl+W to word
erase). Test updated to match.
Co-authored-by: victorjmilagres <294917029+victorjmilagres@users.noreply.github.com>
33 lines
1.2 KiB
TypeScript
33 lines
1.2 KiB
TypeScript
import type { MenuItemConstructorOptions } from 'electron'
|
|
|
|
interface WindowMenuItem extends MenuItemConstructorOptions {
|
|
submenu: MenuItemConstructorOptions[]
|
|
}
|
|
|
|
function windowMenuTemplate(isMac: boolean): WindowMenuItem {
|
|
return {
|
|
label: 'Window',
|
|
// Mark the macOS menu as AppKit's standard Window menu. Without this role,
|
|
// macOS still exposes tiling from the green button but does not attach its
|
|
// Move & Resize commands (and their keyboard shortcuts) to the app menu.
|
|
...(isMac ? { role: 'windowMenu' } : {}),
|
|
submenu: isMac
|
|
? [{ role: 'minimize' }, { role: 'zoom' }, { role: 'front' }]
|
|
: // Click-only Close: the `close` role would register its default
|
|
// CommandOrControl+W accelerator, claiming the chord before the
|
|
// before-input-event run that routes a terminal-focused Ctrl+W to the
|
|
// shell's word erase (#65457). The menu item still closes the focused
|
|
// window when clicked.
|
|
[
|
|
{ role: 'minimize' },
|
|
{
|
|
click: (_menuItem, window) => window?.close(),
|
|
label: 'Close',
|
|
registerAccelerator: false
|
|
}
|
|
]
|
|
}
|
|
}
|
|
|
|
export { windowMenuTemplate }
|