Skip to content

armgit / Orkas

Public Imported from GitHub
0

Orkas is an open-source (MIT), local-first AI team for your desktop: a Commander turns your goal into to-dos and coordinates 16 built-in specialist agents plus Claude Code, Codex, OpenCode, OpenClaw and Hermes, with projects, scheduled automations and connectors. Free app for macOS & Windows; built-in models or your own keys.

fix(voice): match Orkas microphone button states

BlueSkyID666f88a23c6f09e
diff --git a/src/renderer/modules/voice-input.js b/src/renderer/modules/voice-input.js
index 35c51f2c..947c4743 100644
--- a/src/renderer/modules/voice-input.js
+++ b/src/renderer/modules/voice-input.js
@@ -409,25 +409,14 @@
button.dataset.voiceBound = '1';
let attempt = null;
let phase = 'idle';
- const phaseText = document.createElement ? document.createElement('span') : null;
- if (phaseText) {
- phaseText.className = 'chat-mic-status'; phaseText.setAttribute('role', 'status');
- phaseText.setAttribute('aria-live', 'polite'); phaseText.hidden = true;
- button.parentNode?.insertBefore(phaseText, button);
- }
function paint(next) {
phase = next;
button.dataset.voicePhase = phase;
- button.classList.toggle('is-recording', phase === 'recording');
- button.classList.toggle('is-busy', phase === 'connecting' || phase === 'finalizing');
+ button.classList.toggle('is-recording', phase === 'recording' || phase === 'connecting');
+ button.classList.toggle('is-busy', phase === 'finalizing');
button.title = tr(phase === 'idle' ? 'title' : phase === 'finalizing' ? 'finalizing' : 'stop_title');
button.setAttribute('aria-label', button.title);
button.setAttribute('aria-pressed', String(phase === 'recording'));
- if (phaseText) {
- phaseText.hidden = phase === 'idle';
- phaseText.textContent = phase === 'recording' ? tr('recording') + ' ' + new Date(Date.now() - attempt.started).toISOString().slice(14, 19)
- : tr(phase === 'finalizing' ? 'finalizing' : 'connecting');
- }
}
function reset(current) {
clearTimeout(current.limit); clearInterval(current.timer);
@@ -462,7 +451,7 @@
async function start() {
if (active) active();
- const current = { client: null, insertion: composerInsertion(editor), started: 0, limit: null, timer: null, terminal: false, text: '', stopped: false };
+ const current = { client: null, insertion: composerInsertion(editor), limit: null, timer: null, terminal: false, text: '', stopped: false };
attempt = current; active = cancel; paint('connecting');
const before = composerText(editor).slice(0, composerSelection(editor).start);
try {
@@ -488,11 +477,10 @@
}, {
onOpen() {
if (attempt !== current) { client.close(); return; }
- current.started = Date.now(); paint('recording');
+ paint('recording');
current.timer = setInterval(() => {
if (attempt !== current) return;
if (editor.getClientRects().length === 0) { cancel(); return; }
- paint(phase);
}, 1000);
current.limit = setTimeout(() => {
if (attempt !== current) return;
diff --git a/src/renderer/style.css b/src/renderer/style.css
index a42e754b..261f5823 100644
--- a/src/renderer/style.css
+++ b/src/renderer/style.css
@@ -6775,11 +6775,23 @@ body.is-task-side-panel-resizing * { cursor: col-resize !important; }
}
.chat-mic-btn { margin-left: auto; }
.chat-mic-icon { display: block; width: 15px; height: 15px; }
-.chat-mic-btn.is-recording { color: var(--danger); background: var(--surface-2); }
-.chat-mic-btn.is-busy { color: var(--muted); }
-.chat-mic-status { font-size: 11px; color: var(--muted); }
-.chat-mic-status:not([hidden]) { margin-left: auto; }
-.chat-mic-status:not([hidden]) + .chat-mic-btn { margin-left: 0; }
+.chat-mic-btn.is-recording {
+ color: #dc2626;
+ background: #fee2e2;
+ animation: chat-mic-pulse 1.3s ease-in-out infinite;
+}
+.chat-mic-btn.is-recording:hover {
+ color: #dc2626;
+ background: #fecaca;
+}
+.chat-mic-btn.is-busy {
+ color: #94a3b8;
+ cursor: default;
+}
+@keyframes chat-mic-pulse {
+ 0%, 100% { box-shadow: 0 0 0 0 rgba(220, 38, 38, 0.28); }
+ 60% { box-shadow: 0 0 0 5px rgba(220, 38, 38, 0); }
+}
.chat-bottom-bar .chat-mic-btn ~ .chat-send-btn { margin-left: 0; }
.composer-model-chip {
diff --git a/test/e2e/voice_input_e2e_lifecycle.spec.ts b/test/e2e/voice_input_e2e_lifecycle.spec.ts
index 53fdf8d5..06a13491 100644
--- a/test/e2e/voice_input_e2e_lifecycle.spec.ts
+++ b/test/e2e/voice_input_e2e_lifecycle.spec.ts
@@ -64,12 +64,14 @@ test.describe('API-key voice input', () => {
const server = createServer();
const cleanup = ownFixtureServer(server);
cleanups.push(cleanup);
+ let sendReady: (() => void) | undefined;
+ let sendResult: (() => void) | undefined;
server.on('upgrade', (request, socket) => {
const key = String(request.headers['sec-websocket-key']);
const accept = createHash('sha1').update(key + '258EAFA5-E914-47DA-95CA-C5AB0DC85B11').digest('base64');
socket.write('HTTP/1.1 101 Switching Protocols\r\nUpgrade: websocket\r\nConnection: Upgrade\r\nSec-WebSocket-Accept: ' + accept + '\r\n\r\n');
const ready = Buffer.from('{"event":"ready"}');
- socket.write(Buffer.concat([Buffer.from([0x81, ready.length]), ready]));
+ sendReady = () => socket.write(Buffer.concat([Buffer.from([0x81, ready.length]), ready]));
let buffer = Buffer.alloc(0);
socket.on('data', chunk => {
buffer = Buffer.concat([buffer, chunk]);
@@ -84,7 +86,7 @@ test.describe('API-key voice input', () => {
if (opcode === 8) { socket.end(Buffer.from([0x88, 0])); return; }
if (opcode !== 1 || payload.toString() !== '__END__') continue;
const result = Buffer.from(JSON.stringify({ is_last_package: true, payload_msg: { result: { text: 'E2E dictated note' } } }));
- socket.write(Buffer.concat([Buffer.from([0x81, result.length]), result]));
+ sendResult = () => socket.write(Buffer.concat([Buffer.from([0x81, result.length]), result]));
}
});
});
@@ -104,13 +106,33 @@ test.describe('API-key voice input', () => {
});
await page.locator('#new-chat-mic-btn').click();
await page.locator('.ui-dialog-overlay.open [data-act="ok"]').click();
- await expect(page.locator('#new-chat-mic-btn')).toHaveAttribute('data-voice-phase', 'recording');
+ const mic = page.locator('#new-chat-mic-btn');
+ const expectActiveIcon = async () => {
+ await expect(mic).toHaveCSS('color', 'rgb(220, 38, 38)');
+ await expect(mic).toHaveCSS('animation-name', 'chat-mic-pulse');
+ await expect(page.locator('.chat-mic-status:visible')).toHaveCount(0);
+ };
+ await expect(mic).toHaveAttribute('data-voice-phase', 'connecting');
+ await expectActiveIcon();
+ await page.screenshot({ path: testInfo.outputPath('voice-connecting-en.png') });
+ await expect.poll(() => !!sendReady).toBe(true);
+ sendReady!();
+ await expect(mic).toHaveAttribute('data-voice-phase', 'recording');
+ await expectActiveIcon();
await page.screenshot({ path: testInfo.outputPath('voice-recording-en.png') });
await page.setViewportSize({ width: 760, height: 600 });
await page.evaluate(async () => { await (window as any).setLang('zh'); });
- await expect(page.locator('.chat-mic-status:visible')).toContainText('正在录音');
+ await expectActiveIcon();
+ await expect(mic).toHaveAttribute('aria-label', '停止录音');
await page.screenshot({ path: testInfo.outputPath('voice-recording-zh-narrow.png') });
await page.locator('#new-chat-mic-btn').click();
+ await expect(mic).toHaveAttribute('data-voice-phase', 'finalizing');
+ await expect(mic).toHaveCSS('color', 'rgb(148, 163, 184)');
+ await expect(mic).toHaveCSS('animation-name', 'none');
+ await expect(page.locator('.chat-mic-status:visible')).toHaveCount(0);
+ await page.screenshot({ path: testInfo.outputPath('voice-finalizing-zh-narrow.png') });
+ await expect.poll(() => !!sendResult).toBe(true);
+ sendResult!();
await expectComposerText(page.locator('#new-chat-input'), 'Draft: E2E dictated note');
await expect(page.locator('#new-chat-mic-btn')).toHaveAttribute('data-voice-phase', 'idle');
expect(await page.evaluate(() => (window as any).__voiceStops)).toBe(1);
diff --git a/test/renderer/voice-input.test.ts b/test/renderer/voice-input.test.ts
index 06ddf012..d6281465 100644
--- a/test/renderer/voice-input.test.ts
+++ b/test/renderer/voice-input.test.ts
@@ -5,8 +5,11 @@ import vm from 'node:vm';
function element() {
const events: Record<string, Function> = {};
+ const classes = new Set<string>();
return { id: 'new-chat-mic-btn', value: 'Draft:', dataset: {} as any, title: '', hidden: false,
- classList: { toggle: vi.fn() }, setAttribute: vi.fn(), getClientRects: () => [1],
+ classList: { toggle: (name: string, enabled: boolean) => enabled ? classes.add(name) : classes.delete(name),
+ contains: (name: string) => classes.has(name) },
+ parentNode: { insertBefore: vi.fn() }, setAttribute: vi.fn(), getClientRects: () => [1],
addEventListener: (name: string, fn: Function) => { events[name] = fn; },
dispatch: (name: string) => events[name]?.(), focus: vi.fn() };
}
@@ -38,7 +41,7 @@ function load(overrides: Record<string, any> = {}) {
}
const context: any = {
window: { orkas: { invoke }, AudioContext, addEventListener: vi.fn(), localStorage: { getItem: () => null, setItem: vi.fn() } },
- document: { addEventListener: vi.fn(), getElementById: () => input, hidden: false },
+ document: { addEventListener: vi.fn(), getElementById: () => input, createElement: () => element(), hidden: false },
navigator: { mediaDevices: { getUserMedia } }, WebSocket: Socket,
composerText: () => input.value, composerSelection: () => ({ start: input.value.length }),
composerInsertion: () => ({ valid: () => true, replace: (text: string) => { input.value = 'Draft:' + text; return true; }, dispose() {} }),
@@ -58,6 +61,27 @@ const flush = async () => { for (let i = 0; i < 15; i++) await Promise.resolve()
afterEach(() => vi.useRealTimers());
describe('voice input user journey', () => {
+ it('uses the Orkas icon-only active and finishing states throughout dictation', async () => {
+ vi.useFakeTimers();
+ const h = load();
+ const expectState = (phase: string, recording: boolean, busy: boolean) => {
+ expect(h.button.dataset.voicePhase).toBe(phase);
+ expect(h.button.classList.contains('is-recording')).toBe(recording);
+ expect(h.button.classList.contains('is-busy')).toBe(busy);
+ expect(h.button.parentNode.insertBefore).not.toHaveBeenCalled();
+ };
+ expectState('idle', false, false);
+ await h.button.dispatch('click'); await flush();
+ expectState('connecting', true, false);
+ expect(h.button.title).toBe('chat.mic_stop_title');
+ h.socket().open(); await flush();
+ expectState('recording', true, false);
+ await h.button.dispatch('click'); await flush();
+ expectState('finalizing', false, true);
+ h.socket().result('spoken note', true);
+ expectState('idle', false, false);
+ expect(h.button.title).toBe('chat.mic_title');
+ });
it('guides a missing key before requesting the microphone', async () => {
const h = load();
h.invoke.mockResolvedValue({ ok: true, configured: false } as any);
@@ -183,6 +207,8 @@ describe('voice input user journey', () => {
expect(h.track.stop).toHaveBeenCalledTimes(1);
expect(h.socket()).toBeUndefined();
expect(h.button.dataset.voicePhase).toBe('idle');
+ expect(h.button.classList.contains('is-recording')).toBe(false);
+ expect(h.button.classList.contains('is-busy')).toBe(false);
});
it('does not resurrect capture when stopped during worklet initialization', async () => {
vi.useFakeTimers();