Clear notifications on electron
This commit is contained in:
parent
7b4694c637
commit
b6939b8138
2 changed files with 51 additions and 0 deletions
|
@ -30,4 +30,30 @@ export default class ElectronPlatform extends BasePlatform {
|
||||||
super.setNotificationCount(count);
|
super.setNotificationCount(count);
|
||||||
remote.app.setBadgeCount(count);
|
remote.app.setBadgeCount(count);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
displayNotification(title: string, msg: string, avatarUrl: string): Notification {
|
||||||
|
// Notifications in Electron use the HTML5 notification API
|
||||||
|
const notification = new global.Notification(
|
||||||
|
title,
|
||||||
|
{
|
||||||
|
"body": msg,
|
||||||
|
"icon": avatarUrl,
|
||||||
|
"tag": "vector"
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
notification.onclick = function() {
|
||||||
|
dis.dispatch({
|
||||||
|
action: 'view_room',
|
||||||
|
room_id: room.roomId
|
||||||
|
});
|
||||||
|
global.focus();
|
||||||
|
};
|
||||||
|
|
||||||
|
return notification;
|
||||||
|
}
|
||||||
|
|
||||||
|
clearNotification(notif: Notification) {
|
||||||
|
notif.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,4 +60,29 @@ export default class WebPlatform extends BasePlatform {
|
||||||
super.setErrorStatus(errorDidOccur);
|
super.setErrorStatus(errorDidOccur);
|
||||||
this.updateFavicon();
|
this.updateFavicon();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
displayNotification(title: string, msg: string, avatarUrl: string) {
|
||||||
|
const notification = new global.Notification(
|
||||||
|
title,
|
||||||
|
{
|
||||||
|
"body": msg,
|
||||||
|
"icon": avatarUrl,
|
||||||
|
"tag": "vector"
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
notification.onclick = function() {
|
||||||
|
dis.dispatch({
|
||||||
|
action: 'view_room',
|
||||||
|
room_id: room.roomId
|
||||||
|
});
|
||||||
|
global.focus();
|
||||||
|
};
|
||||||
|
|
||||||
|
// Chrome only dismisses notifications after 20s, which
|
||||||
|
// is waaaaay too long
|
||||||
|
global.setTimeout(function() {
|
||||||
|
notification.close();
|
||||||
|
}, 5 * 1000);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue