autonomous.contact/public/js/notifications.js

30 lines
601 B
JavaScript
Raw Normal View History

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();
},
};