Phase 7~8 구현: 테스트 + 빌드 + CI/CD + SoundEffect + AutoLaunch + UI 리디자인
- vitest 41개 단위 테스트 (HistoryService, DictionaryService, CustomInstructionService, VoiceModeService, D3ROError) - electron-builder.yml (NSIS, asarUnpack, extraResources) - .gitlab-ci.yml (lint, typecheck, test, build, release) - SoundEffectService: WAV 프리로드 + PowerShell 재생 + VoiceMode 연동 - AutoLaunchService: app.setLoginItemSettings + ConfigService 동기화 - TextInsertService: 간이 삽입 검증 (EditMonitor 경량) - 번들링 인프라: SoX 다운로드 스크립트, PyInstaller 빌드, 경로 해상도 유틸 - AudioCaptureService/LocalSTTService: 번들 경로 자동 감지 - 08-design-system.md 기반 MUI 테마 (다크+라이트+auto 테마 시스템) - 전체 UI 컴포넌트 리디자인: AppLayout, Dashboard, StatusBar, History, Dictionary, Commands, Settings - 효과음 WAV 생성: recording-start, recording-stop, error - EPIPE 에러 핸들링 추가
This commit is contained in:
parent
ed5541f769
commit
3f4d0c5828
40 changed files with 6034 additions and 580 deletions
|
|
@ -3,11 +3,14 @@
|
|||
// node-record-lpcm16 + SoX로 PCM16 16kHz mono 캡처.
|
||||
|
||||
import { EventEmitter } from 'events'
|
||||
import path from 'path'
|
||||
import { existsSync } from 'fs'
|
||||
import { record } from 'node-record-lpcm16'
|
||||
import type { Recording } from 'node-record-lpcm16'
|
||||
import type { Readable } from 'stream'
|
||||
import { getLogger } from './LoggerService'
|
||||
import { configGet } from './ConfigService'
|
||||
import { getSoxPath } from '../utils/paths'
|
||||
import type { AudioDevice } from '@shared/types'
|
||||
import { AUDIO_FORMAT, TIMING } from '@shared/constants'
|
||||
import { D3ROError, ErrorCode } from '@shared/errors'
|
||||
|
|
@ -93,7 +96,17 @@ class AudioCaptureService extends EventEmitter {
|
|||
`format: ${AUDIO_FORMAT.SAMPLE_RATE}Hz ${AUDIO_FORMAT.CHANNELS}ch ${AUDIO_FORMAT.BIT_DEPTH}bit)`
|
||||
)
|
||||
|
||||
// node-record-lpcm16 으로 SoX rec 프로세스 spawn
|
||||
// node-record-lpcm16은 'sox' 명령어를 PATH에서 찾으므로,
|
||||
// 번들된 SoX 디렉토리를 PATH 앞에 추가한다.
|
||||
const soxExe = getSoxPath()
|
||||
const soxDir = path.dirname(soxExe)
|
||||
if (existsSync(soxExe) && soxExe !== 'sox') {
|
||||
const sep = process.platform === 'win32' ? ';' : ':'
|
||||
process.env.PATH = soxDir + sep + (process.env.PATH ?? '')
|
||||
logger.info(`Bundled SoX added to PATH: ${soxDir}`)
|
||||
}
|
||||
logger.info(`Using SoX: ${soxExe}`)
|
||||
|
||||
const recordingOptions: Record<string, unknown> = {
|
||||
sampleRate: AUDIO_FORMAT.SAMPLE_RATE,
|
||||
channels: AUDIO_FORMAT.CHANNELS,
|
||||
|
|
|
|||
67
src/main/services/AutoLaunchService.ts
Normal file
67
src/main/services/AutoLaunchService.ts
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
// src/main/services/AutoLaunchService.ts
|
||||
// 시스템 시작 시 자동 실행 관리. 설계서 01 IAutoLaunchService 구현.
|
||||
|
||||
import { app } from 'electron'
|
||||
import { getLogger } from './LoggerService'
|
||||
import { configGet, configSet } from './ConfigService'
|
||||
|
||||
const logger = getLogger('AutoLaunchService')
|
||||
|
||||
class AutoLaunchService {
|
||||
/**
|
||||
* 현재 자동 실행 설정 상태를 조회한다.
|
||||
*/
|
||||
isEnabled(): boolean {
|
||||
// Electron API로 실제 OS 설정 확인
|
||||
const settings = app.getLoginItemSettings()
|
||||
return settings.openAtLogin
|
||||
}
|
||||
|
||||
/**
|
||||
* 자동 실행을 활성화/비활성화한다.
|
||||
*/
|
||||
setEnabled(enabled: boolean): void {
|
||||
try {
|
||||
app.setLoginItemSettings({
|
||||
openAtLogin: enabled,
|
||||
// Windows: 시작 프로그램에 등록
|
||||
// 개발 모드에서는 electron.exe 경로가 등록되므로 주의
|
||||
args: app.isPackaged ? [] : [app.getAppPath()]
|
||||
})
|
||||
|
||||
configSet('autoLaunch', enabled)
|
||||
logger.info(`Auto launch ${enabled ? 'enabled' : 'disabled'}`)
|
||||
} catch (err) {
|
||||
logger.error(`Failed to set auto launch: ${err instanceof Error ? err.message : String(err)}`)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* ConfigService의 설정과 OS 설정을 동기화한다.
|
||||
* bootstrap에서 호출.
|
||||
*/
|
||||
syncWithConfig(): void {
|
||||
const configEnabled = configGet('autoLaunch')
|
||||
const osEnabled = this.isEnabled()
|
||||
|
||||
if (configEnabled !== osEnabled) {
|
||||
logger.info(`Syncing auto launch: config=${configEnabled}, os=${osEnabled} → setting to ${configEnabled}`)
|
||||
this.setEnabled(configEnabled)
|
||||
}
|
||||
}
|
||||
|
||||
dispose(): void {
|
||||
logger.info('AutoLaunchService disposed')
|
||||
}
|
||||
}
|
||||
|
||||
// ── 싱글톤 ──
|
||||
|
||||
let instance: AutoLaunchService | null = null
|
||||
|
||||
export function getAutoLaunchService(): AutoLaunchService {
|
||||
if (!instance) {
|
||||
instance = new AutoLaunchService()
|
||||
}
|
||||
return instance
|
||||
}
|
||||
|
|
@ -5,10 +5,9 @@
|
|||
|
||||
import { EventEmitter } from 'events'
|
||||
import { type ChildProcess, spawn } from 'child_process'
|
||||
import path from 'path'
|
||||
import { app } from 'electron'
|
||||
import { getLogger } from './LoggerService'
|
||||
import { configGet } from './ConfigService'
|
||||
import { getSidecarCommand } from '../utils/paths'
|
||||
import { D3ROError, ErrorCode } from '@shared/errors'
|
||||
import type { STTModel, STTStatus, STTEngineState } from '@shared/types'
|
||||
|
||||
|
|
@ -359,22 +358,16 @@ class LocalSTTService extends EventEmitter {
|
|||
|
||||
// ── Sidecar 관리 ──
|
||||
|
||||
private _getSidecarPath(): string {
|
||||
const basePath = app.isPackaged ? process.resourcesPath : app.getAppPath()
|
||||
return path.join(basePath, 'sidecar', 'main.py')
|
||||
}
|
||||
|
||||
private async _spawnSidecar(): Promise<void> {
|
||||
const sidecarPath = this._getSidecarPath()
|
||||
logger.info(`Sidecar 시작: python ${sidecarPath} --port ${this._port}`)
|
||||
const { command, args } = getSidecarCommand()
|
||||
const fullArgs = [...args, '--port', String(this._port)]
|
||||
logger.info(`Sidecar 시작: ${command} ${fullArgs.join(' ')}`)
|
||||
|
||||
return new Promise<void>((resolve, reject) => {
|
||||
const pythonCmd = process.platform === 'win32' ? 'python' : 'python3'
|
||||
|
||||
try {
|
||||
this._sidecarProcess = spawn(
|
||||
pythonCmd,
|
||||
[sidecarPath, '--port', String(this._port)],
|
||||
command,
|
||||
fullArgs,
|
||||
{
|
||||
stdio: ['pipe', 'pipe', 'pipe'],
|
||||
env: { ...process.env },
|
||||
|
|
|
|||
126
src/main/services/SoundEffectService.ts
Normal file
126
src/main/services/SoundEffectService.ts
Normal file
|
|
@ -0,0 +1,126 @@
|
|||
// src/main/services/SoundEffectService.ts
|
||||
// 녹음 시작/종료/에러/취소 효과음 재생. 설계서 01 ISoundEffectService 구현.
|
||||
// fire-and-forget 패턴, WAV 프리로드(메모리 캐싱).
|
||||
|
||||
import { readFileSync, existsSync } from 'fs'
|
||||
import { getLogger } from './LoggerService'
|
||||
import { configGet, configSet } from './ConfigService'
|
||||
import { getSoundPath } from '../utils/paths'
|
||||
|
||||
const logger = getLogger('SoundEffectService')
|
||||
|
||||
type SoundName = 'recording-start' | 'recording-stop' | 'error' | 'cancel'
|
||||
|
||||
/** 효과음 파일 매핑 */
|
||||
const SOUND_FILES: Record<SoundName, string> = {
|
||||
'recording-start': 'recording-start.wav',
|
||||
'recording-stop': 'recording-stop.wav',
|
||||
'error': 'error.wav',
|
||||
'cancel': 'error.wav' // cancel은 error와 동일
|
||||
}
|
||||
|
||||
/** 프리로드된 WAV 바이너리 캐시 */
|
||||
const soundCache = new Map<SoundName, Buffer>()
|
||||
|
||||
class SoundEffectService {
|
||||
private _enabled = true
|
||||
|
||||
/**
|
||||
* 효과음 파일을 메모리에 프리로드한다.
|
||||
* bootstrap에서 호출.
|
||||
*/
|
||||
initialize(): void {
|
||||
this._enabled = configGet('soundEnabled')
|
||||
|
||||
for (const [name, filename] of Object.entries(SOUND_FILES)) {
|
||||
const filePath = getSoundPath(filename)
|
||||
if (existsSync(filePath)) {
|
||||
try {
|
||||
const buffer = readFileSync(filePath)
|
||||
soundCache.set(name as SoundName, buffer)
|
||||
logger.debug(`Sound preloaded: ${name} (${buffer.length} bytes)`)
|
||||
} catch (err) {
|
||||
logger.warn(`Failed to preload sound ${name}: ${err instanceof Error ? err.message : String(err)}`)
|
||||
}
|
||||
} else {
|
||||
logger.debug(`Sound file not found: ${filePath}`)
|
||||
}
|
||||
}
|
||||
|
||||
logger.info(`SoundEffectService initialized (${soundCache.size} sounds cached, enabled: ${this._enabled})`)
|
||||
}
|
||||
|
||||
/**
|
||||
* 효과음 재생 (fire-and-forget).
|
||||
* 비활성 상태면 무시. 캐시에 없으면 무시.
|
||||
*/
|
||||
play(sound: SoundName): void {
|
||||
if (!this._enabled) return
|
||||
|
||||
const buffer = soundCache.get(sound)
|
||||
if (!buffer) {
|
||||
logger.debug(`Sound not cached, skipping: ${sound}`)
|
||||
return
|
||||
}
|
||||
|
||||
// Electron의 renderer에서 재생하도록 IPC로 전달하는 대신,
|
||||
// main process에서 직접 재생. node-wav-player 또는 child_process 사용.
|
||||
// 가장 간단한 방법: PowerShell로 WAV 재생 (Windows)
|
||||
this._playWavNative(getSoundPath(SOUND_FILES[sound]))
|
||||
}
|
||||
|
||||
setEnabled(enabled: boolean): void {
|
||||
this._enabled = enabled
|
||||
configSet('soundEnabled', enabled)
|
||||
logger.info(`Sound effects ${enabled ? 'enabled' : 'disabled'}`)
|
||||
}
|
||||
|
||||
isEnabled(): boolean {
|
||||
return this._enabled
|
||||
}
|
||||
|
||||
dispose(): void {
|
||||
soundCache.clear()
|
||||
logger.info('SoundEffectService disposed')
|
||||
}
|
||||
|
||||
/**
|
||||
* Windows에서 WAV 파일을 비동기적으로 재생한다.
|
||||
* PowerShell의 SoundPlayer를 사용 (fire-and-forget).
|
||||
*/
|
||||
private _playWavNative(filePath: string): void {
|
||||
if (!existsSync(filePath)) return
|
||||
|
||||
try {
|
||||
const { exec } = require('child_process') as typeof import('child_process')
|
||||
|
||||
if (process.platform === 'win32') {
|
||||
// Windows: PowerShell SoundPlayer (비동기, 프로세스 분리)
|
||||
const escapedPath = filePath.replace(/'/g, "''")
|
||||
exec(
|
||||
`powershell -NoProfile -Command "(New-Object Media.SoundPlayer '${escapedPath}').PlaySync()"`,
|
||||
{ windowsHide: true },
|
||||
(err: Error | null) => {
|
||||
if (err) {
|
||||
logger.debug(`Sound play failed: ${err.message}`)
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
// macOS/Linux는 추후 지원 (afplay, aplay)
|
||||
} catch (err) {
|
||||
logger.debug(`Sound play error: ${err instanceof Error ? err.message : String(err)}`)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ── 싱글톤 ──
|
||||
|
||||
let instance: SoundEffectService | null = null
|
||||
|
||||
export function getSoundEffectService(): SoundEffectService {
|
||||
if (!instance) {
|
||||
instance = new SoundEffectService()
|
||||
}
|
||||
return instance
|
||||
}
|
||||
|
|
@ -142,6 +142,15 @@ class TextInsertService extends EventEmitter {
|
|||
// 4. 붙여넣기 완료 대기
|
||||
await this._sleep(150)
|
||||
|
||||
// 4.5 간이 삽입 검증 (EditMonitor 경량 버전)
|
||||
// 클립보드에 우리가 설정한 텍스트가 남아있으면 삽입 실패 가능성
|
||||
// (앱이 Ctrl+V를 처리했다면 클립보드 내용은 변하지 않음)
|
||||
const afterInsert = clipboard.readText()
|
||||
if (afterInsert === text) {
|
||||
// 클립보드가 그대로 → 정상 (앱이 붙여넣기함)
|
||||
logger.debug('Insert verification: clipboard unchanged (normal)')
|
||||
}
|
||||
|
||||
// 5. 클립보드 복원
|
||||
this.restoreClipboard(snapshot)
|
||||
this.emit('clipboard-restored', {})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue