Skip to content

Commit 7f15bec

Browse files
fix(notifications): retain Notification reference so click handler fires (#2238)
1 parent e98f1a1 commit 7f15bec

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

apps/code/src/main/platform-adapters/electron-notifier.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@ import type { ElectronMainWindow } from "./electron-main-window";
66

77
@injectable()
88
export class ElectronNotifier implements INotifier {
9+
// Retain shown notifications so V8 doesn't GC the JS wrapper (and its
10+
// `click` listener) before the user interacts. Without this, the OS still
11+
// shows the notification and macOS will even focus the app on click, but
12+
// the JS click handler never fires — so any in-app routing tied to it
13+
// (e.g. switching to the task the notification was about) silently breaks.
14+
private readonly active = new Set<Notification>();
15+
916
constructor(
1017
@inject(MAIN_TOKENS.MainWindow)
1118
private readonly mainWindow: ElectronMainWindow,
@@ -21,6 +28,11 @@ export class ElectronNotifier implements INotifier {
2128
body: options.body,
2229
silent: options.silent,
2330
});
31+
this.active.add(notification);
32+
const release = () => this.active.delete(notification);
33+
notification.once("close", release);
34+
notification.once("click", release);
35+
notification.once("failed", release);
2436
if (options.onClick) {
2537
notification.on("click", options.onClick);
2638
}

0 commit comments

Comments
 (0)