- ipc-channels.ts SSOT에 9개 그룹/키 추가: INSTRUCTION, SYSTEM_AUDIO, POPUP_RESULT/HISTORY/COMMAND/CAPTION, VOICE_PARTIAL, CLIPBOARD, APP, VOICE_CONVERSATION.FINISH_LISTENING - WindowManager/handlers/bootstrap 하드코딩 채널 -> IPC_CHANNELS 교체. 불일치 4건(result:* vs window:tip*)은 preload 재검증 후 SSOT로 통일. notifyRenderer channel: string -> IPCChannel 타입 좁힘. - AppConfig에 7개 누락 키 추가(customInstructions, llmChains, voiceCommandRules, voiceCommandsEnabled, activeInstructionId, activeChainId, captionAudioSource) -> as never 16건 제거. - ChainService/CustomInstructionService/WindowManager dynamic require -> static import. - services/index.ts 데드 레지스트리 제거 (import 0건). SKIP: ipcSuccess/ipcError 헬퍼 통일, catch 패턴(별도) 정책: docs/REFACTOR_POLICY.md DP2, DP9
57 lines
2 KiB
TypeScript
57 lines
2 KiB
TypeScript
// src/main/ipc/instruction-handlers.ts
|
|
|
|
import { ipcMain } from 'electron'
|
|
import { IPC_CHANNELS } from '@d3ro/core/ipc-channels'
|
|
import { ipcSuccess, ipcError, ErrorCode } from '@d3ro/core/errors'
|
|
import { getCustomInstructionService } from '../services/CustomInstructionService'
|
|
import type { CustomInstruction } from '@d3ro/core/types'
|
|
|
|
export function registerInstructionHandlers(): void {
|
|
ipcMain.handle(IPC_CHANNELS.INSTRUCTION.GET_ALL, async () => {
|
|
return ipcSuccess(getCustomInstructionService().getAll())
|
|
})
|
|
|
|
ipcMain.handle(IPC_CHANNELS.INSTRUCTION.GET_BY_ID, async (_event, params: { id: string }) => {
|
|
return ipcSuccess(getCustomInstructionService().getById(params.id))
|
|
})
|
|
|
|
ipcMain.handle(
|
|
IPC_CHANNELS.INSTRUCTION.CREATE,
|
|
async (
|
|
_event,
|
|
params: { name: string; description: string; prompt: string; icon?: string }
|
|
) => {
|
|
try {
|
|
const result = getCustomInstructionService().create(params)
|
|
return ipcSuccess(result)
|
|
} catch {
|
|
return ipcError(ErrorCode.ConfigWriteFailed, 'Failed to create instruction')
|
|
}
|
|
}
|
|
)
|
|
|
|
ipcMain.handle(
|
|
IPC_CHANNELS.INSTRUCTION.UPDATE,
|
|
async (_event, params: { id: string; data: Partial<CustomInstruction> }) => {
|
|
try {
|
|
const result = getCustomInstructionService().update(params.id, params.data)
|
|
return ipcSuccess(result)
|
|
} catch {
|
|
return ipcError(ErrorCode.ConfigWriteFailed, 'Failed to update instruction')
|
|
}
|
|
}
|
|
)
|
|
|
|
ipcMain.handle(IPC_CHANNELS.INSTRUCTION.DELETE, async (_event, params: { id: string }) => {
|
|
const result = getCustomInstructionService().delete(params.id)
|
|
if (!result) {
|
|
return ipcError(ErrorCode.ConfigWriteFailed, 'Cannot delete builtin instruction')
|
|
}
|
|
return ipcSuccess(undefined)
|
|
})
|
|
|
|
ipcMain.handle(IPC_CHANNELS.INSTRUCTION.REORDER, async (_event, params: { ids: string[] }) => {
|
|
getCustomInstructionService().reorder(params.ids)
|
|
return ipcSuccess(undefined)
|
|
})
|
|
}
|