refactor(desktop): session-scoped voice runtime, STT/LLM ports, caption ownership and meeting export fixes

This commit is contained in:
Yun Chan 2026-09-28 00:53:43 +09:00
parent 0adedf5e7b
commit 83cf9133ac
39 changed files with 4787 additions and 1061 deletions

View file

@ -7,9 +7,17 @@ import { getLogger } from './LoggerService'
import { configGet, configSet } from './ConfigService'
import { D3ROError, ErrorCode } from '@d3ro/core/errors'
import type { ScreenContext, CaptureContextResult } from '@d3ro/core/types'
import { waitForModifiersReleased } from './modifier-state'
const logger = getLogger('screen-context')
/**
* 선택 텍스트 캡처 전에 사용자가 수정자 키(Ctrl/Alt/Shift/Win)를 뗄 때까지 기다리는 최대 시간.
* 손을 떼지 않으면 캡처를 건너뛴다 — 수정자를 쥔 채 Ctrl+C 를 보내면 대상 앱엔 Ctrl+Alt+C 등이
* 들어가 복사가 되지 않고(AltGr 배열에선 문자가 입력되어 선택 영역을 덮어쓴다) 클립보드만 비워진다.
*/
const MODIFIER_RELEASE_TIMEOUT_MS = 800
// ============================================================
// nut-js 타입 (lazy import)
// ============================================================
@ -107,7 +115,7 @@ class ScreenContextService {
if (captureSelectedText) {
selectedTextAttempted = true
try {
selectedText = await this._captureSelectedText()
selectedText = await this.captureSelectedText()
} catch (error) {
logger.warn(
`Failed to capture selected text: ${error instanceof Error ? error.message : String(error)}`
@ -130,6 +138,20 @@ class ScreenContextService {
return { context, selectedTextAttempted }
}
/**
* 선택된 텍스트만 캡처한다 (클립보드 방식).
* 수정자 키가 눌려 있으면 뗄 때까지 잠깐 기다리고, 그래도 쥐고 있으면 캡처하지 않고 null 을
* 돌려준다(클립보드도 건드리지 않는다).
*/
async captureSelectedText(): Promise<string | null> {
const released = await waitForModifiersReleased(MODIFIER_RELEASE_TIMEOUT_MS)
if (!released) {
logger.info('Selected text capture skipped: modifier keys still held')
return null
}
return this._captureSelectedText()
}
/**
* ScreenContext를 LLM 시스템 프롬프트 접두사로 변환한다.
* 빈 컨텍스트면 빈 문자열을 반환.
@ -371,7 +393,9 @@ end try
}
/**
* 클립보드 복원 (TextInsertService와 동일 패턴).
* 클립보드 복원 — 저장해 둔 모든 형식(text/html/rtf/image)을 한 번에 되돌린다.
* 예전엔 첫 번째로 있는 형식 하나만 썼기 때문에 서식 있는 복사본이나 텍스트+이미지가
* 캡처 한 번에 평문으로 바뀌었다.
*/
private _restoreClipboard(snapshot: ClipboardSnapshot): void {
if (!snapshot.hasContent) {
@ -379,15 +403,12 @@ end try
return
}
if (snapshot.text) {
clipboard.writeText(snapshot.text)
} else if (snapshot.html) {
clipboard.writeHTML(snapshot.html)
} else if (snapshot.rtf) {
clipboard.writeRTF(snapshot.rtf)
} else if (snapshot.image) {
clipboard.writeImage(snapshot.image)
}
const data: Electron.Data = {}
if (snapshot.text) data.text = snapshot.text
if (snapshot.html) data.html = snapshot.html
if (snapshot.rtf) data.rtf = snapshot.rtf
if (snapshot.image) data.image = snapshot.image
clipboard.write(data)
}
private _sleep(ms: number): Promise<void> {