uptime-kuma/src/serviceWorker.ts

25 lines
724 B
TypeScript
Raw Normal View History

2024-12-15 23:01:34 -05:00
// Needed per Vite PWA docs
import { precacheAndRoute } from 'workbox-precaching'
declare let self: ServiceWorkerGlobalScope
precacheAndRoute(self.__WB_MANIFEST)
// Receive push notifications
2024-12-16 14:21:39 -05:00
self.addEventListener('push', function (event) {
2024-12-15 23:01:34 -05:00
if (!(
self.Notification &&
self.Notification.permission === 'granted'
)) {
//notifications aren't supported or permission not granted!
2024-12-16 14:21:39 -05:00
console.log("Notifications aren't supported or permission not granted!");
2024-12-15 23:01:34 -05:00
return;
}
2024-12-16 14:21:39 -05:00
if (event.data) {
console.log(event);
let message = event.data.json();
self.registration.showNotification(message.title, {
2024-12-15 23:01:34 -05:00
body: message.body,
2024-12-16 14:21:39 -05:00
});
2024-12-15 23:01:34 -05:00
}
});