2026-03-22 00:36:02 -05:00
|
|
|
self.addEventListener("install", () => self.skipWaiting());
|
|
|
|
|
self.addEventListener("activate", (event) => {
|
|
|
|
|
event.waitUntil(self.clients.claim());
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
self.addEventListener("notificationclick", (event) => {
|
|
|
|
|
event.notification.close();
|
|
|
|
|
|
|
|
|
|
const targetUrl = (event.notification.data && event.notification.data.url)
|
|
|
|
|
? event.notification.data.url
|
|
|
|
|
: "/notifications";
|
|
|
|
|
|
|
|
|
|
event.waitUntil(
|
|
|
|
|
self.clients
|
|
|
|
|
.matchAll({ type: "window", includeUncontrolled: true })
|
|
|
|
|
.then((clientList) => {
|
|
|
|
|
for (const client of clientList) {
|
|
|
|
|
try {
|
|
|
|
|
const clientUrl = new URL(client.url);
|
|
|
|
|
if (clientUrl.origin === self.location.origin) {
|
2026-03-23 20:24:35 +01:00
|
|
|
client.navigate(targetUrl);
|
2026-03-22 00:36:02 -05:00
|
|
|
return client.focus();
|
|
|
|
|
}
|
|
|
|
|
} catch {}
|
|
|
|
|
}
|
|
|
|
|
return self.clients.openWindow(targetUrl);
|
|
|
|
|
}),
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
2026-03-23 20:24:35 +01:00
|
|
|
self.addEventListener("push", (event) => {
|
|
|
|
|
if (!event.data) return;
|
|
|
|
|
|
|
|
|
|
let data;
|
|
|
|
|
try {
|
|
|
|
|
data = event.data.json();
|
|
|
|
|
} catch {
|
|
|
|
|
data = { title: "Overlord", body: event.data.text() };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const title = String(data.title || "Overlord Notification");
|
|
|
|
|
const options = {
|
|
|
|
|
body: String(data.body || ""),
|
|
|
|
|
icon: "/assets/overlord.png",
|
|
|
|
|
badge: "/assets/overlord.png",
|
|
|
|
|
tag: data.tag || `overlord-push-${Date.now()}`,
|
|
|
|
|
data: { url: data.url || "/notifications" },
|
|
|
|
|
requireInteraction: false,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
event.waitUntil(self.registration.showNotification(title, options));
|
|
|
|
|
});
|
|
|
|
|
|
2026-03-22 00:36:02 -05:00
|
|
|
self.addEventListener("message", (event) => {
|
|
|
|
|
const data = event.data;
|
|
|
|
|
if (!data || data.type !== "show_notification") return;
|
|
|
|
|
|
|
|
|
|
const title = String(data.title || "Overlord Notification");
|
|
|
|
|
const options = {
|
|
|
|
|
body: String(data.body || ""),
|
|
|
|
|
icon: data.icon || "/assets/overlord.png",
|
|
|
|
|
badge: "/assets/overlord.png",
|
|
|
|
|
tag: data.tag || `overlord-${Date.now()}`,
|
2026-03-23 20:24:35 +01:00
|
|
|
data: { url: data.url || "/notifications" },
|
2026-03-22 00:36:02 -05:00
|
|
|
requireInteraction: false,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
event.waitUntil(self.registration.showNotification(title, options));
|
|
|
|
|
});
|