// Service worker : reçoit les notifications et ouvre l'app au bon endroit. self.addEventListener("push", (event) => { const data = event.data ? event.data.json() : {}; event.waitUntil( self.registration.showNotification(data.title || "Cagnotte", { body: data.body || "", icon: "/pwa-icon/192", badge: "/pwa-icon/192", data: { url: data.url || "/" }, }), ); }); self.addEventListener("notificationclick", (event) => { event.notification.close(); const url = (event.notification.data && event.notification.data.url) || "/"; event.waitUntil( self.clients.matchAll({ type: "window", includeUncontrolled: true }).then((clients) => { for (const client of clients) { if ("focus" in client) { client.navigate(url); return client.focus(); } } return self.clients.openWindow(url); }), ); });