The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): keep native audio/video overflow menus open (#135228)
akimonlet1b0f071dbbfb
diff --git a/apps/desktop/electron/main.ts b/apps/desktop/electron/main.tsindex 3206f7e63c2..88228215b9b 100644--- a/apps/desktop/electron/main.ts+++ b/apps/desktop/electron/main.ts@@ -377,7 +377,7 @@ import {} from './managed-ssh-update'import { registerMcpOauthCallbackIpc } from './mcp-oauth-callback-ipc'import { isMediaCapturePermission } from './media-capture-permission'-import { createMediaProtocolHandler, MEDIA_PROTOCOL } from './media-protocol'+import { createMediaProtocolHandler, MEDIA_PROTOCOL, mediaProtocolDownloadName } from './media-protocol'import { fetchLocalMedia } from './media-range'import { createMinimizeToTray } from './minimize-to-tray'import {@@ -6792,14 +6792,14 @@ function installContextMenuBridge(window: BrowserWindow) {})}-// Chromium-initiated downloads (renderer anchor/blob downloads, drag-outs)-// land here. Without a handler the OS save dialog opens with the process cwd-// as the default directory (win-unpacked in packaged installs) and whatever-// extensionless name the anchor carried. Route every download to the user's-// Downloads directory and guarantee a MIME-derived extension.+// Chromium-initiated downloads (renderer anchor/blob downloads, drag-outs, a+// media player's ⋮ Download) land here. Without a handler the OS save dialog+// opens in the process cwd (win-unpacked in packaged installs) with whatever name+// the URL carried. Route every download to Downloads, name hermes-media:// saves+// after the file, and guarantee a MIME-derived extension.function installDownloadHandling() {session.defaultSession.on('will-download', (_event, item) => {- const suggested = item.getFilename() || 'download'+ const suggested = mediaProtocolDownloadName(item.getURL()) || item.getFilename() || 'download'const hasExtension = Boolean(path.extname(suggested))const extension = hasExtension ? '' : extensionForMimeType(item.getMimeType())const filename = `${suggested}${extension}`diff --git a/apps/desktop/electron/media-protocol.test.ts b/apps/desktop/electron/media-protocol.test.tsindex b54d65b1c8a..e10771b1e75 100644--- a/apps/desktop/electron/media-protocol.test.ts+++ b/apps/desktop/electron/media-protocol.test.ts@@ -8,6 +8,7 @@ import {createMediaProtocolHandler,isStreamableMediaPath,type MediaProtocolDependencies,+ mediaProtocolDownloadName,mediaRequestHeaders,remoteMediaEndpoint} from './media-protocol'@@ -61,6 +62,16 @@ describe('media protocol helpers', () => {expect(endpoint.pathname).toBe('/hermes/api/files/stream')expect(endpoint.searchParams.get('path')).toBe('/tmp/a b.mp4')})++ it('names a native media save after the file, not the flattened path', () => {+ const local = `hermes-media://stream/${encodeURIComponent('C:\\Users\\me\\Videos\\clip (cut).mp4')}`+ const remote = `hermes-media://remote/${encodeURIComponent('/home/me/out/render.webm')}?profile=work`++ expect(mediaProtocolDownloadName(local)).toBe('clip (cut).mp4')+ expect(mediaProtocolDownloadName(remote)).toBe('render.webm')+ expect(mediaProtocolDownloadName('https://example.test/a/clip.mp4')).toBeNull()+ expect(mediaProtocolDownloadName('blob:https://x/123')).toBeNull()+ })})describe('createMediaProtocolHandler', () => {diff --git a/apps/desktop/electron/media-protocol.ts b/apps/desktop/electron/media-protocol.tsindex 5a8eb76066c..7c8e1c7830a 100644--- a/apps/desktop/electron/media-protocol.ts+++ b/apps/desktop/electron/media-protocol.ts@@ -73,6 +73,29 @@ function parseMediaProtocolTarget(rawUrl: string): MediaProtocolTarget {return { connectionId, filePath, mode, profile }}+/**+ * The file name a native save of a `hermes-media://` URL should offer. The+ * media path rides percent-encoded in the URL, so Chromium's own guess flattens+ * the whole path into the name (`C__Users_me_Videos_clip.mp4`). Returns null+ * for any other URL so ordinary downloads keep Chromium's name.+ */+export function mediaProtocolDownloadName(rawUrl: string): null | string {+ let target: MediaProtocolTarget++ try {+ if (new URL(rawUrl).protocol !== `${MEDIA_PROTOCOL}:`) {+ return null+ }++ target = parseMediaProtocolTarget(rawUrl)+ } catch {+ return null+ }++ // Media paths come from the agent's OS: split on both separators.+ return target.filePath.split(/[\\/]/).filter(Boolean).pop() || null+}+export function isStreamableMediaPath(filePath: string): boolean {const lower = filePath.toLowerCase()diff --git a/apps/desktop/src/app/chat/composer/floating-target-media-controls.test.ts b/apps/desktop/src/app/chat/composer/floating-target-media-controls.test.tsnew file mode 100644index 00000000000..73de9b72aba--- /dev/null+++ b/apps/desktop/src/app/chat/composer/floating-target-media-controls.test.ts@@ -0,0 +1,73 @@+// @vitest-environment jsdom+import { afterEach, describe, expect, it } from 'vitest'++import { registerFloatingComposer } from './floating-target'++/** One pane: its composer host plus the chat surface the transcript lives in.+ * Inline media players delivered by the agent render inside that surface. */+function mountPane(id: string) {+ const host = document.createElement('div')+ host.dataset.composerOwner = id+ const editor = document.createElement('div')+ editor.dataset.slot = 'composer-rich-input'+ editor.tabIndex = -1+ host.appendChild(editor)+ document.body.appendChild(host)++ const surface = document.createElement('div')+ surface.dataset.chatSurface = ''+ surface.dataset.composerSurfaceId = id+ document.body.appendChild(surface)++ return { editor, surface }+}++/** A native media element with controls. When its overflow menu opens,+ * Chromium focuses content in the user-agent shadow root and the focus event+ * outside that root targets the AUDIO/VIDEO host, which is what we simulate. */+function mountPlayer(surface: Element, tag: 'audio' | 'video', controls = true) {+ const player = document.createElement(tag)+ player.controls = controls+ player.tabIndex = 0+ surface.appendChild(player)++ return player+}++function movePointerOver(target: Element, x: number) {+ target.dispatchEvent(new PointerEvent('pointermove', { bubbles: true, buttons: 0, clientX: x, clientY: 44 }))+}++/** Opening the ⋮ menu (Download, Playback speed) of an inline player moved+ * focus to the AUDIO/VIDEO host; the focus-follow handed it to the composer+ * and Chromium closed the menu the instant it opened (#135225). */+describe('floating composer focus-follow vs native media controls', () => {+ const unregister: Array<() => void> = []++ afterEach(() => {+ unregister.splice(0).forEach(fn => fn())+ document.body.innerHTML = ''+ })++ it.each(['audio', 'video'] as const)('keeps focus on a <%s controls> menu on focusin and on pointermove', tag => {+ const { editor, surface } = mountPane('surface-1')+ const player = mountPlayer(surface, tag)+ unregister.push(registerFloatingComposer('surface-1', { groupId: 'g1', target: 'main' }))++ player.focus()+ expect(document.activeElement).toBe(player)++ movePointerOver(player, 43)+ expect(document.activeElement).toBe(player)+ expect(document.activeElement).not.toBe(editor)+ })++ it('still redirects focus that lands on a media element without native controls', () => {+ const { editor, surface } = mountPane('surface-1')+ const player = mountPlayer(surface, 'video', false)+ unregister.push(registerFloatingComposer('surface-1', { groupId: 'g1', target: 'main' }))++ player.focus()+ expect(document.activeElement).toBe(editor)+ })+})diff --git a/apps/desktop/src/app/chat/composer/floating-target.ts b/apps/desktop/src/app/chat/composer/floating-target.tsindex 21531b72970..d1b55808f8b 100644--- a/apps/desktop/src/app/chat/composer/floating-target.ts+++ b/apps/desktop/src/app/chat/composer/floating-target.ts@@ -23,6 +23,13 @@ let reconcileQueued = false* the edit ~80ms after it opened (#112935). */const inInlineEdit = (el: Element | null) => Boolean(el?.closest(EDIT_COMPOSER_ROOT))+/** The native overflow menu (⋮ → Download, Playback speed) of an inline+ * <audio controls>/<video controls> lives in the element's user-agent shadow+ * root, so its focus is retargeted to the AUDIO/VIDEO host. Redirecting that+ * focus to the pane composer — on focusin or on the next pointermove — made+ * Chromium close the menu the instant it opened (#135225). */+const inNativeMediaControls = (el: Element | null) => Boolean(el?.closest('audio[controls], video[controls]'))+/** A caret the user placed in a live text-entry surface outside every composer* — the clarify answer box, the transcript find bar, a dialog field — is their* own focus, exactly like the inline edit: moving the pointer must not hand the@@ -30,7 +37,9 @@ const inInlineEdit = (el: Element | null) => Boolean(el?.closest(EDIT_COMPOSER_R* element's focusin visible to React. Composer editors are excluded, so* hover-switching between panes keeps behaving as before (#114245). */const keepsOwnFocus = (el: Element | null) =>- inInlineEdit(el) || (isEditableTarget(el) && !el?.closest('[data-slot="composer-rich-input"]'))+ inNativeMediaControls(el) ||+ inInlineEdit(el) ||+ (isEditableTarget(el) && !el?.closest('[data-slot="composer-rich-input"]'))/** Focus inside an open floating layer — a popover, menu, listbox or dialog* portaled over the transcript — is the user's own as well. Radix moves focus