Skip to content

Commit b6939b8

Browse files
committed
Clear notifications on electron
1 parent 7b4694c commit b6939b8

2 files changed

Lines changed: 51 additions & 0 deletions

File tree

‎src/vector/platform/ElectronPlatform.js‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,30 @@ export default class ElectronPlatform extends BasePlatform {
3030
super.setNotificationCount(count);
3131
remote.app.setBadgeCount(count);
3232
}
33+
34+
displayNotification(title: string, msg: string, avatarUrl: string): Notification {
35+
// Notifications in Electron use the HTML5 notification API
36+
const notification = new global.Notification(
37+
title,
38+
{
39+
"body": msg,
40+
"icon": avatarUrl,
41+
"tag": "vector"
42+
}
43+
);
44+
45+
notification.onclick = function() {
46+
dis.dispatch({
47+
action: 'view_room',
48+
room_id: room.roomId
49+
});
50+
global.focus();
51+
};
52+
53+
return notification;
54+
}
55+
56+
clearNotification(notif: Notification) {
57+
notif.close();
58+
}
3359
}

‎src/vector/platform/WebPlatform.js‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,29 @@ export default class WebPlatform extends BasePlatform {
6060
super.setErrorStatus(errorDidOccur);
6161
this.updateFavicon();
6262
}
63+
64+
displayNotification(title: string, msg: string, avatarUrl: string) {
65+
const notification = new global.Notification(
66+
title,
67+
{
68+
"body": msg,
69+
"icon": avatarUrl,
70+
"tag": "vector"
71+
}
72+
);
73+
74+
notification.onclick = function() {
75+
dis.dispatch({
76+
action: 'view_room',
77+
room_id: room.roomId
78+
});
79+
global.focus();
80+
};
81+
82+
// Chrome only dismisses notifications after 20s, which
83+
// is waaaaay too long
84+
global.setTimeout(function() {
85+
notification.close();
86+
}, 5 * 1000);
87+
}
6388
}

0 commit comments

Comments
 (0)