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(desktop): 组合取消配对结束,并收紧 Windows helper 启动失败

Dash09dee0458c22
diff --git a/apps/desktop/native/voice-input/windows-function-key-listener/src/main.rs b/apps/desktop/native/voice-input/windows-function-key-listener/src/main.rs
index bf14dbff17..2ce75ac670 100644
--- a/apps/desktop/native/voice-input/windows-function-key-listener/src/main.rs
+++ b/apps/desktop/native/voice-input/windows-function-key-listener/src/main.rs
@@ -72,7 +72,7 @@ mod windows_listener {
}
}
- if key_down && ACTIVE.swap(false, Ordering::Relaxed) && modifier_bit != 0 {
+ if key_down && event.vkCode != target_vk && ACTIVE.swap(false, Ordering::Relaxed) {
emit_canceled();
}
diff --git a/apps/desktop/src/main/voice-input/ShortcutHoldPhaseController.ts b/apps/desktop/src/main/voice-input/ShortcutHoldPhaseController.ts
index 4a8340efe3..1c0106ed49 100644
--- a/apps/desktop/src/main/voice-input/ShortcutHoldPhaseController.ts
+++ b/apps/desktop/src/main/voice-input/ShortcutHoldPhaseController.ts
@@ -52,6 +52,7 @@ export class ShortcutHoldPhaseController {
this.holdThresholdReached = false;
if (targetDown) {
this.canceledUntilRelease = true;
+ this.options.onTrigger('end');
return;
}
this.canceledUntilRelease = false;
diff --git a/apps/desktop/src/main/voice-input/WindowsFunctionKeyShortcutListener.ts b/apps/desktop/src/main/voice-input/WindowsFunctionKeyShortcutListener.ts
index 3237585fe7..3559214792 100644
--- a/apps/desktop/src/main/voice-input/WindowsFunctionKeyShortcutListener.ts
+++ b/apps/desktop/src/main/voice-input/WindowsFunctionKeyShortcutListener.ts
@@ -102,6 +102,7 @@ export class WindowsFunctionKeyShortcutListener {
code,
error: result.error,
});
+ this.scheduleRestart(code, null, null);
}
})
.catch((error: unknown) => {
@@ -109,6 +110,7 @@ export class WindowsFunctionKeyShortcutListener {
code,
error: error instanceof Error ? error.message : String(error),
});
+ this.scheduleRestart(code, null, null);
});
}
@@ -205,13 +207,6 @@ export class WindowsFunctionKeyShortcutListener {
child.on('exit', (exitCode, signal) => {
const wasCurrentChild = this.child === child;
- if (wasCurrentChild) {
- this.child = null;
- this.ready = false;
- this.clearStableTimer();
- this.phaseController.releaseIfPressed();
- this.phaseController.reset();
- }
if (!settled) {
settle({
ok: false,
@@ -219,6 +214,13 @@ export class WindowsFunctionKeyShortcutListener {
});
return;
}
+ if (wasCurrentChild) {
+ this.child = null;
+ this.ready = false;
+ this.clearStableTimer();
+ this.phaseController.releaseIfPressed();
+ this.phaseController.reset();
+ }
log.debug('Windows function key listener exited', { exitCode, signal });
if (wasCurrentChild && this.shortcutCode === code)
this.scheduleRestart(code, exitCode, signal);
diff --git a/apps/desktop/src/main/voice-input/__tests__/MacModifierShortcutListenerStartRace.test.ts b/apps/desktop/src/main/voice-input/__tests__/MacModifierShortcutListenerStartRace.test.ts
index 1454c92e56..e7f2fc9305 100644
--- a/apps/desktop/src/main/voice-input/__tests__/MacModifierShortcutListenerStartRace.test.ts
+++ b/apps/desktop/src/main/voice-input/__tests__/MacModifierShortcutListenerStartRace.test.ts
@@ -294,7 +294,7 @@ describe('MacModifierShortcutListener start race', () => {
mocks.stdoutDataHandlers[0]?.('{"type":"keys","keys":["Function:F24","ShiftLeft"]}\n');
mocks.stdoutDataHandlers[0]?.('{"type":"keys","keys":["Function:F24"]}\n');
mocks.stdoutDataHandlers[0]?.('{"type":"keys","keys":[]}\n');
- expect(onTrigger.mock.calls.map(([phase]) => phase)).toEqual(['start']);
+ expect(onTrigger.mock.calls.map(([phase]) => phase)).toEqual(['start', 'end']);
onTrigger.mockClear();
mocks.stdoutDataHandlers[0]?.('{"type":"keys","keys":["Function:F24"]}\n');
diff --git a/apps/desktop/src/main/voice-input/__tests__/ShortcutHoldPhaseController.test.ts b/apps/desktop/src/main/voice-input/__tests__/ShortcutHoldPhaseController.test.ts
index 86da73bd0b..f44b350d94 100644
--- a/apps/desktop/src/main/voice-input/__tests__/ShortcutHoldPhaseController.test.ts
+++ b/apps/desktop/src/main/voice-input/__tests__/ShortcutHoldPhaseController.test.ts
@@ -65,7 +65,7 @@ describe('ShortcutHoldPhaseController', () => {
controller.setPressed(true, true);
controller.setPressed(false, false);
- expect(onTrigger.mock.calls.map(([phase]) => phase)).toEqual(['start']);
+ expect(onTrigger.mock.calls.map(([phase]) => phase)).toEqual(['start', 'end']);
});
it('starts a new activation only after the cancelled target key is released', () => {
@@ -79,6 +79,6 @@ describe('ShortcutHoldPhaseController', () => {
vi.advanceTimersByTime(450);
controller.setPressed(false, false);
- expect(onTrigger.mock.calls.map(([phase]) => phase)).toEqual(['start', 'start', 'end']);
+ expect(onTrigger.mock.calls.map(([phase]) => phase)).toEqual(['start', 'end', 'start', 'end']);
});
});
diff --git a/apps/desktop/src/main/voice-input/__tests__/WindowsFunctionKeyShortcutListener.test.ts b/apps/desktop/src/main/voice-input/__tests__/WindowsFunctionKeyShortcutListener.test.ts
index ec865c84f8..eb7e387880 100644
--- a/apps/desktop/src/main/voice-input/__tests__/WindowsFunctionKeyShortcutListener.test.ts
+++ b/apps/desktop/src/main/voice-input/__tests__/WindowsFunctionKeyShortcutListener.test.ts
@@ -123,7 +123,7 @@ describe('WindowsFunctionKeyShortcutListener', () => {
child.stdoutData('{"type":"pressed","pressed":true}\n');
child.stdoutData('{"type":"pressed","pressed":false}\n');
- expect(onTrigger.mock.calls.map(([phase]) => phase)).toEqual(['start']);
+ expect(onTrigger.mock.calls.map(([phase]) => phase)).toEqual(['start', 'end']);
listener.stop();
});
@@ -162,6 +162,38 @@ describe('WindowsFunctionKeyShortcutListener', () => {
listener.stop();
});
+ it('reports a real start failure when the helper exits before ready', async () => {
+ const { WindowsFunctionKeyShortcutListener } =
+ await import('../WindowsFunctionKeyShortcutListener.js');
+ const listener = new WindowsFunctionKeyShortcutListener({ onTrigger: vi.fn() });
+ const starting = listener.setShortcut(f2Shortcut);
+ await flush();
+ mocks.spawnedChildren[0].handlers.get('exit')?.(1, null);
+ const result = await starting;
+ expect(result).toMatchObject({ ok: false });
+ expect('superseded' in result ? result.superseded : false).toBeFalsy();
+ listener.stop();
+ });
+
+ it('retries a failed helper restart after a system release', async () => {
+ vi.useFakeTimers();
+ const { WindowsFunctionKeyShortcutListener } =
+ await import('../WindowsFunctionKeyShortcutListener.js');
+ const listener = new WindowsFunctionKeyShortcutListener({ onTrigger: vi.fn() });
+ const starting = listener.setShortcut(f2Shortcut);
+ await vi.advanceTimersByTimeAsync(0);
+ mocks.spawnedChildren[0].stdoutData('{"type":"ready"}\n');
+ await expect(starting).resolves.toMatchObject({ ok: true });
+
+ listener.releaseActiveTrigger();
+ await vi.advanceTimersByTimeAsync(0);
+ expect(mocks.spawn).toHaveBeenCalledTimes(2);
+ mocks.spawnedChildren[1].handlers.get('exit')?.(1, null);
+ await vi.advanceTimersByTimeAsync(1_000);
+ expect(mocks.spawn).toHaveBeenCalledTimes(3);
+ listener.stop();
+ });
+
it('stops restarting after consecutive post-ready crashes before the listener is stable', async () => {
vi.useFakeTimers();
const { WindowsFunctionKeyShortcutListener } =