Push notifications: period soon/late reminders, test button
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
ce66b857db
commit
bb19bc0aeb
12 changed files with 872 additions and 21 deletions
29
static/sw.js
Normal file
29
static/sw.js
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
// Service worker: only shows push notifications. It deliberately caches
|
||||
// nothing, so the app always loads fresh from the server.
|
||||
self.addEventListener("install", () => self.skipWaiting());
|
||||
self.addEventListener("activate", event => event.waitUntil(self.clients.claim()));
|
||||
|
||||
self.addEventListener("push", event => {
|
||||
let message = { title: "Flowtrack", body: "" };
|
||||
try {
|
||||
message = { ...message, ...event.data.json() };
|
||||
} catch {
|
||||
// An empty or unreadable push still has to show something on iOS.
|
||||
}
|
||||
event.waitUntil(self.registration.showNotification(message.title, {
|
||||
body: message.body,
|
||||
icon: "/icon-192.png",
|
||||
badge: "/icon-192.png",
|
||||
tag: message.tag,
|
||||
data: { url: message.url || "/" }
|
||||
}));
|
||||
});
|
||||
|
||||
self.addEventListener("notificationclick", event => {
|
||||
event.notification.close();
|
||||
event.waitUntil((async () => {
|
||||
const windows = await self.clients.matchAll({ type: "window", includeUncontrolled: true });
|
||||
if (windows.length) return windows[0].focus();
|
||||
return self.clients.openWindow(event.notification.data.url);
|
||||
})());
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue