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
|
|
@ -13,15 +13,15 @@ import { getAudioCaptureService } from './AudioCaptureService'
|
|||
import { getLocalSTTService } from './LocalSTTService'
|
||||
import type { TranscriptionResult } from './LocalSTTService'
|
||||
import { getSTTManager } from './stt/STTManager'
|
||||
import { getHotkeyService } from './HotkeyService'
|
||||
import type { HotkeyConfig } from './HotkeyService'
|
||||
import { getKeyBindingService } from './KeyBindingService'
|
||||
import type { KeyBindingTriggerPayload } from './KeyBindingService'
|
||||
import { configGet } from './ConfigService'
|
||||
import { getTextInsertService } from './TextInsertService'
|
||||
import { getLocalLLMService } from './LocalLLMService'
|
||||
import { D3ROError, ErrorCode } from '@d3ro/core/errors'
|
||||
import { TIMING } from '@d3ro/core/constants'
|
||||
import { RecognitionState, AudioState } from '@d3ro/core/types'
|
||||
import type { VoiceMode, VoiceState, LLMAction } from '@d3ro/core/types'
|
||||
import type { KeyBindingActionId, VoiceMode, VoiceState, LLMAction } from '@d3ro/core/types'
|
||||
import {
|
||||
showRecordingTip,
|
||||
hideRecordingTip,
|
||||
|
|
@ -55,7 +55,9 @@ interface VoiceAction {
|
|||
type: 'press' | 'release' | 'escape'
|
||||
timestamp: number
|
||||
mode: VoiceMode
|
||||
hotkeyId: string
|
||||
actionId: KeyBindingActionId
|
||||
/** hold-to-talk 여부 — release 에서 세션을 끊을지 결정한다 */
|
||||
holdMode: boolean
|
||||
}
|
||||
|
||||
interface VoiceModeEvents {
|
||||
|
|
@ -147,9 +149,7 @@ class VoiceModeService extends EventEmitter {
|
|||
// 리스너 해제용 참조
|
||||
private _audioDataHandler: ((payload: { buffer: Buffer }) => void) | null = null
|
||||
private _audioLevelHandler: ((payload: { level: number }) => void) | null = null
|
||||
private _hotkeyPressHandler: ((payload: { config: HotkeyConfig; timestamp: number }) => void) | null = null
|
||||
private _hotkeyReleaseHandler: ((payload: { config: HotkeyConfig; durationMs: number; timestamp: number }) => void) | null = null
|
||||
private _doublePressHandler: ((payload: { config: HotkeyConfig }) => void) | null = null
|
||||
private _keyBindingHandler: ((payload: KeyBindingTriggerPayload) => void) | null = null
|
||||
|
||||
private _disposed = false
|
||||
|
||||
|
|
@ -174,39 +174,39 @@ class VoiceModeService extends EventEmitter {
|
|||
// ── 초기화 ──────────────────────────────────────────────
|
||||
|
||||
/**
|
||||
* HotkeyService 이벤트를 구독하여 핫키 → 세션 제어를 연결한다.
|
||||
* KeyBindingService 이벤트를 구독하여 키바인딩 → 세션 제어를 연결한다.
|
||||
* bootstrap에서 호출한다.
|
||||
*/
|
||||
connectHotkey(): void {
|
||||
const hotkey = getHotkeyService()
|
||||
|
||||
this._hotkeyPressHandler = (payload) => {
|
||||
// Phase 10.1: caption 핫키는 VoiceModeService가 아닌 CaptionService로 라우팅
|
||||
if (payload.config.id === 'voice-caption') {
|
||||
this._toggleCaption()
|
||||
return
|
||||
connectKeyBindings(): void {
|
||||
this._keyBindingHandler = (payload) => {
|
||||
switch (payload.actionId) {
|
||||
case 'caption':
|
||||
// Phase 10.1: caption은 VoiceModeService가 아닌 CaptionService로 라우팅.
|
||||
// 토글이므로 press만 처리하고 release는 버린다.
|
||||
if (payload.type === 'pressed') this._toggleCaption()
|
||||
return
|
||||
case 'history-popup':
|
||||
case 'command-popup':
|
||||
// 팝업 액션은 bootstrap이 직접 구독한다.
|
||||
return
|
||||
default:
|
||||
break
|
||||
}
|
||||
const mode = this._resolveMode(payload.config)
|
||||
this._enqueueAction({ type: 'press', timestamp: payload.timestamp, mode, hotkeyId: payload.config.id })
|
||||
|
||||
const holdMode = this._resolveHoldMode(payload.actionId, payload.holdMode)
|
||||
const action: VoiceAction = {
|
||||
type: payload.type === 'pressed' ? 'press' : 'release',
|
||||
timestamp: payload.timestamp,
|
||||
mode: this._resolveMode(payload.actionId, payload.isDoublePress),
|
||||
actionId: payload.actionId,
|
||||
holdMode
|
||||
}
|
||||
this._enqueueAction(action)
|
||||
}
|
||||
|
||||
this._hotkeyReleaseHandler = (payload) => {
|
||||
// caption 핫키의 release는 무시 (토글 방식)
|
||||
if (payload.config.id === 'voice-caption') return
|
||||
const mode = this._resolveMode(payload.config)
|
||||
this._enqueueAction({ type: 'release', timestamp: payload.timestamp, mode, hotkeyId: payload.config.id })
|
||||
}
|
||||
getKeyBindingService().on('triggered', this._keyBindingHandler)
|
||||
|
||||
this._doublePressHandler = (payload) => {
|
||||
// 더블프레스 → hands-free 모드 토글
|
||||
this._enqueueAction({ type: 'press', timestamp: Date.now(), mode: 'hands-free', hotkeyId: payload.config.id })
|
||||
}
|
||||
|
||||
hotkey.on('hotkey-pressed', this._hotkeyPressHandler)
|
||||
hotkey.on('hotkey-released', this._hotkeyReleaseHandler)
|
||||
hotkey.on('double-press', this._doublePressHandler)
|
||||
|
||||
logger.info('Hotkey events connected')
|
||||
logger.info('Key binding events connected')
|
||||
}
|
||||
|
||||
// ── 세션 제어 ──────────────────────────────────────────
|
||||
|
|
@ -1050,24 +1050,34 @@ class VoiceModeService extends EventEmitter {
|
|||
}
|
||||
}
|
||||
|
||||
private async _handleRelease(_action: VoiceAction): Promise<void> {
|
||||
if (_action.mode === 'dictation' && this.isActive) {
|
||||
private async _handleRelease(action: VoiceAction): Promise<void> {
|
||||
if (action.holdMode && action.mode === 'dictation' && this.isActive) {
|
||||
// Dictation: hold-to-talk — release로 즉시 종료
|
||||
// Speakly 패턴: 딜레이 없이 즉시 stop (딜레이가 race condition 유발)
|
||||
await this.stopSession()
|
||||
}
|
||||
// HandsFree: release 무시
|
||||
// HandsFree(토글): release 무시
|
||||
}
|
||||
|
||||
// ── 유틸리티 ───────────────────────────────────────────
|
||||
|
||||
private _resolveMode(config: HotkeyConfig): VoiceMode {
|
||||
if (config.id === 'voice-handsfree' || config.doublePressEnabled) {
|
||||
private _resolveMode(actionId: KeyBindingActionId, isDoublePress: boolean): VoiceMode {
|
||||
if (actionId === 'hands-free' || isDoublePress) {
|
||||
return 'hands-free'
|
||||
}
|
||||
return 'dictation'
|
||||
}
|
||||
|
||||
/**
|
||||
* 'command' 액션에는 아직 전용 핸들러가 없다.
|
||||
* 현행 동작대로 dictation 파이프라인으로 fallback 하며, 그 경로는 hold-to-talk 이므로
|
||||
* KEYBINDING_ACTIONS 의 holdMode(false)가 아니라 dictation 과 같은 값을 쓴다.
|
||||
*/
|
||||
private _resolveHoldMode(actionId: KeyBindingActionId, specHoldMode: boolean): boolean {
|
||||
if (actionId === 'command') return true
|
||||
return specHoldMode
|
||||
}
|
||||
|
||||
// ── 자막 모드 토글 (Phase 10.1) ─────────────────────────
|
||||
|
||||
private async _toggleCaption(): Promise<void> {
|
||||
|
|
@ -1111,16 +1121,10 @@ class VoiceModeService extends EventEmitter {
|
|||
this._cancelSession('user')
|
||||
}
|
||||
|
||||
// 핫키 리스너 해제
|
||||
const hotkey = getHotkeyService()
|
||||
if (this._hotkeyPressHandler) {
|
||||
hotkey.off('hotkey-pressed', this._hotkeyPressHandler)
|
||||
}
|
||||
if (this._hotkeyReleaseHandler) {
|
||||
hotkey.off('hotkey-released', this._hotkeyReleaseHandler)
|
||||
}
|
||||
if (this._doublePressHandler) {
|
||||
hotkey.off('double-press', this._doublePressHandler)
|
||||
// 키바인딩 리스너 해제
|
||||
if (this._keyBindingHandler) {
|
||||
getKeyBindingService().off('triggered', this._keyBindingHandler)
|
||||
this._keyBindingHandler = null
|
||||
}
|
||||
|
||||
// 오디오 리스너 해제
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue