Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix(desktop): dispose host shortcut routing on teardown
Josué42a573bf9885
diff --git a/desktop-app/src/__tests__/mainShortcutLifecycle.test.ts b/desktop-app/src/__tests__/mainShortcutLifecycle.test.tsnew file mode 100644index 000000000..78191b1d3--- /dev/null+++ b/desktop-app/src/__tests__/mainShortcutLifecycle.test.ts@@ -0,0 +1,11 @@+import { describe, expect, it } from 'vitest'+import { readFile } from 'node:fs/promises'+import path from 'node:path'++describe('main window shortcut lifecycle', () => {+ it('owns host shortcut routing through BrowserWindow teardown', async () => {+ const source = await readFile(path.join(process.cwd(), 'src', 'main.ts'), 'utf8')++ expect(source).toContain('wireHostDesktopShortcutRouting(window)')+ })+})diff --git a/desktop-app/src/__tests__/shortcutRouter.test.ts b/desktop-app/src/__tests__/shortcutRouter.test.tsindex 16da1db8f..2e389aef9 100644--- a/desktop-app/src/__tests__/shortcutRouter.test.ts+++ b/desktop-app/src/__tests__/shortcutRouter.test.ts@@ -4,6 +4,7 @@ import {type DesktopShortcutRoute,isStandardEditingShortcut,routeDesktopShortcut,+ wireHostDesktopShortcutRouting,} from '../shortcutRouter.js'function input(overrides: Partial<DesktopShortcutInput> = {}): DesktopShortcutInput {@@ -82,6 +83,35 @@ describe('main-process Desktop shortcut routing', () => {})})+ it('removes a host shortcut listener when its owning window closes', () => {+ const webContents = {+ id: 1,+ isDestroyed: () => false,+ isFocused: () => true,+ focus: vi.fn(),+ on: vi.fn(),+ removeListener: vi.fn(),+ send: vi.fn(),+ }+ let closeListener: (() => void) | undefined+ const host = {+ webContents,+ once: vi.fn((_event: 'closed', listener: () => void) => {+ closeListener = listener+ }),+ }++ wireHostDesktopShortcutRouting(host)++ expect(webContents.on).toHaveBeenCalledOnce()+ expect(host.once).toHaveBeenCalledWith('closed', expect.any(Function))+ closeListener?.()+ expect(webContents.removeListener).toHaveBeenCalledWith(+ 'before-input-event',+ expect.any(Function)+ )+ })+it('does not intercept reserved, ordinary editing, IME, AltGr, or key-up input', () => {const current = route('host')const preventDefault = vi.fn()diff --git a/desktop-app/src/main.ts b/desktop-app/src/main.tsindex 60088e1a7..4475fe156 100644--- a/desktop-app/src/main.ts+++ b/desktop-app/src/main.ts@@ -17,7 +17,7 @@ import {parseSandboxUiDeepLink,} from './sandboxUiDeepLinks.js'import { shouldAcceptSandboxUiProtocolLink } from './sandboxUiProtocolWindowPolicy.js'-import { wireDesktopShortcutRouting } from './shortcutRouter.js'+import { wireHostDesktopShortcutRouting } from './shortcutRouter.js'import { installAdaptiveSystemIcon, resolveSystemIconPath } from './systemIcon.js'const EVENFIRE_APP_NAME = 'Evenfire'@@ -303,11 +303,7 @@ async function createWindow(): Promise<void> {},})mainWindow = window- wireDesktopShortcutRouting({- source: 'host',- sourceWebContents: window.webContents,- trustedRenderer: window.webContents,- })+ wireHostDesktopShortcutRouting(window)mainWindowRendererReady = falsewindow.on('closed', () => {if (mainWindow === window) {diff --git a/desktop-app/src/shortcutRouter.ts b/desktop-app/src/shortcutRouter.tsindex 02dcf9992..701debc5a 100644--- a/desktop-app/src/shortcutRouter.ts+++ b/desktop-app/src/shortcutRouter.ts@@ -21,6 +21,11 @@ export type DesktopShortcutRoute = {isCurrentSource?: () => boolean}+export type DesktopShortcutHost = {+ webContents: ShortcutWebContents+ once(event: 'closed', listener: () => void): unknown+}+/*** Editing chords belong to Chromium/the active app, even if a future command* definition accidentally reuses one. Keep this guard independent of DOM@@ -84,3 +89,12 @@ export function wireDesktopShortcutRouting(route: DesktopShortcutRoute): () => vroute.sourceWebContents.on('before-input-event', listener)return () => route.sourceWebContents.removeListener('before-input-event', listener)}++export function wireHostDesktopShortcutRouting(host: DesktopShortcutHost): void {+ const dispose = wireDesktopShortcutRouting({+ source: 'host',+ sourceWebContents: host.webContents,+ trustedRenderer: host.webContents,+ })+ host.once('closed', dispose)+}