mirror of
https://gitlab.com/soapbox-pub/mkstack.git
synced 2026-12-05 08:23:35 +00:00
34 lines
766 B
JavaScript
34 lines
766 B
JavaScript
// public/sw.js
|
|
|
|
self.addEventListener("push", (event) => {
|
|
if (!event.data) return;
|
|
|
|
try {
|
|
const data = event.data.json();
|
|
|
|
const title = data.title || "New Notification";
|
|
const options = {
|
|
body: data.body,
|
|
icon: data.icon || "/icon-192.png"
|
|
// badge: data.badge || "/badge-72x72.png",
|
|
// data: data.data || {},
|
|
};
|
|
|
|
event.waitUntil(
|
|
self.registration.showNotification(title, options)
|
|
);
|
|
} catch (err) {
|
|
console.error("Push event error:", err);
|
|
}
|
|
});
|
|
|
|
self.addEventListener("notificationclick", (event) => {
|
|
event.notification.close();
|
|
|
|
// If you send a `url` in payload.data, open it
|
|
const url = event.notification.data?.url;
|
|
if (url) {
|
|
event.waitUntil(clients.openWindow(url));
|
|
}
|
|
});
|