Skip to content

Open source Grok Bot alternative, Bring your own agent and subscription: message Claude Code, Codex, Gemini CLI, Cursor, Copilot and 40+ AI agents as bots on your own computer, from iPhone, Mac, Windows, Linux or terminal. Agent-agnostic and free. Also a Muse and Dots alternative. Built in Rust.

fix(desktop): show provider dictation listening once the mic is open

leepokai853edd80c59b
diff --git a/apps/desktop/src/renderer/views/island/island-model.ts b/apps/desktop/src/renderer/views/island/island-model.ts
index ba1aa059..d23c055c 100644
--- a/apps/desktop/src/renderer/views/island/island-model.ts
+++ b/apps/desktop/src/renderer/views/island/island-model.ts
@@ -1,5 +1,5 @@
import {
- FINISHED_MS, focusOf, isActive, islandFrame, islandMode, islandRect, othersOf, transitions,
+ FINISHED_MS, focusOf, isActive, islandFrame, islandMode, islandRect, othersOf, stopsDictation, transitions,
type IslandBot, type IslandNotice, type IslandPermission, type IslandScreen, type IslandSummary, type IslandTab,
} from '@shared/island'
import { VOICE_SHORTCUT_KEYS, type VoiceKey, type VoiceShortcut } from '@shared/voice-shortcut'
@@ -127,8 +127,7 @@ export class IslandModel extends Observable {
/** The header's tabs. Bots puts the approvals on screen off until another arrives. */
setTab(tab: IslandTab) {
- // Leaving the message field hides the recording pill: stop there, keeping the words.
- if (this.tab === 'message' && tab !== 'message' && this.dictation.busy) this.dictation.finish()
+ if (stopsDictation(this.tab, tab, this.dictation.busy)) this.dictation.finish()
this.update(() => {
if (tab === 'bots') for (const p of this.summary.permissions) this.deferred.add(p.entryId)
if (tab === 'message' && !this.messageRef) this.messageRef = this.focus?.ref ?? null
diff --git a/apps/desktop/src/renderer/views/thread/dictation.test.ts b/apps/desktop/src/renderer/views/thread/dictation.test.ts
index 7914bb32..28ede72e 100644
--- a/apps/desktop/src/renderer/views/thread/dictation.test.ts
+++ b/apps/desktop/src/renderer/views/thread/dictation.test.ts
@@ -52,6 +52,7 @@ const settle = () => new Promise((done) => setTimeout(done, 0))
test('on-device words go after the draft, and finish waits for the last of them', () => {
const s = setup()
s.dictation.start(s.box())
+ assert.equal(s.dictation.listening, true)
s.say({ type: 'partial', text: 'in the' })
assert.equal(s.box(), 'Fix the bug in the')
s.say({ type: 'final', text: 'in the parser' })
@@ -60,6 +61,7 @@ test('on-device words go after the draft, and finish waits for the last of them'
assert.equal(sent, false)
s.say({ type: 'final', text: 'today' })
s.say({ type: 'stopped' })
+ assert.equal(s.dictation.listening, false)
assert.equal(s.box(), 'Fix the bug in the parser today')
assert.equal(sent, true)
assert.equal(s.dictation.busy, false)
@@ -104,6 +106,37 @@ test('a provider without a key never opens the microphone', async () => {
assert.equal(s.dictation.busy, false)
})
+test('with a provider it shows listening only once the microphone is open', async () => {
+ let open: (stop: () => void) => void = () => {}
+ const s = setup({ provider: () => 'openai', microphone: () => new Promise((done) => (open = done)) })
+ s.dictation.start(s.box())
+ await settle()
+ assert.equal(s.dictation.listening, false)
+ assert.equal(s.dictation.startedAt, 0)
+ assert.equal(s.dictation.busy, true)
+ open(() => {})
+ await settle()
+ assert.equal(s.dictation.listening, true)
+ assert.ok(s.dictation.startedAt > 0)
+})
+
+test('stopped or cancelled while the microphone opens, it lets the microphone go and never listens', async () => {
+ for (const end of ['finish', 'cancel'] as const) {
+ let open: (stop: () => void) => void = () => {}
+ let closed = false
+ const s = setup({ provider: () => 'openai', microphone: () => new Promise((done) => (open = done)) })
+ s.dictation.start(s.box())
+ await settle()
+ s.dictation[end]()
+ open(() => (closed = true))
+ await settle()
+ assert.equal(closed, true, end)
+ assert.equal(s.dictation.listening, false, end)
+ assert.equal(s.dictation.busy, false, end)
+ assert.equal(s.pending.length, 0, end)
+ }
+})
+
test("a provider's transcript lands after what's in the box by then, in order, then done runs", async () => {
const s = setup({ provider: () => 'gemini' })
s.dictation.start(s.box())
diff --git a/apps/desktop/src/renderer/views/thread/dictation.ts b/apps/desktop/src/renderer/views/thread/dictation.ts
index 9c93ea1e..4c6da59d 100644
--- a/apps/desktop/src/renderer/views/thread/dictation.ts
+++ b/apps/desktop/src/renderer/views/thread/dictation.ts
@@ -101,16 +101,12 @@ export class Dictation extends Observable {
const provider = this.platform.host ? this.platform.provider() : null
if (provider) {
this.recording = { provider, pcm: [], stopMic: null }
- void this.record(this.recording, ++this.generation)
- } else if (speech) {
- this.off = speech.onEvent((e) => this.event(e))
- speech.start(this.platform.language())
- } else {
- return this.fail(`${this.platform.noSpeech} Pick OpenAI or Gemini beside the mic.`)
+ return void this.record(this.recording, ++this.generation)
}
- this.startedAt = Date.now()
- this.listening = true
- this.changed()
+ if (!speech) return this.fail(`${this.platform.noSpeech} Pick OpenAI or Gemini beside the mic.`)
+ this.off = speech.onEvent((e) => this.event(e))
+ speech.start(this.platform.language())
+ this.listen()
}
/** Stops listening; `done` runs once the last words are in the box (recognized, or transcribed for a provider). */
@@ -160,7 +156,10 @@ export class Dictation extends Observable {
if (e.type === 'stopped' || e.type === 'error') this.end()?.()
}
- /** Opens the microphone once the host has the provider's key, so nothing said is lost to a missing one. */
+ /**
+ * Opens the microphone once the host has the provider's key, so nothing said is lost to a missing
+ * one, and only then listens (the pill shows), so nothing said before the microphone is open is lost.
+ */
private async record(recording: Recording, generation: number) {
try {
await this.platform.checkKey(recording.provider)
@@ -171,6 +170,7 @@ export class Dictation extends Observable {
})
if (generation !== this.generation) return stop()
recording.stopMic = stop
+ this.listen()
} catch (e) {
if (generation === this.generation) this.fail(messageOf(e))
}
@@ -207,6 +207,13 @@ export class Dictation extends Observable {
}
}
+ /** Shows it listening, timed from now. */
+ private listen() {
+ this.startedAt = Date.now()
+ this.listening = true
+ this.changed()
+ }
+
/** Ends with `message` and nothing to send. */
private fail(message: string) {
this.byShortcut = false
diff --git a/apps/desktop/src/shared/island.test.ts b/apps/desktop/src/shared/island.test.ts
index 6b9b4ac0..115afa82 100644
--- a/apps/desktop/src/shared/island.test.ts
+++ b/apps/desktop/src/shared/island.test.ts
@@ -2,7 +2,7 @@ import assert from 'node:assert/strict'
import { test } from 'node:test'
import type { BotStatus } from './models.ts'
import {
- focusOf, hitRect, hits, islandFrame, islandMode, islandRect, notchOf, othersOf, transitions,
+ focusOf, hitRect, hits, islandFrame, islandMode, islandRect, notchOf, othersOf, stopsDictation, transitions,
type IslandBot, type IslandNotice, type IslandPermission, type IslandSummary, type IslandTab,
} from './island.ts'
@@ -84,3 +84,11 @@ test('shapes follow the notch, and a plain top edge keeps a thin strip that wake
assert.deepEqual(hitRect(edge), { x: 272, y: 0, width: 176, height: 8 })
assert.deepEqual(hitRect({ x: 0, y: 0, width: 0, height: 0 }), { x: 0, y: 0, width: 0, height: 0 })
})
+
+test('leaving the message tab while dictating stops it there; other tab changes leave it be', () => {
+ assert.equal(stopsDictation('message', 'usage', true), true)
+ assert.equal(stopsDictation('message', 'auto', true), true)
+ assert.equal(stopsDictation('message', 'message', true), false)
+ assert.equal(stopsDictation('message', 'bots', false), false)
+ assert.equal(stopsDictation('usage', 'bots', true), false)
+})
diff --git a/apps/desktop/src/shared/island.ts b/apps/desktop/src/shared/island.ts
index 95c5ce68..a2c82f0e 100644
--- a/apps/desktop/src/shared/island.ts
+++ b/apps/desktop/src/shared/island.ts
@@ -109,6 +109,8 @@ const BAR = 26
export const isActive = (b: Pick<IslandBot, 'status'>) => b.status === 'working' || b.status === 'needsInput'
export const isOpenMode = (mode: IslandMode) => mode !== 'hidden' && mode !== 'peek' && mode !== 'compact'
+/** Leaving the message tab hides its recording pill, so dictation still going there stops (keeping the words). */
+export const stopsDictation = (from: IslandTab, to: IslandTab, dictating: boolean) => dictating && from === 'message' && to !== 'message'
export function islandMode(
summary: IslandSummary,
diff --git a/docs/features/voice-call.md b/docs/features/voice-call.md
index 11ed24ef..e43f8fed 100644
--- a/docs/features/voice-call.md
+++ b/docs/features/voice-call.md
@@ -54,7 +54,8 @@ was recognized so far. The desktop island's message field has the same mic and p
A `chevron.up` beside the composer's mic picks dictation's engine, kept on the device apart from the
call engine (`dictationEngine`): **On device** (the above), or **OpenAI** / **Gemini** on the user's
own key. With a provider, the mic first checks that the computer holds its key (`voiceStatus`; no key
-means an error before anything is recorded), then records; nothing is typed while recording. The
+means an error before anything is recorded), then records; the pill (and its time) appears only once
+the microphone is open, so nothing said before it is lost; nothing is typed while recording. The
pill's stop turns the pill into "Transcribing…" and the whole recording goes through
`voiceTranscribe` with the call settings' speech-to-text model; the text lands after what's in the
box when it arrives (typing goes on while it records). The recording goes in 20 s pieces (one