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,39 @@
// src/renderer/utils/formatters.ts
// 공유 포맷팅 유틸리티 — SSOT, 중복 제거
/** 초 단위 duration → "M:SS" 형식 */
export function formatDuration(sec: number): string {
const m = Math.floor(sec / 60)
const s = Math.round(sec % 60)
return `${m}:${s.toString().padStart(2, '0')}`
}
/** 타임스탬프 → "YYYY-MM-DD" 날짜 키 (그룹핑용) */
export function getDateKey(ts: number): string {
const d = new Date(ts)
return `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, '0')}-${String(d.getDate()).padStart(2, '0')}`
}
/** 큰 숫자 → "1.2K" / "3.4M" 축약 */
export function formatNumber(n: number): string {
if (n >= 1000000) return `${(n / 1000000).toFixed(1)}M`
if (n >= 1000) return `${(n / 1000).toFixed(1)}K`
return `${n}`
}
/** ms → 녹음 시간 수치 ("12" 또는 "1:30") */
export function formatRecordingTime(ms: number): string {
const totalMin = Math.round(ms / 60000)
if (totalMin >= 60) {
const h = Math.floor(totalMin / 60)
const m = totalMin % 60
return `${h}:${m.toString().padStart(2, '0')}`
}
return `${totalMin}`
}
/** ms → 녹음 시간 단위 ("HR" 또는 "MIN") */
export function formatRecordingTimeUnit(ms: number): string {
const totalMin = Math.round(ms / 60000)
return totalMin >= 60 ? 'HR' : 'MIN'
}

View file

@ -0,0 +1,98 @@
// src/renderer/utils/systemAudioCapture.ts
// 시스템 오디오(데스크톱 소리) 캡처 — Electron setDisplayMediaRequestHandler + audio: 'loopback'
// contextIsolation: true 환경에서 preload IPC 브릿지를 통해 동작
let mediaStream: MediaStream | null = null
let audioContext: AudioContext | null = null
let processorNode: ScriptProcessorNode | null = null
const TARGET_SAMPLE_RATE = 16000
/**
* .
* 1. preload를 loopback
* 2. getDisplayMedia로 MediaStream
* 3. ScriptProcessorNode로 PCM16 16kHz mono
*/
export async function startSystemAudioCapture(
onAudioData: (pcm16Buffer: ArrayBuffer) => void,
): Promise<void> {
if (mediaStream) {
throw new Error('System audio capture already active')
}
// 1. 메인 프로세스에 loopback 핸들러 등록
await window.electronAPI.caption.enableLoopback()
// 2. getDisplayMedia — video: true 필수 (Chromium 제약), 이후 video track 제거
try {
mediaStream = await navigator.mediaDevices.getDisplayMedia({
video: true,
audio: true,
})
} catch (err) {
// loopback 핸들러 해제
await window.electronAPI.caption.disableLoopback()
throw err
}
// 3. loopback 핸들러 해제 (다른 getDisplayMedia 호출에 영향 방지)
await window.electronAPI.caption.disableLoopback()
// 4. 비디오 트랙 제거
mediaStream.getVideoTracks().forEach((t) => {
t.stop()
mediaStream?.removeTrack(t)
})
const audioTrack = mediaStream.getAudioTracks()[0]
if (!audioTrack) {
stopSystemAudioCapture()
throw new Error('No audio track in loopback stream')
}
// 5. AudioContext로 PCM 추출
audioContext = new AudioContext({ sampleRate: TARGET_SAMPLE_RATE })
const source = audioContext.createMediaStreamSource(new MediaStream([audioTrack]))
const bufferSize = 4096
processorNode = audioContext.createScriptProcessor(bufferSize, 1, 1)
processorNode.onaudioprocess = (event: AudioProcessingEvent) => {
const inputData = event.inputBuffer.getChannelData(0)
// Float32 → PCM16 변환
const pcm16 = new Int16Array(inputData.length)
for (let i = 0; i < inputData.length; i++) {
const s = Math.max(-1, Math.min(1, inputData[i]))
pcm16[i] = s < 0 ? s * 0x8000 : s * 0x7fff
}
onAudioData(pcm16.buffer)
}
source.connect(processorNode)
processorNode.connect(audioContext.destination)
}
export function stopSystemAudioCapture(): void {
if (processorNode) {
processorNode.disconnect()
processorNode.onaudioprocess = null
processorNode = null
}
if (audioContext) {
audioContext.close().catch(() => { /* ignore */ })
audioContext = null
}
if (mediaStream) {
mediaStream.getTracks().forEach((t) => t.stop())
mediaStream = null
}
}
export function isSystemAudioCaptureActive(): boolean {
return mediaStream !== null
}