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