mirror of
https://github.com/Retrospring/retrospring.git
synced 2024-11-20 16:29:52 +01:00
25 lines
750 B
JavaScript
25 lines
750 B
JavaScript
self.addEventListener('push', function (event) {
|
|
if (event.data) {
|
|
const notification = event.data.json();
|
|
|
|
event.waitUntil(self.registration.showNotification(notification.title, {
|
|
body: notification.body,
|
|
tag: notification.type,
|
|
icon: notification.icon,
|
|
}));
|
|
} else {
|
|
console.error("Push event received, but it didn't contain any data.", event);
|
|
}
|
|
});
|
|
|
|
self.addEventListener('notificationclick', async event => {
|
|
if (event.notification.tag === 'inbox') {
|
|
event.preventDefault();
|
|
return clients.openWindow("/inbox", "_blank").then(result => {
|
|
event.notification.close();
|
|
return result;
|
|
});
|
|
} else {
|
|
console.warn(`Unhandled notification tag: ${event.notification.tag}`);
|
|
}
|
|
});
|