Node-based terminal manager for AI coding agents — tmux-backed terminals and parallel agent sessions as draggable nodes on an infinite pan/zoom canvas. macOS, Linux, and a browser Server Edition.
TypeScript adhdagent-orchestrationai-agentscanvasclaude-codecodexcoding-agentsdeveloper-toolselectrongeminilinuxmacosmultiplexeropencodeparallel-agentsterminalterminal-emulatorterminal-multiplexertmuxworkspace-manager
fix(notify): retain Notification objects so click handlers survive GC
enes905f1f339a73
diff --git a/src/main/index.ts b/src/main/index.tsindex eac3f385f..cfaab9fb8 100644--- a/src/main/index.ts+++ b/src/main/index.ts@@ -14,6 +14,7 @@ import { initUpdater } from './updater'import { fetchCheck } from './check'import { hookServer } from './agents/hook-server'import { setMainWindow, getMainWindow, sendToMain, shouldHideOnClose } from './main-window'+import { retainUntilDismissed } from './notifications'import { installManagedAgentHooks } from './agents/hooks'import { createSubagentTail } from './subagent-tail'import { createContextTail, type TaskNotification } from './context-tail'@@ -292,6 +293,9 @@ app.whenReady().then(async () => {w.focus()if (payload.nodeId) w.webContents.send(IPC.appFocusNode, payload.nodeId)})+ // Without a retained reference the wrapper gets GC'd and the click handler dies —+ // clicking would then only activate the app, never focus the originating node.+ retainUntilDismissed(n)n.show()return true}diff --git a/src/main/notifications.test.ts b/src/main/notifications.test.tsnew file mode 100644index 000000000..3c1ae860b--- /dev/null+++ b/src/main/notifications.test.ts@@ -0,0 +1,66 @@+import { describe, it, expect, beforeEach } from 'vitest'+import {+ retainUntilDismissed,+ retainedNotificationCount,+ clearRetainedNotifications,+ MAX_RETAINED_NOTIFICATIONS,+ type NotificationLike+} from './notifications'++// Minimal EventEmitter-ish stand-in for Electron's Notification.+function fakeNotification(): NotificationLike & { emit(event: string): void } {+ const listeners = new Map<string, Array<() => void>>()+ return {+ on(event: string, cb: () => void) {+ const list = listeners.get(event) ?? []+ list.push(cb)+ listeners.set(event, list)+ },+ emit(event: string) {+ for (const cb of listeners.get(event) ?? []) cb()+ }+ }+}++describe('retainUntilDismissed', () => {+ beforeEach(() => clearRetainedNotifications())++ it('retains a notification so it cannot be garbage-collected', () => {+ retainUntilDismissed(fakeNotification())+ expect(retainedNotificationCount()).toBe(1)+ })++ it('releases on click', () => {+ const n = fakeNotification()+ retainUntilDismissed(n)+ n.emit('click')+ expect(retainedNotificationCount()).toBe(0)+ })++ it('releases on close', () => {+ const n = fakeNotification()+ retainUntilDismissed(n)+ n.emit('close')+ expect(retainedNotificationCount()).toBe(0)+ })++ it('releases on failed', () => {+ const n = fakeNotification()+ retainUntilDismissed(n)+ n.emit('failed')+ expect(retainedNotificationCount()).toBe(0)+ })++ it('a click on one notification does not release the others', () => {+ const a = fakeNotification()+ retainUntilDismissed(a)+ retainUntilDismissed(fakeNotification())+ a.emit('click')+ expect(retainedNotificationCount()).toBe(1)+ })++ it('caps retained notifications by dropping the oldest', () => {+ for (let i = 0; i < MAX_RETAINED_NOTIFICATIONS + 5; i++) retainUntilDismissed(fakeNotification())+ expect(retainedNotificationCount()).toBe(MAX_RETAINED_NOTIFICATIONS)+ })+})diff --git a/src/main/notifications.ts b/src/main/notifications.tsnew file mode 100644index 000000000..d59b5c167--- /dev/null+++ b/src/main/notifications.ts@@ -0,0 +1,37 @@+// Electron garbage-collects Notification objects nothing references (electron/electron#16922):+// the notification still shows, but once the wrapper is collected its 'click' handler is gone —+// clicking then only activates the app (macOS default) instead of running our focus logic.+// Retain every shown notification here until the OS reports it dismissed.++// Structural view of Electron's Notification (keeps this module electron-free and unit-testable).+export interface NotificationLike {+ on(event: 'click' | 'close' | 'failed', cb: () => void): void+}++// Backstop for notifications macOS parks in Notification Center without ever emitting+// 'close' — beyond this, the oldest retained one is dropped (its click stops working,+// which is the pre-fix behavior; anything recent keeps its handler alive).+export const MAX_RETAINED_NOTIFICATIONS = 50++const live = new Set<NotificationLike>()++export function retainUntilDismissed(n: NotificationLike): void {+ live.add(n)+ const release = () => live.delete(n)+ n.on('click', release)+ n.on('close', release)+ n.on('failed', release)+ while (live.size > MAX_RETAINED_NOTIFICATIONS) {+ const oldest = live.values().next().value+ if (!oldest) break+ live.delete(oldest)+ }+}++export function retainedNotificationCount(): number {+ return live.size+}++export function clearRetainedNotifications(): void {+ live.clear()+}diff --git a/src/main/updater.ts b/src/main/updater.tsindex 5994e2312..ba67632a7 100644--- a/src/main/updater.ts+++ b/src/main/updater.ts@@ -7,6 +7,7 @@import { app, BrowserWindow, ipcMain, Notification } from 'electron'import electronUpdater from 'electron-updater'import { IPC } from '../shared/ipc'+import { retainUntilDismissed } from './notifications'const { autoUpdater } = electronUpdater@@ -58,6 +59,8 @@ export function initUpdater(win: BrowserWindow): void {win.show()win.focus()})+ // Keep a reference or GC silently kills the click handler (electron/electron#16922).+ retainUntilDismissed(n)n.show()}})