From 82ea96facb47eaa7f033ca094c8caf21d082480f Mon Sep 17 00:00:00 2001 From: altaf-creator Date: Fri, 16 Jan 2026 20:34:35 +0800 Subject: enhancements --- frontend/sw.js | 40 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 37 insertions(+), 3 deletions(-) (limited to 'frontend/sw.js') 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/"); + } }); -- cgit v1.2.3