Skip to content

Commit e2d3502

Browse files
authored
Merge pull request #4538 from tloncorp/po/desktop-add-dock-notification-badge
desktop: add dock notification badging
2 parents cb77f19 + ecc7865 commit e2d3502

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

apps/tlon-desktop/src/main/notification-service.ts

+24-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,19 @@
1-
import { BrowserWindow, Notification, ipcMain } from 'electron';
1+
import { BrowserWindow, Notification, ipcMain, app } from 'electron';
2+
3+
let unreadNotificationCount = 0;
4+
5+
function updateDockBadge() {
6+
if (unreadNotificationCount > 0) {
7+
app.setBadgeCount(unreadNotificationCount);
8+
} else {
9+
app.setBadgeCount(0);
10+
}
11+
}
12+
13+
export function clearNotifications() {
14+
unreadNotificationCount = 0;
15+
updateDockBadge();
16+
}
217

318
export function setupNotificationService(mainWindow: BrowserWindow) {
419
ipcMain.handle('show-notification', (event, { title, body, data }) => {
@@ -23,6 +38,14 @@ export function setupNotificationService(mainWindow: BrowserWindow) {
2338
});
2439

2540
notification.show();
41+
42+
unreadNotificationCount++;
43+
updateDockBadge();
44+
2645
return true;
2746
});
47+
48+
mainWindow.on('focus', () => {
49+
clearNotifications();
50+
});
2851
}

0 commit comments

Comments
 (0)