1/* Advottic web push service worker. 2 * 3 * Registered by components/PushOptIn.tsx after the user opts in. 4 * Receives push events and shows a Notification, with a click 5 * handler that focuses an existing tab on `data.url` or opens a 6 * new one. 7 */ 8 9self.addEventListener('push', (event) => { 10 if (!event.data) return; 11 let payload = {}; 12 try { 13 payload = event.data.json(); 14 } catch (e) { 15 payload = { title: 'Advottic', body: event.data.text() }; 16 } 17 const title = payload.title || 'Advottic'; 18 const options = { 19 body: payload.body || '', 20 icon: '/icon-192.png', 21 badge: '/icon-192.png', 22 data: { url: payload.url || '/inbox' }, 23 tag: payload.tag, 24 }; 25 event.waitUntil(self.registration.showNotification(title, options)); 26}); 27 28self.addEventListener('notificationclick', (event) => { 29 event.notification.close(); 30 const url = (event.notification.data && event.notification.data.url) || '/inbox'; 31 event.waitUntil( 32 self.clients 33 .matchAll({ type: 'window', includeUncontrolled: true }) 34 .then((clientList) => { 35 for (const client of clientList) { 36 if (client.url.includes(self.location.origin) && 'focus' in client) { 37 client.navigate(url); 38 return client.focus(); 39 } 40 } 41 if (self.clients.openWindow) return self.clients.openWindow(url); 42 return undefined; 43 }), 44 ); 45});
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.