folx-tv/client/public/sw.js
sebastjanartic f6478a7663 Add web push notification system for user engagement and updates
Implement a web push notification system, including service worker integration, user subscription management, and an admin interface for sending broadcast messages.

Replit-Commit-Author: Agent
Replit-Commit-Session-Id: 23852c00-4779-460a-9e0c-d09fee4b6c92
Replit-Commit-Checkpoint-Type: full_checkpoint
Replit-Commit-Event-Id: f585829f-898b-492f-82a5-11f4a76c87fb
Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/f209e72a-0939-48fa-84fc-57854de71967/23852c00-4779-460a-9e0c-d09fee4b6c92/ICRgny1
Replit-Helium-Checkpoint-Created: true
2026-03-07 15:16:12 +00:00

32 lines
948 B
JavaScript

self.addEventListener("push", (event) => {
let data = { title: "FOLX TV", body: "Neuer Inhalt verfügbar!", url: "/" };
try {
data = event.data.json();
} catch (e) {}
event.waitUntil(
self.registration.showNotification(data.title, {
body: data.body,
icon: "/favicon.png",
badge: "/favicon.png",
data: { url: data.url || "/" },
})
);
});
self.addEventListener("notificationclick", (event) => {
event.notification.close();
let url = event.notification.data?.url || "/";
if (!url.startsWith("/") || url.startsWith("//")) url = "/";
event.waitUntil(
clients.matchAll({ type: "window", includeUncontrolled: true }).then((clientList) => {
for (const client of clientList) {
if (client.url.includes(self.location.origin) && "focus" in client) {
client.navigate(url);
return client.focus();
}
}
return clients.openWindow(url);
})
);
});