/* * SkateSpots push service worker. * * Receives a Web Push payload from `push-service/` — which is CONTENT-FREE * ({ title, body, wrapId, url }) because the server never decrypts anything — * and shows an OS notification. Tapping it focuses/opens the app, where the real * message is fetched by wrapId and decrypted locally. * * Deliberately tiny: no caching, no offline logic. */ self.addEventListener('push', (event) => { let data = {}; try { data = event.data ? event.data.json() : {}; } catch { /* non-JSON payload — fall back to defaults */ } const title = data.title || 'SkateSpots'; const body = data.body || 'You have a new notification'; event.waitUntil( self.registration.showNotification(title, { body, tag: data.wrapId || undefined, data: { url: data.url || '/' }, }), ); }); self.addEventListener('notificationclick', (event) => { event.notification.close(); const target = (event.notification.data && event.notification.data.url) || '/'; event.waitUntil( self.clients.matchAll({ type: 'window', includeUncontrolled: true }).then((list) => { for (const client of list) { if ('focus' in client) return client.focus(); } return self.clients.openWindow(target); }), ); });