Skip to content

Commit 0db6eb1

Browse files
committed
Clean up notification code: fix desktop notifications and remove unused IPC
- Move desktop notification logic into NotificationService (was broken) - Desktop notifications now show properly via server-side trigger - Remove unused NOTIFICATION_SEND IPC channel and handler - Remove send() method from notification API (not needed) - Use dynamic import instead of require for electron module - Update all comments to reflect server-side architecture
1 parent 61123cf commit 0db6eb1

File tree

7 files changed

+19
-41
lines changed

7 files changed

+19
-41
lines changed

src/App.stories.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ function setupMockAPI(options: {
8989
subscribePush: () => Promise.resolve(undefined),
9090
unsubscribePush: () => Promise.resolve(undefined),
9191
getVapidKey: () => Promise.resolve(null),
92-
send: () => Promise.resolve(undefined),
9392
},
9493
...options.apiOverrides,
9594
};

src/browser/api.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,8 +276,6 @@ const webApi: IPCApi = {
276276
unsubscribePush: (workspaceId, endpoint) =>
277277
invokeIPC(IPC_CHANNELS.NOTIFICATION_UNSUBSCRIBE_PUSH, workspaceId, endpoint),
278278
getVapidKey: () => invokeIPC(IPC_CHANNELS.NOTIFICATION_GET_VAPID_KEY),
279-
send: (workspaceId, workspaceName) =>
280-
invokeIPC(IPC_CHANNELS.NOTIFICATION_SEND, workspaceId, workspaceName),
281279
},
282280
};
283281

src/constants/ipc-constants.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ export const IPC_CHANNELS = {
5252
NOTIFICATION_SUBSCRIBE_PUSH: "notification:subscribePush",
5353
NOTIFICATION_UNSUBSCRIBE_PUSH: "notification:unsubscribePush",
5454
NOTIFICATION_GET_VAPID_KEY: "notification:getVapidKey",
55-
NOTIFICATION_SEND: "notification:send",
5655

5756
// Dynamic channel prefixes
5857
WORKSPACE_CHAT_PREFIX: "workspace:chat:",

src/preload.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,6 @@ const api: IPCApi = {
148148
unsubscribePush: (workspaceId: string, endpoint: string) =>
149149
ipcRenderer.invoke(IPC_CHANNELS.NOTIFICATION_UNSUBSCRIBE_PUSH, workspaceId, endpoint),
150150
getVapidKey: () => ipcRenderer.invoke(IPC_CHANNELS.NOTIFICATION_GET_VAPID_KEY),
151-
send: (workspaceId: string, workspaceName: string) =>
152-
ipcRenderer.invoke(IPC_CHANNELS.NOTIFICATION_SEND, workspaceId, workspaceName),
153151
},
154152
};
155153

src/services/NotificationService.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,13 +103,25 @@ export class NotificationService {
103103

104104
/**
105105
* Send a completion notification
106-
* Desktop: Shows Electron notification (handled by caller)
106+
* Desktop: Shows Electron notification directly (no push needed)
107107
* Web/Mobile: Sends push notification to all subscribed clients
108108
*/
109109
async sendCompletionNotification(workspaceId: string, workspaceName: string): Promise<void> {
110110
if (this.isDesktop) {
111-
// Desktop notifications are handled by the caller (main-desktop.ts)
112-
// This method is only called for web/mobile push notifications
111+
// Desktop: Show native Electron notification
112+
try {
113+
// Dynamic import required: can't statically import electron in server mode
114+
// eslint-disable-next-line no-restricted-syntax -- Dynamic import necessary for server compatibility
115+
const electron = await import("electron");
116+
const notification = new electron.Notification({
117+
title: "Completion",
118+
body: `${workspaceName} has finished`,
119+
});
120+
notification.show();
121+
log.debug(`Showed desktop notification for workspace ${workspaceId}`);
122+
} catch (error) {
123+
log.error("Failed to show desktop notification:", error);
124+
}
113125
return;
114126
}
115127

src/services/ipcMain.ts

Lines changed: 3 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1210,37 +1210,9 @@ export class IpcMain {
12101210
}
12111211
);
12121212

1213-
// Send notification (for desktop or push)
1214-
ipcMain.handle(
1215-
IPC_CHANNELS.NOTIFICATION_SEND,
1216-
async (_event, workspaceId: string, workspaceName: string) => {
1217-
try {
1218-
if (this.isDesktop) {
1219-
// Dynamic import required: can't statically import electron in server mode
1220-
// eslint-disable-next-line no-restricted-syntax -- Dynamic import necessary for server compatibility
1221-
const { Notification } = await import("electron");
1222-
const notification = new Notification({
1223-
title: "Completion",
1224-
body: `${workspaceName} has finished`,
1225-
});
1226-
notification.on("click", () => {
1227-
if (this.mainWindow) {
1228-
if (this.mainWindow.isMinimized()) {
1229-
this.mainWindow.restore();
1230-
}
1231-
this.mainWindow.focus();
1232-
}
1233-
});
1234-
notification.show();
1235-
} else {
1236-
// For web/mobile, send push notifications
1237-
await this.notificationService.sendCompletionNotification(workspaceId, workspaceName);
1238-
}
1239-
} catch (error) {
1240-
log.error("Failed to send notification:", error);
1241-
}
1242-
}
1243-
);
1213+
// Note: NOTIFICATION_SEND handler intentionally omitted
1214+
// Notifications are now triggered server-side in AgentSession on stream-end
1215+
// This ensures push notifications work even when the app is closed (PWA/mobile)
12441216
}
12451217

12461218
private registerProjectHandlers(ipcMain: ElectronIpcMain): void {

src/types/ipc.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ export interface IPCApi {
298298
subscribePush(workspaceId: string, subscription: unknown): Promise<void>;
299299
unsubscribePush(workspaceId: string, endpoint: string): Promise<void>;
300300
getVapidKey(): Promise<string | null>;
301-
send(workspaceId: string, workspaceName: string): Promise<void>;
301+
// Note: send() method removed - notifications triggered server-side in AgentSession
302302
};
303303
}
304304

0 commit comments

Comments
 (0)