Retrospring/public/service_worker.js

24 lines
713 B
JavaScript
Raw Normal View History

self.addEventListener('push', function (event) {
if (event.data) {
const notification = event.data.json();
console.log(event.data);
event.waitUntil(self.registration.showNotification(notification.title, {
2022-09-11 14:55:06 -07:00
body: notification.body,
2022-12-24 12:11:30 -08:00
tag: notification.type,
icon: "/icons/maskable_icon_x128.png"
}));
} else {
console.error("Push event received, but it didn't contain any data.", event);
}
});
2022-09-11 14:55:06 -07:00
self.addEventListener('notificationclick', async event => {
if (event.notification.tag === 'inbox') {
event.preventDefault();
return clients.openWindow("/inbox", "_blank");
} else {
console.warn(`Unhandled notification tag: ${event.notification.tag}`);
}
});