Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

fix(voice-input): 待命窗口到期即禁止挂载重新开麦

Dash26bab9f3bd26
diff --git a/apps/desktop/src/renderer/voice-input/WebMicAudioEngine.ts b/apps/desktop/src/renderer/voice-input/WebMicAudioEngine.ts
index d7276d1c8b..bfb7205882 100644
--- a/apps/desktop/src/renderer/voice-input/WebMicAudioEngine.ts
+++ b/apps/desktop/src/renderer/voice-input/WebMicAudioEngine.ts
@@ -1059,7 +1059,7 @@ export function noteVoiceInputUse(): void {
*/
function isWithinVoiceInputUseWindow(): boolean {
if (lastVoiceInputUseAt === undefined) return false;
- return keepAliveMonotonicNow() - lastVoiceInputUseAt <= KEEP_ALIVE_MIC_IDLE_TTL_MS;
+ return keepAliveMonotonicNow() - lastVoiceInputUseAt < KEEP_ALIVE_MIC_IDLE_TTL_MS;
}
/**
diff --git a/apps/desktop/src/renderer/voice-input/__tests__/WebMicAudioEngine.keepAliveIdle.test.ts b/apps/desktop/src/renderer/voice-input/__tests__/WebMicAudioEngine.keepAliveIdle.test.ts
index 80145fdb76..2dbe225451 100644
--- a/apps/desktop/src/renderer/voice-input/__tests__/WebMicAudioEngine.keepAliveIdle.test.ts
+++ b/apps/desktop/src/renderer/voice-input/__tests__/WebMicAudioEngine.keepAliveIdle.test.ts
@@ -166,7 +166,7 @@ describe('keep-alive microphone idle window', () => {
expect(getUserMedia).not.toHaveBeenCalled();
});
- it('does not relight the microphone from a later mount after the idle release', async () => {
+ it.each([0, 60 * 1000])('does not relight the microphone %i ms after the idle release', async (delay) => {
mod.noteVoiceInputUse();
await mod.prewarmVoiceInputMicrophone({ workletUrl: WORKLET_URL });
await vi.advanceTimersByTimeAsync(IDLE_TTL_MS);
@@ -176,7 +176,7 @@ describe('keep-alive microphone idle window', () => {
// Past the window the user stopped dictating: remounting the ChatInput (a new
// task, a settings change) must not start a fresh 30-minute window, otherwise
// the indicator never goes out while the user just keeps working.
- await vi.advanceTimersByTimeAsync(60 * 1000);
+ await vi.advanceTimersByTimeAsync(delay);
await mod.prewarmVoiceInputMicrophone({ workletUrl: WORKLET_URL });
expect(getUserMedia).not.toHaveBeenCalled();
@@ -304,6 +304,8 @@ describe('keep-alive microphone idle window', () => {
await vi.advanceTimersByTimeAsync(0);
expect(track.stopped).toBe(true);
+ await mod.prewarmVoiceInputMicrophone({ workletUrl: WORKLET_URL });
+ expect(getUserMedia).toHaveBeenCalledTimes(1);
});
it('stops a stream that arrives after the session was released mid-startup', async () => {
@@ -510,6 +512,11 @@ describe('keep-alive microphone idle window', () => {
// happen until the machine wakes up.
expect(onInterrupted).toHaveBeenCalledTimes(1);
expect(track.stopped).toBe(true);
+ // The UI stops the interrupted engine after the power notification. That
+ // cleanup must not create a fresh use window when the window remounts.
+ await engine.stop();
+ await mod.prewarmVoiceInputMicrophone({ workletUrl: WORKLET_URL });
+ expect(getUserMedia).toHaveBeenCalledTimes(1);
});
it('reports cancellation when the shared context fails after a release', async () => {