forked from andyburke/autonomous.contact
29 lines
601 B
JavaScript
29 lines
601 B
JavaScript
const NOTIFICATIONS = {
|
|
_notifications: [],
|
|
|
|
send: function (message, options = {}) {
|
|
if (!Notification || Notification.permission !== "granted") {
|
|
return;
|
|
}
|
|
|
|
const notification = new Notification(message, options);
|
|
this._notifications.push( notification );
|
|
return notification;
|
|
},
|
|
|
|
close: function() {
|
|
for ( const notification of this._notifications ) {
|
|
notification?.close();
|
|
}
|
|
|
|
this._notifications.length = 0;
|
|
},
|
|
|
|
request_permission: function () {
|
|
if (Notification && Notification.permission === "granted") {
|
|
return;
|
|
}
|
|
|
|
Notification.requestPermission();
|
|
},
|
|
};
|