From 757604fd600f7bec109a805588d08a61c00876de Mon Sep 17 00:00:00 2001 From: David Baker Date: Wed, 2 Nov 2016 17:36:48 +0000 Subject: [PATCH 1/2] Add Notification support to the Web Platform Except display notification which was already accidentally included in a previous PR --- src/vector/platform/WebPlatform.js | 34 ++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/vector/platform/WebPlatform.js b/src/vector/platform/WebPlatform.js index 7ef2b6b8a..b3274021f 100644 --- a/src/vector/platform/WebPlatform.js +++ b/src/vector/platform/WebPlatform.js @@ -63,6 +63,40 @@ export default class WebPlatform extends BasePlatform { this._updateFavicon(); } + /** + * Returns true if the platform supports displaying + * notifications, otherwise false. + */ + supportsNotifications() : boolean { + return true; + } + + /** + * Returns true if the application currently has permission + * to display notifications. Otherwise false. + */ + maySendNotifications() : boolean { + return global.Notification.permission == 'granted'; + } + + /** + * Requests permission to send notifications. Returns + * a promise that is resolved when the user has responded + * to the request. The promise has a single string argument + * that is 'granted' if the user allowed the request or + * 'denied' otherwise. + */ + requestNotificationPermission() : Promise { + // annoyingly, the latest spec says this returns a + // promise, but this is only supported in Chrome 46 + // and Firefox 47, so adapt the callback API. + const defer = q.defer(); + global.Notification.requestPermission((result) => { + defer.resolve(result); + }); + return defer.promise; + } + displayNotification(title: string, msg: string, avatarUrl: string) { const notification = new global.Notification( title, From 6aba9f8edaa749247917002fc7a7b83b6e859731 Mon Sep 17 00:00:00 2001 From: David Baker Date: Wed, 2 Nov 2016 19:26:07 +0000 Subject: [PATCH 2/2] Don't always claim we have notif support Only if the browser has the Notification API --- src/vector/platform/WebPlatform.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/vector/platform/WebPlatform.js b/src/vector/platform/WebPlatform.js index b3274021f..3477fc8bc 100644 --- a/src/vector/platform/WebPlatform.js +++ b/src/vector/platform/WebPlatform.js @@ -68,7 +68,7 @@ export default class WebPlatform extends BasePlatform { * notifications, otherwise false. */ supportsNotifications() : boolean { - return true; + return Boolean(global.Notification); } /**