feat(commands): multi-select ordered command pipeline with step reordering and single-pass composition (AI-05, AI-07)
This commit is contained in:
parent
f49acf0105
commit
10af20a0ad
157 changed files with 29455 additions and 913 deletions
|
|
@ -6,7 +6,7 @@ import { ipcSuccess, ipcError, ErrorCode } from '@d3ro/core/errors'
|
|||
import { getAudioCaptureService, calculateRMS, type CaptureLease } from '../services/AudioCaptureService'
|
||||
import { getMainWindow } from '../windows/WindowManager'
|
||||
import { configGet, configSet } from '../services/ConfigService'
|
||||
import type { SetDeviceParams } from '@d3ro/core/types'
|
||||
import type { SetDeviceParams, TestDeviceParams } from '@d3ro/core/types'
|
||||
|
||||
let testTimer: ReturnType<typeof setTimeout> | null = null
|
||||
let testAudioHandler: ((payload: { buffer: Buffer; timestamp: number }) => void) | null = null
|
||||
|
|
@ -23,7 +23,7 @@ let testLease: CaptureLease | null = null
|
|||
*/
|
||||
let testGeneration = 0
|
||||
|
||||
function stopAudioTest(): void {
|
||||
async function stopAudioTest(): Promise<void> {
|
||||
testGeneration += 1
|
||||
const service = getAudioCaptureService()
|
||||
if (testAudioHandler) {
|
||||
|
|
@ -41,7 +41,7 @@ function stopAudioTest(): void {
|
|||
testLastRms = 0
|
||||
const lease = testLease
|
||||
testLease = null
|
||||
lease?.release().catch(() => { /* ignore */ })
|
||||
await lease?.release().catch(() => { /* ignore */ })
|
||||
}
|
||||
|
||||
export function registerAudioHandlers(): void {
|
||||
|
|
@ -69,14 +69,23 @@ export function registerAudioHandlers(): void {
|
|||
}
|
||||
})
|
||||
|
||||
ipcMain.handle(IPC_CHANNELS.AUDIO.TEST_DEVICE, async () => {
|
||||
ipcMain.handle(IPC_CHANNELS.AUDIO.TEST_DEVICE, async (_event, params?: TestDeviceParams) => {
|
||||
try {
|
||||
// 이전 테스트가 진행 중이면 정리
|
||||
stopAudioTest()
|
||||
await stopAudioTest()
|
||||
const generation = testGeneration
|
||||
|
||||
const requestedDeviceId =
|
||||
typeof params?.deviceId === 'string' && params.deviceId.trim().length > 0
|
||||
? params.deviceId.trim()
|
||||
: undefined
|
||||
const durationMs =
|
||||
typeof params?.durationMs === 'number' && Number.isFinite(params.durationMs) && params.durationMs > 0
|
||||
? params.durationMs
|
||||
: 5000
|
||||
|
||||
const service = getAudioCaptureService()
|
||||
const lease = await service.acquire()
|
||||
const lease = await service.acquire(requestedDeviceId)
|
||||
if (generation !== testGeneration) {
|
||||
// 기다리는 사이 새 테스트가 시작됐거나 중지됐다 — 이 임대는 바로 놓는다
|
||||
await lease.release().catch(() => { /* ignore */ })
|
||||
|
|
@ -100,18 +109,18 @@ export function registerAudioHandlers(): void {
|
|||
}
|
||||
}, 100)
|
||||
|
||||
// 5초 후 자동 중지
|
||||
// durationMs(기본 5초) 후 자동 중지
|
||||
testTimer = setTimeout(() => {
|
||||
stopAudioTest()
|
||||
void stopAudioTest()
|
||||
const win = getMainWindow()
|
||||
if (win && !win.isDestroyed()) {
|
||||
win.webContents.send(IPC_CHANNELS.AUDIO.TEST_LEVEL, { level: 0, done: true })
|
||||
}
|
||||
}, 5000)
|
||||
}, durationMs)
|
||||
|
||||
return ipcSuccess({ averageLevel: 0, peakLevel: 0, hasAudio: true })
|
||||
} catch (err) {
|
||||
stopAudioTest()
|
||||
await stopAudioTest()
|
||||
return ipcError(
|
||||
ErrorCode.AudioDeviceNotFound,
|
||||
`Audio test failed: ${err instanceof Error ? err.message : String(err)}`,
|
||||
|
|
@ -121,7 +130,7 @@ export function registerAudioHandlers(): void {
|
|||
|
||||
// 테스트 수동 중지 (STOP 버튼)
|
||||
ipcMain.handle(IPC_CHANNELS.AUDIO.STOP_TEST, async () => {
|
||||
stopAudioTest()
|
||||
await stopAudioTest()
|
||||
const win = getMainWindow()
|
||||
if (win && !win.isDestroyed()) {
|
||||
win.webContents.send(IPC_CHANNELS.AUDIO.TEST_LEVEL, { level: 0, done: true })
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue