- cloud-sync-handlers 수동 ok/fail -> ipcSuccess/ipcError 헬퍼 (6 핸들러)
- catch {} -> catch(error) 에러 메시지 보강 32건 (11 ipc handler 파일)
KEEP: template-handlers(주석 명시 에러 무시), license-handlers(이미 헬퍼 사용),
audio-handlers stop().catch(() => {})(의도적 무시)
정책: docs/REFACTOR_POLICY.md DP2
85 lines
3.2 KiB
TypeScript
85 lines
3.2 KiB
TypeScript
// src/main/ipc/hotkey-handlers.ts
|
|
|
|
import { ipcMain } from 'electron'
|
|
import { IPC_CHANNELS } from '@d3ro/core/ipc-channels'
|
|
import { ipcSuccess, ipcError, ErrorCode } from '@d3ro/core/errors'
|
|
import { getHotkeyService } from '../services/HotkeyService'
|
|
import { configGet, configSet } from '../services/ConfigService'
|
|
import type { SetHotkeyParams, SetEnabledParams } from '@d3ro/core/types'
|
|
|
|
export function registerHotkeyHandlers(): void {
|
|
ipcMain.handle(IPC_CHANNELS.HOTKEY.GET_DICTATION_SHORTCUT, async () => {
|
|
return ipcSuccess(configGet('dictationShortcut'))
|
|
})
|
|
|
|
ipcMain.handle(IPC_CHANNELS.HOTKEY.SET_DICTATION_SHORTCUT, async (_event, params: SetHotkeyParams) => {
|
|
try {
|
|
configSet('dictationShortcut', params.binding)
|
|
getHotkeyService().loadFromConfig()
|
|
return ipcSuccess(undefined)
|
|
} catch (error) {
|
|
const message = error instanceof Error ? error.message : String(error)
|
|
return ipcError(ErrorCode.HotkeyRegistrationFailed, `Failed to set dictation shortcut: ${message}`)
|
|
}
|
|
})
|
|
|
|
ipcMain.handle(IPC_CHANNELS.HOTKEY.GET_HANDS_FREE_SHORTCUT, async () => {
|
|
return ipcSuccess(configGet('handsFreeShortcut'))
|
|
})
|
|
|
|
ipcMain.handle(IPC_CHANNELS.HOTKEY.SET_HANDS_FREE_SHORTCUT, async (_event, params: SetHotkeyParams) => {
|
|
try {
|
|
configSet('handsFreeShortcut', params.binding)
|
|
getHotkeyService().loadFromConfig()
|
|
return ipcSuccess(undefined)
|
|
} catch (error) {
|
|
const message = error instanceof Error ? error.message : String(error)
|
|
return ipcError(ErrorCode.HotkeyRegistrationFailed, `Failed to set hands-free shortcut: ${message}`)
|
|
}
|
|
})
|
|
|
|
ipcMain.handle(IPC_CHANNELS.HOTKEY.GET_COMMAND_SHORTCUT, async () => {
|
|
return ipcSuccess(configGet('commandShortcut'))
|
|
})
|
|
|
|
ipcMain.handle(IPC_CHANNELS.HOTKEY.SET_COMMAND_SHORTCUT, async (_event, params: SetHotkeyParams) => {
|
|
try {
|
|
configSet('commandShortcut', params.binding)
|
|
getHotkeyService().loadFromConfig()
|
|
return ipcSuccess(undefined)
|
|
} catch (error) {
|
|
const message = error instanceof Error ? error.message : String(error)
|
|
return ipcError(ErrorCode.HotkeyRegistrationFailed, `Failed to set command shortcut: ${message}`)
|
|
}
|
|
})
|
|
|
|
ipcMain.handle(IPC_CHANNELS.HOTKEY.GET_CAPTION_SHORTCUT, async () => {
|
|
return ipcSuccess(configGet('captionShortcut'))
|
|
})
|
|
|
|
ipcMain.handle(IPC_CHANNELS.HOTKEY.SET_CAPTION_SHORTCUT, async (_event, params: SetHotkeyParams) => {
|
|
try {
|
|
configSet('captionShortcut', params.binding)
|
|
getHotkeyService().loadFromConfig()
|
|
return ipcSuccess(undefined)
|
|
} catch (error) {
|
|
const message = error instanceof Error ? error.message : String(error)
|
|
return ipcError(ErrorCode.HotkeyRegistrationFailed, `Failed to set caption shortcut: ${message}`)
|
|
}
|
|
})
|
|
|
|
ipcMain.handle(IPC_CHANNELS.HOTKEY.IS_ENABLED, async () => {
|
|
return ipcSuccess(configGet('hotkeyEnabled'))
|
|
})
|
|
|
|
ipcMain.handle(IPC_CHANNELS.HOTKEY.SET_ENABLED, async (_event, params: SetEnabledParams) => {
|
|
configSet('hotkeyEnabled', params.enabled)
|
|
const hotkey = getHotkeyService()
|
|
if (params.enabled) {
|
|
hotkey.start()
|
|
} else {
|
|
hotkey.stop()
|
|
}
|
|
return ipcSuccess(undefined)
|
|
})
|
|
}
|