The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
feat(desktop): flash the taskbar/dock entry when a native notification fires while unfocused
Sn0wfly0ab62b8949cb
diff --git a/apps/desktop/electron/notification-ipc.test.ts b/apps/desktop/electron/notification-ipc.test.tsindex e695a1741f7..966ebb363c7 100644--- a/apps/desktop/electron/notification-ipc.test.ts+++ b/apps/desktop/electron/notification-ipc.test.ts@@ -27,11 +27,13 @@ vi.mock('electron', () => ({import { registerNativeNotifications } from './notification-ipc'-function windowStub() {- return {+function windowStub(focused = true) {+ return Object.assign(new EventEmitter(), {+ flashFrame: vi.fn(),isDestroyed: vi.fn(() => false),+ isFocused: vi.fn(() => focused),webContents: { isDestroyed: vi.fn(() => false), send: vi.fn() }- }+ })}beforeEach(() => {@@ -130,3 +132,27 @@ it('delivers plugin callbacks to their source and falls back only for navigation}))})++it('flashes an unfocused source window until it regains focus, and leaves a focused one alone', async () => {+ const source = windowStub(false)+ host.fromWebContents.mockReturnValue(source)+ registerNativeNotifications({ getMainWindow: () => null, focusWindow: vi.fn(), platform: 'win32' })++ const notify = host.handle.mock.calls[0][1] as (+ event: IpcMainInvokeEvent,+ payload: HermesNotification+ ) => Promise<boolean>++ const event = { sender: source.webContents } as unknown as IpcMainInvokeEvent++ await notify(event, { kind: 'turnDone', sessionId: 'a', title: 'Hermes finished' })+ await notify(event, { kind: 'turnDone', sessionId: 'b', title: 'Hermes finished' })+ expect(source.flashFrame.mock.calls).toEqual([[true]])++ source.emit('focus')+ expect(source.flashFrame.mock.calls).toEqual([[true], [false]])++ source.isFocused.mockReturnValue(true)+ await notify(event, { kind: 'turnDone', sessionId: 'c', title: 'Hermes finished' })+ expect(source.flashFrame).toHaveBeenCalledTimes(2)+})diff --git a/apps/desktop/electron/notification-ipc.ts b/apps/desktop/electron/notification-ipc.tsindex 2c784ec2a2e..42550572b2c 100644--- a/apps/desktop/electron/notification-ipc.ts+++ b/apps/desktop/electron/notification-ipc.ts@@ -12,6 +12,24 @@ interface NotificationHost {platform?: NodeJS.Platform}+const flashingWindows = new WeakSet<BrowserWindow>()++export function requestAttention(window: BrowserWindow | null | undefined): void {+ if (!window || window.isDestroyed() || window.isFocused() || flashingWindows.has(window)) {+ return+ }++ flashingWindows.add(window)+ window.flashFrame(true)+ window.once('focus', () => {+ flashingWindows.delete(window)++ if (!window.isDestroyed()) {+ window.flashFrame(false)+ }+ })+}+export function registerNativeNotifications({getMainWindow,focusWindow,@@ -109,6 +127,9 @@ export function registerNativeNotifications({})notifications.retain(notification)+ // The toast is transient; flash the taskbar/dock entry until the window is focused.+ requestAttention(targetWindow())+// Peers share the actual outcome, including pending/failed Linux delivery.const delivery = Promise.resolve(notification.show()).then(result => result !== false)deliveries.set(key, delivery)diff --git a/apps/desktop/electron/notification-linux.test.ts b/apps/desktop/electron/notification-linux.test.tsindex 381d5756c06..5cf314caac0 100644--- a/apps/desktop/electron/notification-linux.test.ts+++ b/apps/desktop/electron/notification-linux.test.ts@@ -143,8 +143,21 @@ function setup(alreadyRunning = false) {}host.createClient.mockReturnValue({ connection, invoke, invokeDbus: invoke })- const primary = { isDestroyed: vi.fn(() => false), webContents: { send: vi.fn() } }- const source = { isDestroyed: vi.fn(() => false), webContents: { send: vi.fn() } }++ const primary = {+ flashFrame: vi.fn(),+ isDestroyed: vi.fn(() => false),+ isFocused: vi.fn(() => true),+ webContents: { send: vi.fn() }+ }++ const source = {+ flashFrame: vi.fn(),+ isDestroyed: vi.fn(() => false),+ isFocused: vi.fn(() => true),+ webContents: { send: vi.fn() }+ }+host.fromWebContents.mockReturnValue(source)const focusWindow = vi.fn()