mirror of
https://github.com/escalante29/WealthySmart.git
synced 2026-07-17 14:28:47 +02:00
manifest.webmanifest with the existing icons, apple-touch-icon, and SW registration at startup. The old sw.js was a self-unregistering cleanup stub — meaning serviceWorker.ready never resolved and web push has been silently dead; the new worker handles push display and notification clicks, and makes the app installable. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
43 lines
1.2 KiB
JavaScript
43 lines
1.2 KiB
JavaScript
/* WealthySmart service worker: web push + PWA installability.
|
|
* (Replaces the old self-unregistering cleanup stub, which also meant
|
|
* `navigator.serviceWorker.ready` never resolved and push silently no-oped.) */
|
|
|
|
self.addEventListener("install", () => self.skipWaiting());
|
|
|
|
self.addEventListener("activate", (event) => {
|
|
event.waitUntil(self.clients.claim());
|
|
});
|
|
|
|
self.addEventListener("push", (event) => {
|
|
let data = { title: "WealthySmart", body: "", url: "/" };
|
|
try {
|
|
data = { ...data, ...event.data.json() };
|
|
} catch {
|
|
if (event.data) data.body = event.data.text();
|
|
}
|
|
event.waitUntil(
|
|
self.registration.showNotification(data.title, {
|
|
body: data.body,
|
|
icon: "/icons/icon-192.png",
|
|
badge: "/icons/icon-192.png",
|
|
data: { url: data.url },
|
|
}),
|
|
);
|
|
});
|
|
|
|
self.addEventListener("notificationclick", (event) => {
|
|
event.notification.close();
|
|
const url = 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);
|
|
}),
|
|
);
|
|
});
|