Revert "feat: replace Web Push with ntfy for medication reminders"
This reverts commit 1cada42370.
This commit is contained in:
+57
-1
@@ -1,4 +1,4 @@
|
||||
const CACHE = "tym-v1.1.0";
|
||||
const CACHE = "tym-v1.0.1";
|
||||
const ASSETS = [
|
||||
"/",
|
||||
"/index.html",
|
||||
@@ -64,6 +64,62 @@ self.addEventListener("fetch", (event) => {
|
||||
);
|
||||
});
|
||||
|
||||
self.addEventListener("push", (event) => {
|
||||
if (!event.data) return;
|
||||
let data = {};
|
||||
try { data = event.data.json(); } catch { data = { body: event.data.text() }; }
|
||||
|
||||
const options = {
|
||||
body: data.body || "Med-Time!",
|
||||
icon: "/icon-192x192.png",
|
||||
badge: "/icon-72x72.png",
|
||||
silent: data.silent !== false,
|
||||
tag: data.tag || "med-reminder",
|
||||
renotify: true,
|
||||
data: { slot_id: data.slot_id },
|
||||
actions: [
|
||||
{ action: "take", title: "Genommen ✓" },
|
||||
{ action: "snooze15", title: "+15 Min" },
|
||||
{ action: "snooze30", title: "+30 Min" },
|
||||
],
|
||||
};
|
||||
|
||||
event.waitUntil(
|
||||
self.registration.showNotification(data.title || "TakeYourMeds", options)
|
||||
);
|
||||
});
|
||||
|
||||
async function apiPost(path, body) {
|
||||
const clients = await self.clients.matchAll({ type: "window" });
|
||||
for (const client of clients) {
|
||||
client.postMessage({ type: "API_ACTION", path, body });
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
self.addEventListener("notificationclick", (event) => {
|
||||
event.notification.close();
|
||||
const slotId = event.notification.data?.slot_id;
|
||||
const action = event.action;
|
||||
|
||||
if (action === "take" && slotId) {
|
||||
event.waitUntil(
|
||||
self.clients.openWindow(`/?action=take&slot=${slotId}`)
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
if ((action === "snooze15" || action === "snooze30") && slotId) {
|
||||
const minutes = action === "snooze15" ? 15 : 30;
|
||||
event.waitUntil(
|
||||
self.clients.openWindow(`/?action=snooze&slot=${slotId}&minutes=${minutes}`)
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
event.waitUntil(self.clients.openWindow("/"));
|
||||
});
|
||||
|
||||
self.addEventListener("sync", (event) => {
|
||||
if (event.tag === "sync-logs") {
|
||||
event.waitUntil(
|
||||
|
||||
Reference in New Issue
Block a user