// 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) }) }