Some checks failed
Tick / tick (push) Failing after 1s
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
29 lines
893 B
JavaScript
29 lines
893 B
JavaScript
// 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);
|
|
}),
|
|
);
|
|
});
|