refactor(desktop): align settings menu shortcut handling with closeBinding

This commit is contained in:
lsdsjy committed 2026-11-18 13:49:10 +08:00
1 parent d345a58ccb
commit 3a205340a6
2 files changed
+9 -10

No files matched your search

+3 -3
View File
@@ -1,7 +1,7 @@
/** Product-window preference IPC and native menu interception during physical-key dispatch/recording. */
import { ipcMain, type BrowserWindow, type IpcMainInvokeEvent, type Input, type MenuItemConstructorOptions, type WebContents } from 'electron'
import { bindingKey, effectiveShortcuts, presentBinding, parseShortcutDefinitions, parseShortcutEdit } from '@deepseek-ai/dsh-client-shortcuts/protocol'
import type { NormalizedBinding, ShortcutCommandId, ShortcutConfigSnapshot, ShortcutDefinition, ShortcutPlatform, ShortcutRevision } from '@deepseek-ai/dsh-client-shortcuts/protocol'
import type { NormalizedBinding, ShortcutConfigSnapshot, ShortcutDefinition, ShortcutPlatform, ShortcutRevision } from '@deepseek-ai/dsh-client-shortcuts/protocol'
import type { DesktopBrowserLeaseId } from '@deepseek-ai/dsh-client-ui-sidebar-browser/types'
import { desktopKeybindings } from './keybindings.ts'
import { DESKTOP_IPC, assertDesktopSender } from './ipc.ts'
@@ -168,7 +168,7 @@ export function installDesktopShortcuts(
? input.key.toUpperCase() === acceleratorKey.toUpperCase()
: input.code === binding.code
}
const menuMatch = matchesMenuKey(closeBinding) || (platform !== 'windows' && matchesMenuKey(settingsBinding))
const menuMatch = matchesMenuKey(closeBinding) || matchesMenuKey(settingsBinding)
contents.setIgnoreMenuShortcuts(recording || match || menuMatch)
const frame = contents.focusedFrame
const composing = input.isComposing || input.key === 'Dead' || deadKey || input.modifiers.includes('altgr')
@@ -284,7 +284,7 @@ export function installDesktopShortcuts(
if (window === undefined || window.isDestroyed() || (focusWindow === undefined && !window.isFocused()) || !window.isEnabled()
|| overlayInput(window).blocked) return
window.webContents.send(DESKTOP_IPC.shortcutsInput, {
kind: 'menu', commandId: 'settings.open' as ShortcutCommandId, revision,
kind: 'menu', commandId: 'settings.open', revision,
})
},
}
+6 -7
View File
@@ -852,13 +852,12 @@ it.each([
id: 'dsh-settings-open', label: 'Settings…', enabled: true, accelerator: expectedAccelerator,
})
if (platform === 'macos') {
f.contents.emit('before-input-event', { preventDefault: vi.fn() }, {
type: 'keyDown', code: 'KeyW', key: ',', modifiers: ['meta'],
meta: true, control: false, alt: false, shift: false, isAutoRepeat: false, isComposing: false,
})
expect(f.contents.setIgnoreMenuShortcuts).toHaveBeenLastCalledWith(true)
}
const meta = platform === 'macos'
f.contents.emit('before-input-event', { preventDefault: vi.fn() }, {
type: 'keyDown', code: 'KeyW', key: ',', modifiers: [meta ? 'meta' : 'control'],
meta, control: !meta, alt: false, shift: false, isAutoRepeat: false, isComposing: false,
})
expect(f.contents.setIgnoreMenuShortcuts).toHaveBeenLastCalledWith(true)
let currentRevision = initial.revision
if (platform === 'windows') {