mirror of
https://github.com/SchildiChat/element-web.git
synced 2024-10-01 01:26:12 -04:00
Add Notification support to the Web Platform
Except display notification which was already accidentally included in a previous PR
This commit is contained in:
parent
0b5085ecbb
commit
757604fd60
@ -63,6 +63,40 @@ export default class WebPlatform extends BasePlatform {
|
|||||||
this._updateFavicon();
|
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) {
|
displayNotification(title: string, msg: string, avatarUrl: string) {
|
||||||
const notification = new global.Notification(
|
const notification = new global.Notification(
|
||||||
title,
|
title,
|
||||||
|
Loading…
Reference in New Issue
Block a user