feat(keybinding): several shortcuts per action, mouse buttons, searchable picker
Shortcuts were defined in four places that drifted apart: per-action IPC channel pairs, a hand-written VK table in the service, a second one in the renderer, and three copies of the keycap styling. Adding an action meant editing all of them, so two shortcuts stayed hardcoded in bootstrap and one had no settings entry at all. packages/core/src/keybinding.ts is now the single source for the binding type, the selectable key catalog, the action catalog, normalization, validation, conflict detection, display labels, search and deserialization. Main, preload and renderer all read from it; nothing redefines keys or rules locally. - Each action holds a list of bindings instead of one. AppConfig's four *Shortcut fields collapse into a single keyBindings map, migrated on launch. - Mouse buttons can be bound. Left click is refused, right/middle need a modifier, side buttons are free. uiohook cannot swallow events, so the original click still fires and the UI says so. - Keys can be picked from a grouped dropdown with a search box, not only by recording a keypress. - HOTKEY's 14 channels become KEYBINDING's 9, taking the action as a parameter, so actions no longer multiply channels. The history and command popups moved out of bootstrap into ordinary actions. - displayLabel is gone; labels derive from the binding and follow the app language and platform. Fixes found on the way: - Double-press hands-free was unreachable: lookup returned only the first matching action, and dictation shares its default binding. - Reserved-combination checks compared joined key names, so a different modifier order let Ctrl+C through. - Disabling shortcuts released every global registration in the process, including the popup ones, and never restored them. - Enabling shortcuts after starting disabled left nothing registered. - The dashboard stored the caption event payload instead of the state in it.
This commit is contained in:
parent
0ca9e242fa
commit
4ad1ae6ed4
49 changed files with 5901 additions and 1792 deletions
|
|
@ -1,8 +1,18 @@
|
|||
import { describe, it, expect, vi } from 'vitest'
|
||||
import { IPC_CHANNELS } from '@d3ro/core/ipc-channels'
|
||||
import { ErrorCode } from '@d3ro/core/errors'
|
||||
import {
|
||||
KEYBINDING_ACTIONS,
|
||||
createDefaultBindingMap,
|
||||
findActionSpec,
|
||||
} from '@d3ro/core/keybinding'
|
||||
import type {
|
||||
KeyBinding,
|
||||
KeyBindingMap,
|
||||
KeyBindingValidationResult,
|
||||
} from '@d3ro/core/types'
|
||||
import { configGet } from '../../src/main/services/ConfigService'
|
||||
import { registerHotkeyHandlers } from '../../src/main/ipc/hotkey-handlers'
|
||||
import { registerKeyBindingHandlers } from '../../src/main/ipc/keybinding-handlers'
|
||||
import { registerCaptionHandlers } from '../../src/main/ipc/caption-handlers'
|
||||
import { registerRAGHandlers } from '../../src/main/ipc/rag-handlers'
|
||||
import { registerVoiceConversationHandlers } from '../../src/main/ipc/voice-conversation-handlers'
|
||||
|
|
@ -13,73 +23,171 @@ import { registerTemplateHandlers } from '../../src/main/ipc/template-handlers'
|
|||
import { registerMeetingDocTemplateHandlers } from '../../src/main/ipc/meeting-doc-template-handlers'
|
||||
import { invokeIpc, useRedHarness } from './harness'
|
||||
|
||||
vi.mock('../../src/main/services/HotkeyService', () => ({
|
||||
getHotkeyService: () => ({
|
||||
const { keyBindingService } = vi.hoisted(() => ({
|
||||
keyBindingService: {
|
||||
loadFromConfig: vi.fn(),
|
||||
start: vi.fn(),
|
||||
stop: vi.fn(),
|
||||
on: vi.fn(),
|
||||
off: vi.fn(),
|
||||
}),
|
||||
},
|
||||
}))
|
||||
|
||||
vi.mock('../../src/main/services/KeyBindingService', () => ({
|
||||
getKeyBindingService: () => keyBindingService,
|
||||
}))
|
||||
|
||||
useRedHarness()
|
||||
|
||||
const SAMPLE_BINDING = {
|
||||
keyCode: 65,
|
||||
/** Ctrl + A — 시스템 예약 조합이라 검증에서 거부되어야 한다 */
|
||||
const RESERVED_BINDING: KeyBinding = {
|
||||
device: 'keyboard',
|
||||
code: 0x41,
|
||||
ctrl: true,
|
||||
alt: false,
|
||||
shift: false,
|
||||
meta: false,
|
||||
displayLabel: 'Ctrl+A',
|
||||
}
|
||||
|
||||
describe('유스케이스: 핫키 / 캡션 / RAG / 대화 / 액션 / 파일전사 / 회의 IPC', () => {
|
||||
it('핫키 받아쓰기 단축키를 읽고 쓴다', async () => {
|
||||
registerHotkeyHandlers()
|
||||
const set = await invokeIpc(IPC_CHANNELS.HOTKEY.SET_DICTATION_SHORTCUT, { binding: SAMPLE_BINDING })
|
||||
/** Ctrl + Shift + F9 — 예약되지 않은 유효한 조합 */
|
||||
const FREE_BINDING: KeyBinding = {
|
||||
device: 'keyboard',
|
||||
code: 0x78,
|
||||
ctrl: true,
|
||||
alt: false,
|
||||
shift: true,
|
||||
meta: false,
|
||||
}
|
||||
|
||||
describe('유스케이스: 키바인딩 / 캡션 / RAG / 대화 / 액션 / 파일전사 / 회의 IPC', () => {
|
||||
it('키바인딩 맵을 읽으면 모든 액션이 들어 있다', async () => {
|
||||
registerKeyBindingHandlers()
|
||||
const get = await invokeIpc<KeyBindingMap>(IPC_CHANNELS.KEYBINDING.GET_MAP)
|
||||
expect(get.success).toBe(true)
|
||||
if (get.success) {
|
||||
for (const action of KEYBINDING_ACTIONS) {
|
||||
expect(get.data[action.id]).toEqual(action.defaultBindings)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
it('액션 바인딩을 교체하면 맵에 반영되고 서비스가 다시 읽는다', async () => {
|
||||
registerKeyBindingHandlers()
|
||||
const set = await invokeIpc(IPC_CHANNELS.KEYBINDING.SET_BINDINGS, {
|
||||
actionId: 'dictation',
|
||||
bindings: [FREE_BINDING],
|
||||
})
|
||||
expect(set.success).toBe(true)
|
||||
const get = await invokeIpc(IPC_CHANNELS.HOTKEY.GET_DICTATION_SHORTCUT)
|
||||
expect(get.success).toBe(true)
|
||||
if (get.success) expect(get.data.displayLabel).toBe('Ctrl+A')
|
||||
expect(keyBindingService.loadFromConfig).toHaveBeenCalled()
|
||||
|
||||
const get = await invokeIpc<KeyBindingMap>(IPC_CHANNELS.KEYBINDING.GET_MAP)
|
||||
if (get.success) expect(get.data.dictation).toEqual([FREE_BINDING])
|
||||
})
|
||||
|
||||
it('핫키 핸즈프리 단축키를 읽고 쓴다', async () => {
|
||||
registerHotkeyHandlers()
|
||||
await invokeIpc(IPC_CHANNELS.HOTKEY.SET_HANDS_FREE_SHORTCUT, { binding: SAMPLE_BINDING })
|
||||
const get = await invokeIpc(IPC_CHANNELS.HOTKEY.GET_HANDS_FREE_SHORTCUT)
|
||||
expect(get.success).toBe(true)
|
||||
it('시스템 예약 조합은 HotkeySystemReserved로 거부된다', async () => {
|
||||
registerKeyBindingHandlers()
|
||||
const set = await invokeIpc(IPC_CHANNELS.KEYBINDING.SET_BINDINGS, {
|
||||
actionId: 'dictation',
|
||||
bindings: [RESERVED_BINDING],
|
||||
})
|
||||
expect(set.success).toBe(false)
|
||||
if (!set.success) expect(set.error.code).toBe(ErrorCode.HotkeySystemReserved)
|
||||
})
|
||||
|
||||
it('핫키 명령 단축키를 읽고 쓴다', async () => {
|
||||
registerHotkeyHandlers()
|
||||
await invokeIpc(IPC_CHANNELS.HOTKEY.SET_COMMAND_SHORTCUT, { binding: SAMPLE_BINDING })
|
||||
const get = await invokeIpc(IPC_CHANNELS.HOTKEY.GET_COMMAND_SHORTCUT)
|
||||
expect(get.success).toBe(true)
|
||||
it('다른 액션이 쓰는 바인딩은 HotkeyConflict로 거부된다', async () => {
|
||||
registerKeyBindingHandlers()
|
||||
const ok = await invokeIpc(IPC_CHANNELS.KEYBINDING.SET_BINDINGS, {
|
||||
actionId: 'caption',
|
||||
bindings: [FREE_BINDING],
|
||||
})
|
||||
expect(ok.success).toBe(true)
|
||||
|
||||
const conflict = await invokeIpc(IPC_CHANNELS.KEYBINDING.SET_BINDINGS, {
|
||||
actionId: 'command',
|
||||
bindings: [FREE_BINDING],
|
||||
})
|
||||
expect(conflict.success).toBe(false)
|
||||
if (!conflict.success) expect(conflict.error.code).toBe(ErrorCode.HotkeyConflict)
|
||||
})
|
||||
|
||||
it('핫키 자막 단축키를 읽고 쓴다', async () => {
|
||||
registerHotkeyHandlers()
|
||||
await invokeIpc(IPC_CHANNELS.HOTKEY.SET_CAPTION_SHORTCUT, { binding: SAMPLE_BINDING })
|
||||
const get = await invokeIpc(IPC_CHANNELS.HOTKEY.GET_CAPTION_SHORTCUT)
|
||||
expect(get.success).toBe(true)
|
||||
it('바인딩 사전 검사는 유효성과 충돌을 함께 돌려준다', async () => {
|
||||
registerKeyBindingHandlers()
|
||||
const reserved = await invokeIpc<KeyBindingValidationResult>(
|
||||
IPC_CHANNELS.KEYBINDING.VALIDATE,
|
||||
{ actionId: 'dictation', binding: RESERVED_BINDING },
|
||||
)
|
||||
expect(reserved.success).toBe(true)
|
||||
if (reserved.success) {
|
||||
expect(reserved.data.validation.valid).toBe(false)
|
||||
expect(reserved.data.validation.reason).toBe('system-reserved')
|
||||
}
|
||||
|
||||
const free = await invokeIpc<KeyBindingValidationResult>(
|
||||
IPC_CHANNELS.KEYBINDING.VALIDATE,
|
||||
{ actionId: 'dictation', binding: FREE_BINDING },
|
||||
)
|
||||
if (free.success) {
|
||||
expect(free.data.validation.valid).toBe(true)
|
||||
expect(free.data.conflicts).toEqual([])
|
||||
}
|
||||
})
|
||||
|
||||
it('핫키 활성 토글을 끈다', async () => {
|
||||
registerHotkeyHandlers()
|
||||
const set = await invokeIpc(IPC_CHANNELS.HOTKEY.SET_ENABLED, { enabled: false })
|
||||
it('액션 하나를 기본값으로 되돌린다', async () => {
|
||||
registerKeyBindingHandlers()
|
||||
await invokeIpc(IPC_CHANNELS.KEYBINDING.SET_BINDINGS, {
|
||||
actionId: 'dictation',
|
||||
bindings: [FREE_BINDING],
|
||||
})
|
||||
const reset = await invokeIpc(IPC_CHANNELS.KEYBINDING.RESET_ACTION, { actionId: 'dictation' })
|
||||
expect(reset.success).toBe(true)
|
||||
|
||||
const get = await invokeIpc<KeyBindingMap>(IPC_CHANNELS.KEYBINDING.GET_MAP)
|
||||
if (get.success) {
|
||||
expect(get.data.dictation).toEqual(findActionSpec('dictation')?.defaultBindings)
|
||||
}
|
||||
})
|
||||
|
||||
it('전체를 기본값으로 되돌린다', async () => {
|
||||
registerKeyBindingHandlers()
|
||||
await invokeIpc(IPC_CHANNELS.KEYBINDING.SET_BINDINGS, {
|
||||
actionId: 'caption',
|
||||
bindings: [FREE_BINDING],
|
||||
})
|
||||
const reset = await invokeIpc(IPC_CHANNELS.KEYBINDING.RESET_ALL)
|
||||
expect(reset.success).toBe(true)
|
||||
|
||||
const get = await invokeIpc<KeyBindingMap>(IPC_CHANNELS.KEYBINDING.GET_MAP)
|
||||
if (get.success) expect(get.data).toEqual(createDefaultBindingMap())
|
||||
})
|
||||
|
||||
it('알 수 없는 액션 id는 거부된다', async () => {
|
||||
registerKeyBindingHandlers()
|
||||
const res = await invokeIpc(IPC_CHANNELS.KEYBINDING.SET_BINDINGS, {
|
||||
actionId: 'nope',
|
||||
bindings: [FREE_BINDING],
|
||||
})
|
||||
expect(res.success).toBe(false)
|
||||
})
|
||||
|
||||
it('키바인딩 활성 토글을 끈다', async () => {
|
||||
registerKeyBindingHandlers()
|
||||
const set = await invokeIpc(IPC_CHANNELS.KEYBINDING.SET_ENABLED, { enabled: false })
|
||||
expect(set.success).toBe(true)
|
||||
const get = await invokeIpc(IPC_CHANNELS.HOTKEY.IS_ENABLED)
|
||||
const get = await invokeIpc(IPC_CHANNELS.KEYBINDING.IS_ENABLED)
|
||||
expect(get.success).toBe(true)
|
||||
if (get.success) expect(get.data).toBe(false)
|
||||
expect(configGet('hotkeyEnabled')).toBe(false)
|
||||
expect(keyBindingService.stop).toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('핫키 활성 토글을 켠다', async () => {
|
||||
registerHotkeyHandlers()
|
||||
await invokeIpc(IPC_CHANNELS.HOTKEY.SET_ENABLED, { enabled: true })
|
||||
const get = await invokeIpc(IPC_CHANNELS.HOTKEY.IS_ENABLED)
|
||||
it('키바인딩을 다시 켜면 등록을 다시 읽고 후킹을 시작한다', async () => {
|
||||
registerKeyBindingHandlers()
|
||||
keyBindingService.loadFromConfig.mockClear()
|
||||
await invokeIpc(IPC_CHANNELS.KEYBINDING.SET_ENABLED, { enabled: true })
|
||||
const get = await invokeIpc(IPC_CHANNELS.KEYBINDING.IS_ENABLED)
|
||||
if (get.success) expect(get.data).toBe(true)
|
||||
expect(keyBindingService.loadFromConfig).toHaveBeenCalled()
|
||||
expect(keyBindingService.start).toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('캡션 초기 상태를 읽는다', async () => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue