The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop/radio): resume the preserved stream when dictation lands in the composer
Brooklyn Nicholson544df42d789f
diff --git a/apps/desktop/src/contrib/radio-plugin.test.ts b/apps/desktop/src/contrib/radio-plugin.test.tsindex b3d95a94a9e..d6c30125aac 100644--- a/apps/desktop/src/contrib/radio-plugin.test.ts+++ b/apps/desktop/src/contrib/radio-plugin.test.ts@@ -10,6 +10,8 @@ vi.mock('./runtime-loader', () => ({ watchRuntimePlugins: vi.fn() }))interface RadioPlayer {play: () => Promise<void>status: { get: () => string }+ stop: () => void+ toggle: () => void | Promise<void>}function player(): RadioPlayer {@@ -113,4 +115,74 @@ describe('bundled Radio plugin', () => {media.dispatchEvent(new Event('playing'))expect(radio.status.get()).toBe('live')})++ it('resumes the preserved stream when dictation text lands in an editable field (#108113)', async () => {+ $pluginDecisions.set({ accent: false, kanban: false, 'hermes-bots': false })+ discoverBundledPlugins()+ const playMock = vi.spyOn(HTMLMediaElement.prototype, 'play').mockResolvedValue()+ vi.spyOn(HTMLMediaElement.prototype, 'pause').mockImplementation(() => {})+ vi.spyOn(HTMLMediaElement.prototype, 'load').mockImplementation(() => {})+ vi.stubGlobal('AudioContext', undefined)+ await setPluginEnabled('radio', true)+ const radio = player()+ await radio.play()+ const media = document.querySelector('audio')!+ media.dispatchEvent(new Event('playing'))+ expect(radio.status.get()).toBe('live')+ playMock.mockClear()++ // Fluid Voice pauses the stream, then inserts the transcript as a paste+ // into the focused field — no media resume event ever follows.+ Object.defineProperty(media, 'paused', { value: true, configurable: true })+ Object.defineProperty(media, 'ended', { value: false, configurable: true })+ media.dispatchEvent(new Event('pause'))+ expect(radio.status.get()).toBe('paused')++ const composer = document.createElement('textarea')+ document.body.append(composer)+ composer.dispatchEvent(new Event('paste', { bubbles: true }))++ await vi.waitFor(() => expect(radio.status.get()).toBe('live'))+ // Same element, same stream — no teardown and reconnect.+ expect(document.querySelector('audio')).toBe(media)+ expect(playMock).toHaveBeenCalled()+ composer.remove()+ })++ it('keeps the plugin Pause destructive: no paste resume, and Play reconnects (#108113)', async () => {+ $pluginDecisions.set({ accent: false, kanban: false, 'hermes-bots': false })+ discoverBundledPlugins()+ const playMock = vi.spyOn(HTMLMediaElement.prototype, 'play').mockResolvedValue()+ vi.spyOn(HTMLMediaElement.prototype, 'pause').mockImplementation(() => {})+ vi.spyOn(HTMLMediaElement.prototype, 'load').mockImplementation(() => {})+ vi.stubGlobal('AudioContext', undefined)+ await setPluginEnabled('radio', true)+ const radio = player()+ await radio.play()+ const first = document.querySelector('audio')!+ first.dispatchEvent(new Event('playing'))+ expect(radio.status.get()).toBe('live')++ // The plugin's own Pause releases the stream by design.+ radio.toggle()+ expect(radio.status.get()).toBe('paused')+ expect(document.querySelector('audio')).toBeNull()+ expect(first.hasAttribute('src')).toBe(false)++ // A dictation paste must NOT resurrect a stream the user paused.+ const composer = document.createElement('textarea')+ document.body.append(composer)+ composer.dispatchEvent(new Event('paste', { bubbles: true }))+ expect(radio.status.get()).toBe('paused')+ expect(document.querySelector('audio')).toBeNull()+ composer.remove()++ // Play after an intentional pause is a full reconnect: a fresh element.+ playMock.mockClear()+ await radio.toggle()+ const second = document.querySelector('audio')!+ expect(second).not.toBe(first)+ second.dispatchEvent(new Event('playing'))+ expect(radio.status.get()).toBe('live')+ })})diff --git a/apps/desktop/src/plugins/radio/plugin.js b/apps/desktop/src/plugins/radio/plugin.jsindex 1c5615a8a6d..1ec2f1a92db 100644--- a/apps/desktop/src/plugins/radio/plugin.js+++ b/apps/desktop/src/plugins/radio/plugin.js@@ -172,6 +172,7 @@ function createPlayer(ctx) {let output = nullconst waveformData = new Float32Array(2048)let generation = 0+ let playGeneration = -1let timeout = nulllet disposed = falselet lastVolume = volume.get() || 25@@ -227,10 +228,15 @@ function createPlayer(ctx) {} else stop('error')}element.addEventListener('playing', () => {- if (current()) { clearTimeout(timeout); status.set('live') }+ if (current()) { clearTimeout(timeout); playGeneration = token; status.set('live') }})// Browser/media controls can pause the element outside our buttons.// Reflect that state instead of showing a frozen trace as live playback.+ // Non-destructive: an external controller (macOS media keys, a dictation+ // tool pausing audio to listen) may resume the same element afterwards,+ // so the stream must survive. The plugin's own Pause control stays+ // destructive — toggle() advances the generation first, so the pause+ // event it triggers fails the current() guard and still runs stop().element.addEventListener('pause', () => {if (current() && element.paused && !element.ended) status.set('paused')})@@ -261,7 +267,31 @@ function createPlayer(ctx) {function toggle() {if (status.get() === 'live' || status.get() === 'connecting') stop()- else void play()+ else if (!resume()) void play()+ }++ // Dictation tools (Fluid Voice) pause the stream to hear the microphone,+ // then deliver the transcript as a paste-like insertion into the focused+ // field. No media-session resume event ever follows, so the only+ // renderer-visible "dictation is done" signal is the text itself arriving+ // in the composer. On that signal the plugin resumes the preserved stream.+ // Never resumed on window focus — that would override an intentional pause.+ // Returns false when the stream is not intact (fresh start, the plugin's+ // own destructive Pause, a stop from another window), so callers can fall+ // back to a full reconnect.+ function resume() {+ if (disposed || !audio || generation !== playGeneration || status.get() !== 'paused') return false+ const token = generation+ status.set('connecting')+ void audio+ .play()+ .then(() => {+ if (!disposed && token === generation) { clearTimeout(timeout); status.set('live') }+ })+ .catch(() => {+ if (!disposed && token === generation) stop('error')+ })+ return true}function next() {@@ -293,6 +323,20 @@ function createPlayer(ctx) {bus.onmessage = event => {if (event.data?.type === 'play' && event.data.sender !== windowId) stop('elsewhere')}++ // Dictation completion: Fluid Voice delivers the transcript as a paste into+ // the focused editable field (its Electron delivery path is a guarded ⌘V,+ // a real DOM paste event). resume() no-ops unless the stream was paused+ // externally and is still intact, so ordinary pastes while stopped, errored+ // or intentionally paused (the plugin's own Pause is destructive) do nothing.+ const onTextInserted = event => {+ const target = event.target+ const editable = target instanceof HTMLTextAreaElement+ || target instanceof HTMLInputElement+ || (target instanceof HTMLElement && target.isContentEditable)+ if (editable) void resume()+ }+ document.addEventListener('paste', onTextInserted)function waveform(columns) {if (!analyser || status.get() !== 'live') return Array(columns).fill(0)analyser.getFloatTimeDomainData(waveformData)@@ -314,6 +358,7 @@ function createPlayer(ctx) {ctx.onDispose(() => {disposed = true+ document.removeEventListener('paste', onTextInserted)stop()bus.close()if (audioContext) void audioContext.close()