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>
27 lines
700 B
TypeScript
27 lines
700 B
TypeScript
import assert from 'node:assert/strict'
|
|
|
|
import { test } from 'vitest'
|
|
|
|
import { windowMenuTemplate } from './window-menu'
|
|
|
|
test('macOS registers the native Window menu so AppKit window commands remain available', () => {
|
|
const menu = windowMenuTemplate(true)
|
|
|
|
assert.equal(menu.role, 'windowMenu')
|
|
assert.deepEqual(
|
|
menu.submenu.map(item => item.role),
|
|
['minimize', 'zoom', 'front']
|
|
)
|
|
})
|
|
|
|
test('non-macOS keeps the explicit cross-platform Window menu', () => {
|
|
const menu = windowMenuTemplate(false)
|
|
|
|
assert.equal(menu.label, 'Window')
|
|
assert.deepEqual(
|
|
menu.submenu.map(item => item.role),
|
|
['minimize', undefined]
|
|
)
|
|
assert.equal(menu.submenu[1].label, 'Close')
|
|
})
|