From b6939b8138a832fe8f4bc9a023942488748e0f66 Mon Sep 17 00:00:00 2001 From: David Baker Date: Mon, 24 Oct 2016 16:56:00 +0100 Subject: [PATCH] Clear notifications on electron --- src/vector/platform/ElectronPlatform.js | 26 +++++++++++++++++++++++++ src/vector/platform/WebPlatform.js | 25 ++++++++++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/src/vector/platform/ElectronPlatform.js b/src/vector/platform/ElectronPlatform.js index 56620de21a..da901b923a 100644 --- a/src/vector/platform/ElectronPlatform.js +++ b/src/vector/platform/ElectronPlatform.js @@ -30,4 +30,30 @@ export default class ElectronPlatform extends BasePlatform { super.setNotificationCount(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(); + } } diff --git a/src/vector/platform/WebPlatform.js b/src/vector/platform/WebPlatform.js index be1244434e..d1ae01d630 100644 --- a/src/vector/platform/WebPlatform.js +++ b/src/vector/platform/WebPlatform.js @@ -60,4 +60,29 @@ export default class WebPlatform extends BasePlatform { super.setErrorStatus(errorDidOccur); 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); + } }