trading-app/public/sw.js
David 27a358038a
Some checks failed
Tick / tick (push) Failing after 1s
Cagnotte V1: IA news-driven trading sim, sandbox, PEA tracking, PWA
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-13 19:06:17 +01:00

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);
}),
);
});