refactor(main): IPC 채널 SSOT 일원화 + AppConfig 타입 강화 (WS2)

- 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
This commit is contained in:
Yun Chan 2026-07-22 01:54:18 +09:00
parent b820c789bb
commit aef44289a5
15 changed files with 161 additions and 126 deletions

View file

@ -9,7 +9,7 @@ import type { CaptionConfig } from '@d3ro/core/types'
export function registerCaptionHandlers(): void {
// 시스템 오디오 루프백: setDisplayMediaRequestHandler로 audio: 'loopback' 설정
ipcMain.handle('system-audio:enable-loopback', async () => {
ipcMain.handle(IPC_CHANNELS.SYSTEM_AUDIO.ENABLE_LOOPBACK, async () => {
session.defaultSession.setDisplayMediaRequestHandler(async (_request, callback) => {
const sources = await desktopCapturer.getSources({ types: ['screen'] })
if (sources.length === 0) {
@ -21,7 +21,7 @@ export function registerCaptionHandlers(): void {
return ipcSuccess(undefined)
})
ipcMain.handle('system-audio:disable-loopback', async () => {
ipcMain.handle(IPC_CHANNELS.SYSTEM_AUDIO.DISABLE_LOOPBACK, async () => {
session.defaultSession.setDisplayMediaRequestHandler(null)
return ipcSuccess(undefined)
})

View file

@ -7,6 +7,7 @@ import { D3ROError, ErrorCode } from '@d3ro/core/errors'
import type { IPCResult } from '@d3ro/core/errors'
import { getCloudSyncService } from '../services/CloudSyncService'
import { getLogger } from '../services/LoggerService'
import { configSet } from '../services/ConfigService'
const logger = getLogger('cloud-sync-handlers')
@ -70,7 +71,7 @@ export function registerCloudSyncHandlers(): void {
ipcMain.handle(IPC_CHANNELS.CLOUD_SYNC.PUSH_ALL, async () => {
try {
const result = await sync.pushAll()
configSet('cloudSyncLastAt' as never, Date.now() as never)
configSet('cloudSyncLastAt', Date.now())
return ok(result)
} catch (e) {
return fail(e)
@ -80,7 +81,7 @@ export function registerCloudSyncHandlers(): void {
ipcMain.handle(IPC_CHANNELS.CLOUD_SYNC.PULL_ALL, async () => {
try {
const result = await sync.pullAll()
configSet('cloudSyncLastAt' as never, Date.now() as never)
configSet('cloudSyncLastAt', Date.now())
return ok(result)
} catch (e) {
return fail(e)

View file

@ -1,32 +1,22 @@
// 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 '../services/CustomInstructionService'
// IPC_CHANNELS에 instruction 채널이 없으므로 직접 문자열 사용
// (Phase 6 전용, 설계서 02에는 미포함)
const CHANNELS = {
GET_ALL: 'instruction:getAll',
GET_BY_ID: 'instruction:getById',
CREATE: 'instruction:create',
UPDATE: 'instruction:update',
DELETE: 'instruction:delete',
REORDER: 'instruction:reorder'
} as const
import type { CustomInstruction } from '@d3ro/core/types'
export function registerInstructionHandlers(): void {
ipcMain.handle(CHANNELS.GET_ALL, async () => {
ipcMain.handle(IPC_CHANNELS.INSTRUCTION.GET_ALL, async () => {
return ipcSuccess(getCustomInstructionService().getAll())
})
ipcMain.handle(CHANNELS.GET_BY_ID, async (_event, params: { id: string }) => {
ipcMain.handle(IPC_CHANNELS.INSTRUCTION.GET_BY_ID, async (_event, params: { id: string }) => {
return ipcSuccess(getCustomInstructionService().getById(params.id))
})
ipcMain.handle(
CHANNELS.CREATE,
IPC_CHANNELS.INSTRUCTION.CREATE,
async (
_event,
params: { name: string; description: string; prompt: string; icon?: string }
@ -41,7 +31,7 @@ export function registerInstructionHandlers(): void {
)
ipcMain.handle(
CHANNELS.UPDATE,
IPC_CHANNELS.INSTRUCTION.UPDATE,
async (_event, params: { id: string; data: Partial<CustomInstruction> }) => {
try {
const result = getCustomInstructionService().update(params.id, params.data)
@ -52,7 +42,7 @@ export function registerInstructionHandlers(): void {
}
)
ipcMain.handle(CHANNELS.DELETE, async (_event, params: { id: string }) => {
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')
@ -60,7 +50,7 @@ export function registerInstructionHandlers(): void {
return ipcSuccess(undefined)
})
ipcMain.handle(CHANNELS.REORDER, async (_event, params: { ids: string[] }) => {
ipcMain.handle(IPC_CHANNELS.INSTRUCTION.REORDER, async (_event, params: { ids: string[] }) => {
getCustomInstructionService().reorder(params.ids)
return ipcSuccess(undefined)
})

View file

@ -131,7 +131,7 @@ export function registerVoiceConversationHandlers(): void {
)
// finishListening — 렌더러에서 녹음 종료 버튼 클릭 시
ipcMain.handle('voiceConversation:finishListening', async () => {
ipcMain.handle(IPC_CHANNELS.VOICE_CONVERSATION.FINISH_LISTENING, async () => {
try {
await getVoiceConversationService().finishListening()
return ipcSuccess(undefined)

View file

@ -30,11 +30,11 @@ export function registerWindowHandlers(): void {
})
// 팝업 윈도우 hide 요청 (렌더러 → 메인)
ipcMain.on('window:hideResultPopup', () => {
ipcMain.on(IPC_CHANNELS.WINDOW.HIDE_RESULT_POPUP, () => {
hideResultPopup()
})
ipcMain.on('window:hideRecordingTip', () => {
ipcMain.on(IPC_CHANNELS.WINDOW.HIDE_RECORDING_TIP, () => {
hideRecordingTip()
})