fix(recording-tip): show "inserted" only after the text was actually inserted
The tip drew its done state on session-completed, before the async insert ran and even when auto-insert was off or the text was empty. A failed insert also left the screen-saver-level tip over the result popup's copy button. session-completed now says whether an insert follows, VoiceModeService emits text-inserted on success, and the tip hides first when the insert fails.
This commit is contained in:
parent
06365651fc
commit
e7937c877f
5 changed files with 104 additions and 12 deletions
|
|
@ -476,6 +476,7 @@ async function initVoiceMode(): Promise<void> {
|
||||||
voiceMode.on('audio-level', ({ level }) => tip.onAudioLevel(level))
|
voiceMode.on('audio-level', ({ level }) => tip.onAudioLevel(level))
|
||||||
voiceMode.on('partial-transcript', ({ text }) => tip.onPartialTranscript(text))
|
voiceMode.on('partial-transcript', ({ text }) => tip.onPartialTranscript(text))
|
||||||
voiceMode.on('insert-failed', ({ text }) => tip.onInsertFailed(text))
|
voiceMode.on('insert-failed', ({ text }) => tip.onInsertFailed(text))
|
||||||
|
voiceMode.on('text-inserted', () => tip.onTextInserted())
|
||||||
|
|
||||||
// 수정자 없는 Esc 로 진행 중인 받아쓰기(녹음·처리)를 취소한다. 녹음 팁은 포커스를 받지 않는 창이라
|
// 수정자 없는 Esc 로 진행 중인 받아쓰기(녹음·처리)를 취소한다. 녹음 팁은 포커스를 받지 않는 창이라
|
||||||
// 전역 keydown 을 직접 듣는다(제안 오버레이의 Esc 와 같은 방식). 세션이 없으면 아무 일도 하지 않는다.
|
// 전역 keydown 을 직접 듣는다(제안 오버레이의 Esc 와 같은 방식). 세션이 없으면 아무 일도 하지 않는다.
|
||||||
|
|
@ -494,8 +495,8 @@ async function initVoiceMode(): Promise<void> {
|
||||||
soundEffect.play('recording-start')
|
soundEffect.play('recording-start')
|
||||||
})
|
})
|
||||||
|
|
||||||
voiceMode.on('session-completed', ({ session, finalText, audioPath }) => {
|
voiceMode.on('session-completed', ({ session, finalText, audioPath, willInsert }) => {
|
||||||
tip.onSessionCompleted()
|
tip.onSessionCompleted(willInsert)
|
||||||
soundEffect.play('recording-stop')
|
soundEffect.play('recording-stop')
|
||||||
|
|
||||||
// 녹음은 완료 이벤트 전에 저장됐다 — 실제 저장 경로(없으면 null)만 히스토리에 남긴다.
|
// 녹음은 완료 이벤트 전에 저장됐다 — 실제 저장 경로(없으면 null)만 히스토리에 남긴다.
|
||||||
|
|
|
||||||
|
|
@ -84,7 +84,15 @@ export interface VoiceModeEvents {
|
||||||
}) => void
|
}) => void
|
||||||
'transcription-update': (payload: { text: string; isFinal: boolean }) => void
|
'transcription-update': (payload: { text: string; isFinal: boolean }) => void
|
||||||
/** audioPath: 저장된 녹음 WAV 경로(완료 이벤트 전에 저장됨). 오디오가 없거나 저장 실패면 null */
|
/** audioPath: 저장된 녹음 WAV 경로(완료 이벤트 전에 저장됨). 오디오가 없거나 저장 실패면 null */
|
||||||
'session-completed': (payload: { session: VoiceSession; finalText: string; audioPath: string | null }) => void
|
/** willInsert: 이어서 자동 입력을 시도하는지(자동 입력 꺼짐·빈 글이면 false) */
|
||||||
|
'session-completed': (payload: {
|
||||||
|
session: VoiceSession
|
||||||
|
finalText: string
|
||||||
|
audioPath: string | null
|
||||||
|
willInsert: boolean
|
||||||
|
}) => void
|
||||||
|
/** 완료된 세션의 글을 자동 입력했다 */
|
||||||
|
'text-inserted': (payload: { sessionId: string }) => void
|
||||||
'session-cancelled': (payload: {
|
'session-cancelled': (payload: {
|
||||||
session: VoiceSession
|
session: VoiceSession
|
||||||
reason: 'user' | 'timeout' | 'too-short'
|
reason: 'user' | 'timeout' | 'too-short'
|
||||||
|
|
@ -1122,7 +1130,8 @@ class VoiceModeService extends EventEmitter {
|
||||||
// Speakly 패턴: 먼저 IDLE 복귀 (다음 핫키 즉시 사용 가능). 표시 계층이 완료 이벤트로 팁을 숨긴다.
|
// Speakly 패턴: 먼저 IDLE 복귀 (다음 핫키 즉시 사용 가능). 표시 계층이 완료 이벤트로 팁을 숨긴다.
|
||||||
this._setRecognitionState(RecognitionState.COMPLETED)
|
this._setRecognitionState(RecognitionState.COMPLETED)
|
||||||
this._setAudioState(AudioState.STOPPED)
|
this._setAudioState(AudioState.STOPPED)
|
||||||
this.emit('session-completed', { session, finalText, audioPath })
|
const willInsert = Boolean(configGet('autoInsert')) && finalText.length > 0
|
||||||
|
this.emit('session-completed', { session, finalText, audioPath, willInsert })
|
||||||
this._endRun(run)
|
this._endRun(run)
|
||||||
|
|
||||||
// 텍스트 삽입은 세션과 무관하게 비동기 실행 (세션 블로킹 방지)
|
// 텍스트 삽입은 세션과 무관하게 비동기 실행 (세션 블로킹 방지)
|
||||||
|
|
@ -1140,6 +1149,7 @@ class VoiceModeService extends EventEmitter {
|
||||||
if (selectionCapture) await selectionCapture
|
if (selectionCapture) await selectionCapture
|
||||||
const insertMethod = configGet('insertMethod')
|
const insertMethod = configGet('insertMethod')
|
||||||
await getTextInsertService().insertText(finalText, insertMethod)
|
await getTextInsertService().insertText(finalText, insertMethod)
|
||||||
|
this.emit('text-inserted', { sessionId })
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.warn(`Text insert failed: ${describe(error)}`)
|
logger.warn(`Text insert failed: ${describe(error)}`)
|
||||||
// 삽입 실패 시 표시 계층이 ResultPopup에 텍스트를 보여 준다
|
// 삽입 실패 시 표시 계층이 ResultPopup에 텍스트를 보여 준다
|
||||||
|
|
|
||||||
|
|
@ -49,6 +49,8 @@ export interface RecordingTipPresenterOptions {
|
||||||
resultPopupMs?: number
|
resultPopupMs?: number
|
||||||
/** 완료 확인 표시 후 팁을 숨기기까지(ms). 기본 700 */
|
/** 완료 확인 표시 후 팁을 숨기기까지(ms). 기본 700 */
|
||||||
doneHideMs?: number
|
doneHideMs?: number
|
||||||
|
/** 완료 뒤 삽입 결과(성공·실패)를 기다리는 최대 시간 */
|
||||||
|
insertResultTimeoutMs?: number
|
||||||
timers?: RecordingTipTimers
|
timers?: RecordingTipTimers
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -57,6 +59,9 @@ export type RecordingTipSeverity = 'error' | 'warning'
|
||||||
|
|
||||||
export class RecordingTipPresenter {
|
export class RecordingTipPresenter {
|
||||||
private _hideTimer: ReturnType<typeof setTimeout> | null = null
|
private _hideTimer: ReturnType<typeof setTimeout> | null = null
|
||||||
|
/** 완료 뒤 삽입 결과를 기다리는 중 — "입력함"은 실제로 넣은 뒤에만 보인다 */
|
||||||
|
private _awaitingInsert = false
|
||||||
|
private readonly _insertResultTimeoutMs: number
|
||||||
private readonly _errorHideMs: number
|
private readonly _errorHideMs: number
|
||||||
private readonly _resultPopupMs: number
|
private readonly _resultPopupMs: number
|
||||||
private readonly _doneHideMs: number
|
private readonly _doneHideMs: number
|
||||||
|
|
@ -69,6 +74,7 @@ export class RecordingTipPresenter {
|
||||||
this._errorHideMs = options.errorHideMs ?? 3000
|
this._errorHideMs = options.errorHideMs ?? 3000
|
||||||
this._resultPopupMs = options.resultPopupMs ?? 10000
|
this._resultPopupMs = options.resultPopupMs ?? 10000
|
||||||
this._doneHideMs = options.doneHideMs ?? 700
|
this._doneHideMs = options.doneHideMs ?? 700
|
||||||
|
this._insertResultTimeoutMs = options.insertResultTimeoutMs ?? 5000
|
||||||
this._timers = options.timers ?? {
|
this._timers = options.timers ?? {
|
||||||
setTimeout: (fn, ms) => setTimeout(fn, ms),
|
setTimeout: (fn, ms) => setTimeout(fn, ms),
|
||||||
clearTimeout: (handle) => clearTimeout(handle),
|
clearTimeout: (handle) => clearTimeout(handle),
|
||||||
|
|
@ -78,6 +84,7 @@ export class RecordingTipPresenter {
|
||||||
/** 새 세션이 시작되면 이전 에러의 숨김 예약을 취소한다 (새 팁을 숨기지 않게) */
|
/** 새 세션이 시작되면 이전 에러의 숨김 예약을 취소한다 (새 팁을 숨기지 않게) */
|
||||||
onSessionStarted(): void {
|
onSessionStarted(): void {
|
||||||
this._cancelHide()
|
this._cancelHide()
|
||||||
|
this._awaitingInsert = false
|
||||||
}
|
}
|
||||||
|
|
||||||
onPhase(phase: RecordingTipPhase): void {
|
onPhase(phase: RecordingTipPhase): void {
|
||||||
|
|
@ -122,19 +129,46 @@ export class RecordingTipPresenter {
|
||||||
* 세션 완료 — "입력함"을 잠깐 보이고 숨긴다. 이전에는 즉시 사라져 성공했는지 알 수 없었다(2026-09-28).
|
* 세션 완료 — "입력함"을 잠깐 보이고 숨긴다. 이전에는 즉시 사라져 성공했는지 알 수 없었다(2026-09-28).
|
||||||
* 숨김 예약은 오류와 같은 핸들 하나 — 곧바로 새 세션이 시작되면 onSessionStarted 가 취소한다.
|
* 숨김 예약은 오류와 같은 핸들 하나 — 곧바로 새 세션이 시작되면 onSessionStarted 가 취소한다.
|
||||||
*/
|
*/
|
||||||
onSessionCompleted(): void {
|
onSessionCompleted(willInsert: boolean): void {
|
||||||
|
this._cancelHide()
|
||||||
|
// 자동 입력이 꺼졌거나 넣을 글이 없으면 아무것도 입력하지 않았다 — "입력함"을 보이지 않는다.
|
||||||
|
if (!willInsert) {
|
||||||
|
this._awaitingInsert = false
|
||||||
|
this._view.hide()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// 삽입은 완료 뒤 비동기로 끝난다. 결과가 오지 않으면(예외 경로) 잠시 뒤 숨긴다.
|
||||||
|
this._awaitingInsert = true
|
||||||
|
this._scheduleHide(this._insertResultTimeoutMs)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 자동 입력 성공 — 이제 "입력함"을 잠깐 보이고 숨긴다 */
|
||||||
|
onTextInserted(): void {
|
||||||
|
if (!this._awaitingInsert) return
|
||||||
|
this._awaitingInsert = false
|
||||||
this._cancelHide()
|
this._cancelHide()
|
||||||
this._view.showDone()
|
this._view.showDone()
|
||||||
this._hideTimer = this._timers.setTimeout(() => {
|
this._scheduleHide(this._doneHideMs)
|
||||||
this._hideTimer = null
|
|
||||||
this._view.hide()
|
|
||||||
}, this._doneHideMs)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
onInsertFailed(text: string): void {
|
onInsertFailed(text: string): void {
|
||||||
|
// 팁은 결과 팝업보다 위 레벨이라 같은 자리에 남으면 복사 버튼을 덮는다 — 먼저 내린다.
|
||||||
|
if (this._awaitingInsert) {
|
||||||
|
this._awaitingInsert = false
|
||||||
|
this._cancelHide()
|
||||||
|
this._view.hide()
|
||||||
|
}
|
||||||
this._view.showResult(text, this._resultPopupMs)
|
this._view.showResult(text, this._resultPopupMs)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _scheduleHide(ms: number): void {
|
||||||
|
this._hideTimer = this._timers.setTimeout(() => {
|
||||||
|
this._hideTimer = null
|
||||||
|
this._awaitingInsert = false
|
||||||
|
this._view.hide()
|
||||||
|
}, ms)
|
||||||
|
}
|
||||||
|
|
||||||
dispose(): void {
|
dispose(): void {
|
||||||
this._cancelHide()
|
this._cancelHide()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -353,6 +353,21 @@ describe('표시 이벤트', () => {
|
||||||
expect(phases).toEqual(['recording', 'thinking'])
|
expect(phases).toEqual(['recording', 'thinking'])
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('자동 삽입이 끝나면 text-inserted 를 내보낸다(완료 이벤트는 willInsert 로 예고한다)', async () => {
|
||||||
|
const svc = getVoiceModeService()
|
||||||
|
const inserted: string[] = []
|
||||||
|
const willInsert: boolean[] = []
|
||||||
|
svc.on('session-completed', (p) => willInsert.push(p.willInsert))
|
||||||
|
svc.on('text-inserted', ({ sessionId }) => inserted.push(sessionId))
|
||||||
|
|
||||||
|
await svc.startSession('dictation')
|
||||||
|
audioBus.emit('audio-data', { buffer: SPEECH })
|
||||||
|
advanceClock(1000)
|
||||||
|
await svc.stopSession()
|
||||||
|
await vi.waitFor(() => expect(inserted).toHaveLength(1))
|
||||||
|
expect(willInsert).toEqual([true])
|
||||||
|
})
|
||||||
|
|
||||||
it('자동 삽입이 실패하면 insert-failed 를 내보낸다', async () => {
|
it('자동 삽입이 실패하면 insert-failed 를 내보낸다', async () => {
|
||||||
mockInsert.insertText.mockRejectedValueOnce(new Error('clipboard busy'))
|
mockInsert.insertText.mockRejectedValueOnce(new Error('clipboard busy'))
|
||||||
const svc = getVoiceModeService()
|
const svc = getVoiceModeService()
|
||||||
|
|
|
||||||
|
|
@ -93,11 +93,13 @@ describe('RecordingTipPresenter', () => {
|
||||||
expect(view.calls).toEqual(['error:x'])
|
expect(view.calls).toEqual(['error:x'])
|
||||||
})
|
})
|
||||||
|
|
||||||
it('완료는 "입력함"을 잠깐 보이고 숨기며, 곧바로 시작한 새 세션의 팁은 숨기지 않는다', () => {
|
it('입력에 성공하면 "입력함"을 잠깐 보이고 숨기며, 곧바로 시작한 새 세션의 팁은 숨기지 않는다', () => {
|
||||||
const view = fakeView()
|
const view = fakeView()
|
||||||
const presenter = new RecordingTipPresenter(view)
|
const presenter = new RecordingTipPresenter(view)
|
||||||
presenter.onPhase('recording')
|
presenter.onPhase('recording')
|
||||||
presenter.onSessionCompleted()
|
presenter.onSessionCompleted(true)
|
||||||
|
expect(view.calls).toEqual(['show'])
|
||||||
|
presenter.onTextInserted()
|
||||||
vi.advanceTimersByTime(699)
|
vi.advanceTimersByTime(699)
|
||||||
expect(view.calls).toEqual(['show', 'done'])
|
expect(view.calls).toEqual(['show', 'done'])
|
||||||
vi.advanceTimersByTime(1)
|
vi.advanceTimersByTime(1)
|
||||||
|
|
@ -105,11 +107,41 @@ describe('RecordingTipPresenter', () => {
|
||||||
|
|
||||||
const view2 = fakeView()
|
const view2 = fakeView()
|
||||||
const presenter2 = new RecordingTipPresenter(view2)
|
const presenter2 = new RecordingTipPresenter(view2)
|
||||||
presenter2.onSessionCompleted()
|
presenter2.onSessionCompleted(true)
|
||||||
|
presenter2.onTextInserted()
|
||||||
vi.advanceTimersByTime(300)
|
vi.advanceTimersByTime(300)
|
||||||
presenter2.onSessionStarted()
|
presenter2.onSessionStarted()
|
||||||
presenter2.onPhase('recording')
|
presenter2.onPhase('recording')
|
||||||
vi.advanceTimersByTime(2000)
|
vi.advanceTimersByTime(2000)
|
||||||
expect(view2.calls).toEqual(['done', 'show'])
|
expect(view2.calls).toEqual(['done', 'show'])
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('자동 입력을 하지 않는 완료는 "입력함" 없이 숨긴다', () => {
|
||||||
|
const view = fakeView()
|
||||||
|
const presenter = new RecordingTipPresenter(view)
|
||||||
|
presenter.onPhase('recording')
|
||||||
|
presenter.onSessionCompleted(false)
|
||||||
|
presenter.onTextInserted()
|
||||||
|
expect(view.calls).toEqual(['show', 'hide'])
|
||||||
|
})
|
||||||
|
|
||||||
|
it('입력이 실패하면 "입력함" 없이 팁을 내리고 결과 팝업을 띄운다', () => {
|
||||||
|
const view = fakeView()
|
||||||
|
const presenter = new RecordingTipPresenter(view)
|
||||||
|
presenter.onPhase('recording')
|
||||||
|
presenter.onSessionCompleted(true)
|
||||||
|
presenter.onInsertFailed('text')
|
||||||
|
vi.advanceTimersByTime(10000)
|
||||||
|
expect(view.calls).toEqual(['show', 'hide', 'result:text:10000'])
|
||||||
|
})
|
||||||
|
|
||||||
|
it('입력 결과가 오지 않으면 잠시 뒤 숨기고, 늦게 온 성공은 무시한다', () => {
|
||||||
|
const view = fakeView()
|
||||||
|
const presenter = new RecordingTipPresenter(view)
|
||||||
|
presenter.onPhase('recording')
|
||||||
|
presenter.onSessionCompleted(true)
|
||||||
|
vi.advanceTimersByTime(5000)
|
||||||
|
presenter.onTextInserted()
|
||||||
|
expect(view.calls).toEqual(['show', 'hide'])
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue