feat: implement PWA update prompt and manual reload
This commit is contained in:
20
src/main.js
20
src/main.js
@@ -31,23 +31,3 @@ app.directive('cell-hover', vCellHover)
|
||||
|
||||
app.mount('#app')
|
||||
|
||||
if ('serviceWorker' in navigator) {
|
||||
let refreshing = false
|
||||
const triggerReload = () => {
|
||||
if (refreshing) return
|
||||
refreshing = true
|
||||
window.location.reload()
|
||||
}
|
||||
navigator.serviceWorker.addEventListener('controllerchange', triggerReload)
|
||||
const checkForUpdate = () => {
|
||||
navigator.serviceWorker.getRegistration().then((registration) => {
|
||||
if (registration) {
|
||||
registration.update()
|
||||
}
|
||||
})
|
||||
}
|
||||
window.addEventListener('visibilitychange', () => {
|
||||
if (document.visibilityState === 'visible') checkForUpdate()
|
||||
})
|
||||
window.addEventListener('focus', checkForUpdate)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user