2018-12-22 23:37:51 +00:00
|
|
|
import { toast } from '../_components/toast/toast'
|
2018-01-19 07:37:43 +00:00
|
|
|
|
2018-02-09 06:29:29 +00:00
|
|
|
function onUpdateFound (registration) {
|
2018-01-19 07:37:43 +00:00
|
|
|
const newWorker = registration.installing
|
|
|
|
|
|
|
|
newWorker.addEventListener('statechange', async () => {
|
2018-01-19 08:29:45 +00:00
|
|
|
if (newWorker.state === 'installed' && navigator.serviceWorker.controller) {
|
2018-03-15 06:17:47 +00:00
|
|
|
toast.say('App update available. Reload to update.')
|
2018-01-19 07:37:43 +00:00
|
|
|
}
|
2018-02-09 06:29:29 +00:00
|
|
|
})
|
2018-01-19 07:37:43 +00:00
|
|
|
}
|
|
|
|
|
2018-12-16 01:13:46 +00:00
|
|
|
if ('serviceWorker' in navigator) {
|
2018-01-19 07:37:43 +00:00
|
|
|
navigator.serviceWorker.register('/service-worker.js').then(registration => {
|
|
|
|
registration.addEventListener('updatefound', () => onUpdateFound(registration))
|
|
|
|
})
|
2018-02-09 06:29:29 +00:00
|
|
|
}
|