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: 恢复无阶段触发与长按松手的停止行为

zcinta0514ca3c64328d03
diff --git a/apps/desktop/src/renderer/__tests__/askUserQuestionVoice.test.tsx b/apps/desktop/src/renderer/__tests__/askUserQuestionVoice.test.tsx
index 403fa926df..3b443d4dd7 100644
--- a/apps/desktop/src/renderer/__tests__/askUserQuestionVoice.test.tsx
+++ b/apps/desktop/src/renderer/__tests__/askUserQuestionVoice.test.tsx
@@ -164,6 +164,55 @@ describe('AskUserQuestion voice entry', () => {
}
});
+ it('starts dictation from a shortcut trigger without a phase (plain modifier combo)', async () => {
+ const previous = window.electronAPI;
+ let trigger: ((payload?: { id?: string; phase?: 'start' | 'tap' | 'end' }) => void) | undefined;
+ window.electronAPI = {
+ voiceInput: {
+ onGlobalShortcutTrigger: (callback: typeof trigger) => {
+ trigger = callback;
+ return () => { trigger = undefined; };
+ },
+ claimGlobalShortcutTrigger: () => {},
+ getDataSnapshot: () => ({ settings: { shortcut: null } }),
+ },
+ } as unknown as typeof window.electronAPI;
+ try {
+ renderAsk([{ question: '选哪个?', options: [{ label: '甲' }, { label: '乙' }] }]);
+ // Plain modifier combos arrive without a phase; they must still start.
+ trigger?.({ id: 'combo-1' });
+ await waitFor(() => expect(start).toHaveBeenCalledOnce());
+ } finally {
+ window.electronAPI = previous;
+ }
+ });
+
+ it('stops when a held shortcut press is released', async () => {
+ const previous = window.electronAPI;
+ let trigger: ((payload?: { id?: string; phase?: 'start' | 'tap' | 'end' }) => void) | undefined;
+ window.electronAPI = {
+ voiceInput: {
+ onGlobalShortcutTrigger: (callback: typeof trigger) => {
+ trigger = callback;
+ return () => { trigger = undefined; };
+ },
+ claimGlobalShortcutTrigger: () => {},
+ getDataSnapshot: () => ({ settings: { shortcut: null } }),
+ },
+ } as unknown as typeof window.electronAPI;
+ try {
+ renderAsk([{ question: '选哪个?', options: [{ label: '甲' }, { label: '乙' }] }]);
+ trigger?.({ id: 'hold-1', phase: 'start' });
+ await waitFor(() => expect(start).toHaveBeenCalledOnce());
+ await new Promise((resolve) => setTimeout(resolve, 300));
+ // Held press released: `end` must stop, unlike the `tap` of a quick press.
+ trigger?.({ id: 'hold-1', phase: 'end' });
+ await waitFor(() => expect(stop).toHaveBeenCalledOnce());
+ } finally {
+ window.electronAPI = previous;
+ }
+ });
+
it('blocks question navigation and submit while dictation owns the answer', async () => {
const { view } = renderAsk([
{ question: '第一题?', options: [{ label: '甲' }, { label: '乙' }] },
diff --git a/apps/desktop/src/renderer/components/new-chat/AskUserQuestionPrompt.tsx b/apps/desktop/src/renderer/components/new-chat/AskUserQuestionPrompt.tsx
index 01300f20b8..5725c3c1d4 100644
--- a/apps/desktop/src/renderer/components/new-chat/AskUserQuestionPrompt.tsx
+++ b/apps/desktop/src/renderer/components/new-chat/AskUserQuestionPrompt.tsx
@@ -497,18 +497,24 @@ function AskUserQuestionForm({
voiceShortcutAtRef.current = now;
const session = dictationRef.current;
if (session.state === 'submitting' || session.state === 'refining') return;
- if (phase === 'start') {
- // A press while listening means stop; its release must not act again.
- voiceShortcutStartedPressRef.current = !session.isBusy;
- beginVoiceInput();
+ // `tap` closes a quick press, `end` closes a held one; no phase means the
+ // local keyboard handler (a plain modifier combo) pressed the shortcut.
+ if (phase === 'tap') {
+ // The tap of the press that just started dictation must not stop it.
+ if (voiceShortcutStartedPressRef.current) {
+ voiceShortcutStartedPressRef.current = false;
+ return;
+ }
+ if (session.isBusy) void session.stop();
return;
}
- // `tap` / `end` are the release of a press.
- if (voiceShortcutStartedPressRef.current) {
+ if (phase === 'end') {
voiceShortcutStartedPressRef.current = false;
+ if (session.isBusy) void session.stop();
return;
}
- if (session.isBusy) void session.stop();
+ voiceShortcutStartedPressRef.current = !session.isBusy;
+ beginVoiceInput();
};
const onKeyDown = (event: KeyboardEvent) => {
if (event.repeat || event.isComposing) return;