vikunja-frontend/src/sw.js

56 lines
1.3 KiB
JavaScript
Raw Normal View History

2019-10-16 20:25:10 +02:00
/* eslint-disable no-console */
/* eslint-disable no-undef */
2019-10-16 20:25:10 +02:00
importScripts( '/workbox-v6.2.2/workbox-sw.js')
workbox.setConfig({modulePathPrefix: '/workbox-v6.2.2'})
import { precacheAndRoute } from 'workbox-precaching'
precacheAndRoute(self.__WB_MANIFEST)
// Cache assets
workbox.routing.registerRoute(
// This regexp matches all files in precache-manifest
new RegExp('.+\\.(css|json|js|svg|woff2|png|html|txt|wav)$'),
new workbox.strategies.StaleWhileRevalidate(),
)
2019-10-16 20:25:10 +02:00
// Always send api reqeusts through the network
workbox.routing.registerRoute(
new RegExp('api\\/v1\\/.*$'),
new workbox.strategies.NetworkOnly(),
)
// This code listens for the user's confirmation to update the app.
self.addEventListener('message', (e) => {
if (!e.data) {
return
}
switch (e.data) {
case 'skipWaiting':
self.skipWaiting()
break
default:
// NOOP
break
}
})
// Notification action
self.addEventListener('notificationclick', function (event) {
const taskId = event.notification.data.taskId
event.notification.close()
switch (event.action) {
case 'show-task':
clients.openWindow(`/tasks/${taskId}`)
break
}
})
workbox.core.clientsClaim()
// The precaching code provided by Workbox.
self.__precacheManifest = [].concat(self.__precacheManifest || [])
workbox.precaching.precacheAndRoute(self.__precacheManifest, {})
2021-07-26 23:09:49 +02:00