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
|
|
@ -2,7 +2,8 @@
|
|||
// electron-store 기반 설정 관리. 설계서 02의 AppConfig 타입 사용.
|
||||
|
||||
import { EventEmitter } from 'events'
|
||||
import type { AppConfig, ConfigChangedEvent } from '@d3ro/core/types'
|
||||
import type { AppConfig, ConfigChangedEvent, KeyBindingActionId, KeyBindingMap } from '@d3ro/core/types'
|
||||
import { createDefaultBindingMap, normalizeBinding, parseBindingMap } from '@d3ro/core/keybinding'
|
||||
import { D3ROError, ErrorCode } from '@d3ro/core/errors'
|
||||
import { getLogger } from './LoggerService'
|
||||
|
||||
|
|
@ -12,6 +13,7 @@ const logger = getLogger('ConfigService')
|
|||
interface ElectronStore<T> {
|
||||
get<K extends keyof T>(key: K): T[K]
|
||||
set<K extends keyof T>(key: K, value: T[K]): void
|
||||
delete(key: string): void
|
||||
store: T
|
||||
}
|
||||
|
||||
|
|
@ -51,38 +53,7 @@ const CONFIG_DEFAULTS: AppConfig = {
|
|||
// 라이브 음성 대화 백엔드 — 'realtime'은 로그인+구독 필요 (OpenAI Realtime WebRTC)
|
||||
conversationBackend: 'local' as const,
|
||||
defaultLLMAction: 'refine',
|
||||
dictationShortcut: {
|
||||
keyCode: 0xa5, // Right Alt
|
||||
ctrl: false,
|
||||
alt: false,
|
||||
shift: false,
|
||||
meta: false,
|
||||
displayLabel: 'Right Alt'
|
||||
},
|
||||
handsFreeShortcut: {
|
||||
keyCode: 0xa5,
|
||||
ctrl: false,
|
||||
alt: false,
|
||||
shift: false,
|
||||
meta: false,
|
||||
displayLabel: 'Right Alt (double)'
|
||||
},
|
||||
commandShortcut: {
|
||||
keyCode: 0xa5,
|
||||
ctrl: true,
|
||||
alt: false,
|
||||
shift: false,
|
||||
meta: false,
|
||||
displayLabel: 'Ctrl + Right Alt'
|
||||
},
|
||||
captionShortcut: {
|
||||
keyCode: 0xa5,
|
||||
ctrl: true,
|
||||
alt: false,
|
||||
shift: true,
|
||||
meta: false,
|
||||
displayLabel: 'Ctrl + Shift + Right Alt'
|
||||
},
|
||||
keyBindings: createDefaultBindingMap(),
|
||||
hotkeyEnabled: true,
|
||||
insertMethod: 'clipboard',
|
||||
autoInsert: true,
|
||||
|
|
@ -125,6 +96,9 @@ function createMemoryStore(initial: AppConfig): ElectronStore<AppConfig> {
|
|||
set<K extends keyof AppConfig>(key: K, value: AppConfig[K]): void {
|
||||
data[key] = value
|
||||
},
|
||||
delete(key: string): void {
|
||||
delete (data as unknown as Record<string, unknown>)[key]
|
||||
},
|
||||
get store(): AppConfig {
|
||||
return data
|
||||
},
|
||||
|
|
@ -134,6 +108,77 @@ function createMemoryStore(initial: AppConfig): ElectronStore<AppConfig> {
|
|||
}
|
||||
}
|
||||
|
||||
// ── 키바인딩 마이그레이션 (구 *Shortcut 4개 → keyBindings) ──
|
||||
|
||||
/** 0.x 저장 형태. 구조·라벨 정본이 keybinding.ts 로 옮겨지기 전의 값이다. */
|
||||
interface LegacyShortcut {
|
||||
keyCode: number
|
||||
ctrl: boolean
|
||||
alt: boolean
|
||||
shift: boolean
|
||||
meta: boolean
|
||||
}
|
||||
|
||||
const LEGACY_SHORTCUT_ACTIONS: Readonly<Record<string, KeyBindingActionId>> = {
|
||||
dictationShortcut: 'dictation',
|
||||
handsFreeShortcut: 'hands-free',
|
||||
commandShortcut: 'command',
|
||||
captionShortcut: 'caption',
|
||||
}
|
||||
|
||||
function isLegacyShortcut(value: unknown): value is LegacyShortcut {
|
||||
if (typeof value !== 'object' || value === null) return false
|
||||
const v = value as Record<string, unknown>
|
||||
return (
|
||||
typeof v.keyCode === 'number' &&
|
||||
typeof v.ctrl === 'boolean' &&
|
||||
typeof v.alt === 'boolean' &&
|
||||
typeof v.shift === 'boolean' &&
|
||||
typeof v.meta === 'boolean'
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* 저장된 keyBindings 를 복원하고, 남아 있는 구 `*Shortcut` 값을 1회만 이관한다.
|
||||
*
|
||||
* 구 필드는 이관 직후 삭제하므로 다시 읽히지 않는다.
|
||||
* `displayLabel` 은 폐기한다 — 라벨은 formatBindingSegments() 로 파생시킨다.
|
||||
*/
|
||||
function migrateKeyBindings(activeStore: ElectronStore<AppConfig>): void {
|
||||
const raw = activeStore.store as unknown as Record<string, unknown>
|
||||
const restored: KeyBindingMap = parseBindingMap(raw.keyBindings)
|
||||
|
||||
const legacyKeys = Object.keys(LEGACY_SHORTCUT_ACTIONS).filter((key) =>
|
||||
isLegacyShortcut(raw[key]),
|
||||
)
|
||||
if (legacyKeys.length === 0) {
|
||||
activeStore.set('keyBindings', restored)
|
||||
return
|
||||
}
|
||||
|
||||
for (const key of legacyKeys) {
|
||||
const legacy = raw[key] as LegacyShortcut
|
||||
const actionId = LEGACY_SHORTCUT_ACTIONS[key]
|
||||
if (actionId === undefined) continue
|
||||
restored[actionId] = [
|
||||
normalizeBinding({
|
||||
device: 'keyboard',
|
||||
code: legacy.keyCode,
|
||||
ctrl: legacy.ctrl,
|
||||
alt: legacy.alt,
|
||||
shift: legacy.shift,
|
||||
meta: legacy.meta,
|
||||
}),
|
||||
]
|
||||
}
|
||||
|
||||
activeStore.set('keyBindings', restored)
|
||||
for (const key of legacyKeys) {
|
||||
activeStore.delete(key)
|
||||
}
|
||||
logger.info(`Migrated ${legacyKeys.length} legacy shortcut(s) to keyBindings`)
|
||||
}
|
||||
|
||||
/** electron-store 없이 설정 CRUD를 가능하게 한다 (테스트 + 초기화 전 안전망). */
|
||||
export function initInMemoryConfig(overrides?: Partial<AppConfig>): void {
|
||||
store = createMemoryStore({ ...CONFIG_DEFAULTS, ...overrides })
|
||||
|
|
@ -149,6 +194,7 @@ export async function initConfigService(): Promise<void> {
|
|||
name: 'd3ro-voice-config',
|
||||
defaults: CONFIG_DEFAULTS
|
||||
})
|
||||
migrateKeyBindings(store)
|
||||
logger.info('ConfigService initialized')
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue