24 lines
683 B
JavaScript
24 lines
683 B
JavaScript
import { precacheAndRoute } from 'workbox-precaching'
|
|
|
|
precacheAndRoute(self.__WB_MANIFEST)
|
|
|
|
self.addEventListener('push', (event) => {
|
|
let data = { title: 'Dyna Biz Coignières', body: '' }
|
|
try {
|
|
if (event.data) data = event.data.json()
|
|
} catch {}
|
|
const options = {
|
|
body: data.body,
|
|
icon: data.icon || '/logo.svg',
|
|
badge: data.badge || '/favicon.svg',
|
|
data: { url: data.data?.url || '/' },
|
|
}
|
|
event.waitUntil(self.registration.showNotification(data.title, options))
|
|
})
|
|
|
|
self.addEventListener('notificationclick', (event) => {
|
|
event.notification.close()
|
|
const url = event.notification.data?.url || '/'
|
|
event.waitUntil(clients.openWindow(url))
|
|
})
|