diff options
| author | altaf-creator <dev@altafcreator.com> | 2026-01-16 20:34:35 +0800 |
|---|---|---|
| committer | altaf-creator <dev@altafcreator.com> | 2026-01-16 20:34:35 +0800 |
| commit | 82ea96facb47eaa7f033ca094c8caf21d082480f (patch) | |
| tree | 60f6b26302577870029384dba2d59e1db166fa81 /frontend/sw.js | |
| parent | 83c5deaa22742bce41ae38d9730fc4b5dd63eecf (diff) | |
enhancements
Diffstat (limited to 'frontend/sw.js')
| -rw-r--r-- | frontend/sw.js | 40 |
1 files changed, 37 insertions, 3 deletions
diff --git a/frontend/sw.js b/frontend/sw.js index f0ba7d8..bd38341 100644 --- a/frontend/sw.js +++ b/frontend/sw.js @@ -2,7 +2,41 @@ self.addEventListener('push', (e) => { console.log(e.data); const data = e.data.json(); console.log(data); - self.registration.showNotification(data.title, { - body: data.body, - }); + if (data.requireInteraction) { + self.registration.showNotification(data.title, { + body: data.body, + vibrate: [200, 100, 200], + requireInteraction: data.requireInteraction, + actions: [ + { + title: "I've collected my laundry!", + action: "collect", + } + ], + data: {timerId: data.timerId}, + }); + } else { + self.registration.showNotification(data.title, { + body: data.body, + vibrate: [200, 100, 200], + }); + } +}); + +self.addEventListener("notificationclick", (event) => { + if (event.action === "collect") { + timerId = event.data.timerId; + console.log("finishing timer! w/ id "+timerId.toString()); + fetch(`${API_URL}/finish`, { + method: "POST", + credentials: "include", + headers: { + "Content-Type": "application/json" + }, + body: JSON.stringify({id: timerId}), + }); + clients.openWindow("/timer/"); + } else { + clients.openWindow("/timer/"); + } }); |
