diff --git a/src/serviceworker/mod.ts b/src/serviceworker/mod.ts index c910317..3700c87 100644 --- a/src/serviceworker/mod.ts +++ b/src/serviceworker/mod.ts @@ -9,22 +9,31 @@ const _preCachedPaths = ['/', '/css/*', '/assets/*'] //TODO pre-cache these path export function main() { self.addEventListener('install', (event) => { + //TODO handle installation event.waitUntil( addToCache([]), ) }) self.addEventListener('activate', () => { - console.log('sw activated') + //TODO handle activation }) self.addEventListener('fetch', (_event) => { //TODO add fetch strategies }) + + self.addEventListener('push', (event) => { + const { title, options } = (event.data?.json() ?? {}) as { title?: string, options?: Partial } + if (title) { + event.waitUntil( + self.registration.showNotification(title, options) + ) + } + }) } async function addToCache(ressources: string[]) { const cache = await caches.open(cacheName) //TODO dynamique cache key - await cache.addAll(ressources) //TODO list statics