feat(V2-1a): Monorepo 구조 전환 — apps/desktop으로 V1 이동

- npm workspaces 루트 (apps/*, packages/*) 세팅
- V1 전체를 apps/desktop/으로 git mv (src, resources, tests, sidecar,
  scripts, electron.vite.config.ts, electron-builder.yml, vitest.config.ts,
  tsconfig.node.json, tsconfig.web.json)
- apps/desktop/package.json 신규 (name=@d3ro/desktop)
- productName: 'd3ro-voice' 명시 — app.getName()을 고정하여 userData 경로
  %APPDATA%\d3ro-voice\ 그대로 유지 (기존 DB/설정 연속성 보장)
- 루트 package.json을 workspace 루트로 재구성, 공통 devDep만 유지
  (typescript, eslint, prettier)
- turbo.json, tsconfig.base.json 추가 (Turborepo 자체 설치는 별도 sub-phase)
- memory/project_status.md 생성 (규칙 13)

검증:
- npm run typecheck 통과
- npm run build 통과 (electron-vite main+preload+renderer)
- npm run dev 실제 실행 → DB/핫키/Ollama 자동 실행 모두 정상
This commit is contained in:
yunchan8804 2026-04-08 14:04:41 +09:00
parent 3a160b9032
commit 45a580878a
178 changed files with 214 additions and 0 deletions

View file

@ -0,0 +1,101 @@
// src/main/ipc/audio-handlers.ts
import { ipcMain } from 'electron'
import { IPC_CHANNELS } from '@shared/ipc-channels'
import { ipcSuccess, ipcError, ErrorCode } from '@shared/errors'
import { getAudioCaptureService, calculateRMS } from '../services/AudioCaptureService'
import { getMainWindow } from '../windows/WindowManager'
import { configGet, configSet } from '../services/ConfigService'
import { getLogger } from '../services/LoggerService'
import type { SetDeviceParams } from '@shared/types'
const logger = getLogger('audio-handlers')
let testTimer: ReturnType<typeof setTimeout> | null = null
let testAudioHandler: ((payload: { buffer: Buffer; timestamp: number }) => void) | null = null
let testLevelInterval: ReturnType<typeof setInterval> | null = null
let testLastRms = 0
function stopAudioTest(): void {
const service = getAudioCaptureService()
if (testAudioHandler) {
service.off('audio-data', testAudioHandler)
testAudioHandler = null
}
if (testLevelInterval) {
clearInterval(testLevelInterval)
testLevelInterval = null
}
if (testTimer) {
clearTimeout(testTimer)
testTimer = null
}
testLastRms = 0
service.stop().catch(() => { /* ignore */ })
}
export function registerAudioHandlers(): void {
ipcMain.handle(IPC_CHANNELS.AUDIO.GET_DEVICES, async () => {
try {
const devices = await getAudioCaptureService().getDevices()
return ipcSuccess(devices)
} catch {
return ipcError(ErrorCode.AudioDeviceNotFound, 'Failed to enumerate audio devices')
}
})
ipcMain.handle(IPC_CHANNELS.AUDIO.GET_SELECTED_DEVICE, async () => {
return ipcSuccess(configGet('selectedDeviceId'))
})
ipcMain.handle(IPC_CHANNELS.AUDIO.SET_SELECTED_DEVICE, async (_event, params: SetDeviceParams) => {
try {
configSet('selectedDeviceId', params.deviceId)
return ipcSuccess(undefined)
} catch {
return ipcError(ErrorCode.AudioDeviceNotFound, 'Failed to set device')
}
})
ipcMain.handle(IPC_CHANNELS.AUDIO.TEST_DEVICE, async () => {
try {
// 이전 테스트가 진행 중이면 정리
stopAudioTest()
const service = getAudioCaptureService()
await service.start()
// 오디오 데이터에서 RMS 추적
testAudioHandler = (payload: { buffer: Buffer; timestamp: number }) => {
testLastRms = calculateRMS(payload.buffer)
}
service.on('audio-data', testAudioHandler)
// 100ms 간격으로 레벨을 렌더러에 전송
testLevelInterval = setInterval(() => {
const level = testLastRms > 0 ? Math.min(1.0, Math.pow(testLastRms, 0.28)) : 0
const win = getMainWindow()
if (win && !win.isDestroyed()) {
win.webContents.send('audio:testLevel', { level })
}
}, 100)
// 5초 후 자동 중지
testTimer = setTimeout(() => {
stopAudioTest()
const win = getMainWindow()
if (win && !win.isDestroyed()) {
win.webContents.send('audio:testLevel', { level: 0 })
}
}, 5000)
return ipcSuccess({ averageLevel: 0, peakLevel: 0, hasAudio: true })
} catch (err) {
stopAudioTest()
return ipcError(
ErrorCode.AudioDeviceNotFound,
`Audio test failed: ${err instanceof Error ? err.message : String(err)}`,
)
}
})
}