MeshCentral/public/serviceworker.js

13 lines
644 B
JavaScript
Raw Normal View History

2021-02-09 10:35:03 +03:00
self.addEventListener('push', function (event) {
2021-02-10 02:31:50 +03:00
if (event.data == null) return;
var json = event.data.json();
const options = { body: json.body, icon: '/favicon-303x303.png', data: { url: json.url } };
2021-02-10 02:31:50 +03:00
if (json.icon) { options.icon = '/images/notify/icons128-' + json.icon + '.png'; }
event.waitUntil(self.registration.showNotification(json.title, options));
2021-02-09 10:35:03 +03:00
});
2021-02-10 02:31:50 +03:00
self.addEventListener('notificationclick', function (event) {
event.notification.close();
if ((event.notification.data.url != null) && (event.notification.data.url != '')) { event.waitUntil(self.clients.openWindow(event.notification.data.url)); }
2021-02-10 02:31:50 +03:00
});