36 lines
1017 B
JavaScript
36 lines
1017 B
JavaScript
const CACHE_NAME = "saldo-shell-v1";
|
|
const APP_SHELL = [
|
|
"/",
|
|
"/static/css/app.css",
|
|
"/static/js/app.js",
|
|
"/static/manifest.json",
|
|
];
|
|
|
|
self.addEventListener("install", (event) => {
|
|
event.waitUntil(caches.open(CACHE_NAME).then((cache) => cache.addAll(APP_SHELL)));
|
|
});
|
|
|
|
self.addEventListener("fetch", (event) => {
|
|
if (event.request.method !== "GET") return;
|
|
event.respondWith(
|
|
caches.match(event.request).then((response) => response || fetch(event.request))
|
|
);
|
|
});
|
|
|
|
self.addEventListener("push", (event) => {
|
|
const data = event.data ? event.data.json() : { title: "Saldo", body: "Neue Erinnerung" };
|
|
event.waitUntil(
|
|
self.registration.showNotification(data.title, {
|
|
body: data.body,
|
|
icon: "/static/icons/landmark.svg",
|
|
badge: "/static/icons/bell.svg",
|
|
data: { url: data.url || "/" },
|
|
})
|
|
);
|
|
});
|
|
|
|
self.addEventListener("notificationclick", (event) => {
|
|
event.notification.close();
|
|
event.waitUntil(clients.openWindow(event.notification.data.url || "/"));
|
|
});
|