mirror of
https://github.com/Ylianst/MeshCentral.git
synced 2025-11-07 21:02:53 -05:00
More web push progress.
This commit is contained in:
@@ -1,18 +1,13 @@
|
||||
|
||||
self.addEventListener('push', function (event) {
|
||||
console.log('Service Worker push', JSON.stringify(event));
|
||||
if (event.data) {
|
||||
console.log("Push event!! ", event.data.text());
|
||||
showLocalNotification("Yolo", event.data.text(), self.registration);
|
||||
} else {
|
||||
console.log("Push event but no data");
|
||||
}
|
||||
if (event.data == null) return;
|
||||
var json = event.data.json();
|
||||
const options = { body: json.body, icon: '/favicon-303x303.png', tag: json.url };
|
||||
if (json.icon) { options.icon = '/images/notify/icons128-' + json.icon + '.png'; }
|
||||
self.registration.showNotification(json.title, options);
|
||||
});
|
||||
|
||||
const showLocalNotification = function(title, body, swRegistration) {
|
||||
const options = {
|
||||
body
|
||||
// here you can add more properties like icon, image, vibrate, etc.
|
||||
};
|
||||
swRegistration.showNotification(title, options);
|
||||
};
|
||||
self.addEventListener('notificationclick', function (event) {
|
||||
event.notification.close();
|
||||
if ((event.notification.tag != null) && (event.notification.tag != '')) { event.waitUntil(self.clients.openWindow(event.notification.tag)); }
|
||||
});
|
||||
Reference in New Issue
Block a user