diff --git a/src/main/menu/app-menu-window.ts b/src/main/menu/app-menu-window.ts new file mode 100644 index 00000000000..33281659bf0 --- /dev/null +++ b/src/main/menu/app-menu-window.ts @@ -0,0 +1,16 @@ +export function createAppWindowMenu( + label: string, + isMac: boolean +): Electron.MenuItemConstructorOptions { + return { + label, + submenu: [ + { + // Why: Electron's minimize role otherwise steals Ctrl+M from terminal apps such as Crush. + role: 'minimize', + ...(isMac ? {} : { accelerator: '', registerAccelerator: false }) + }, + { role: 'zoom' } + ] + } +} diff --git a/src/main/menu/register-app-menu.test.ts b/src/main/menu/register-app-menu.test.ts index b5a12718058..ee8bf6ccc08 100644 --- a/src/main/menu/register-app-menu.test.ts +++ b/src/main/menu/register-app-menu.test.ts @@ -72,6 +72,23 @@ function getSubmenu( } describe('registerAppMenu', () => { + it.each(['linux', 'win32', 'darwin'] as const)( + 'leaves Ctrl+M to the terminal while preserving macOS minimize on %s', + (platform) => { + vi.spyOn(process, 'platform', 'get').mockReturnValue(platform) + registerAppMenu(buildMenuOptions()) + + const windowSubmenu = getSubmenu(getTemplate(), 'Window') + const minimize = windowSubmenu.find((item) => item.role === 'minimize') + expect(minimize).toEqual( + platform === 'darwin' + ? { role: 'minimize' } + : { role: 'minimize', accelerator: '', registerAccelerator: false } + ) + expect(windowSubmenu.find((item) => item.role === 'zoom')).toEqual({ role: 'zoom' }) + } + ) + it('shows the Settings hint when the user assigns a shortcut', () => { registerAppMenu({ ...buildMenuOptions(), diff --git a/src/main/menu/register-app-menu.ts b/src/main/menu/register-app-menu.ts index 889e0cd0b08..3c8bb434c29 100644 --- a/src/main/menu/register-app-menu.ts +++ b/src/main/menu/register-app-menu.ts @@ -8,6 +8,7 @@ import { import type { UpdateCheckOptions } from '../../shared/update-status-types' import { translateMain } from '../i18n/main-i18n' import { createAppMenuSelectionItem } from './app-menu-selection-item' +import { createAppWindowMenu } from './app-menu-window' export type AppearanceMenuState = { showTasksButton: boolean @@ -318,10 +319,7 @@ function buildAndApplyMenu(options: RegisterAppMenuOptions): void { ] } - const windowMenu: Electron.MenuItemConstructorOptions = { - label: translateMain('menu.window', 'Window'), - submenu: [{ role: 'minimize' }, { role: 'zoom' }] - } + const windowMenu = createAppWindowMenu(translateMain('menu.window', 'Window'), isMac) const helpMenu: Electron.MenuItemConstructorOptions = { label: translateMain('menu.help', 'Help'),