Skip to content

Commit 2ff4af0

Browse files
committed
Add notification
1 parent 0aa8c0e commit 2ff4af0

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/layouts/Layout.astro

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,13 +107,24 @@ footer {
107107
if ("serviceWorker" in navigator) {
108108
window.addEventListener("load", () => {
109109
navigator.serviceWorker.register("/service-worker.js").then((registration) => {
110-
console.log("ServiceWorker registered: ", registration);
110+
registration.pushManager.getSubscription()
111+
112+
self.addEventListener("push", (event: any) => {
113+
const payload = event.data?.text() ?? "no payload";
114+
event.waitUntil(
115+
registration.showNotification("EP 2025", {
116+
body: payload,
117+
}),
118+
);
119+
});
120+
111121
}).catch((registrationError) => {
112122
console.log("ServiceWorker registration failed: ", registrationError);
113123
});
114124
});
115125
}
116126

127+
117128
document.addEventListener('DOMContentLoaded', () => {
118129
if (window.matchMedia('(display-mode: standalone)').matches) {
119130
document.addEventListener('click', function (e: Event) {

0 commit comments

Comments
 (0)