mirror of
https://github.com/lana-k/sqliteviz.git
synced 2025-12-06 10:08:52 +08:00
fix service worker registration #12
This commit is contained in:
@@ -1,8 +1,11 @@
|
|||||||
|
let refresh = false
|
||||||
|
|
||||||
function invokeServiceWorkerUpdateFlow (registration) {
|
function invokeServiceWorkerUpdateFlow (registration) {
|
||||||
const agree = confirm('New version of the app is available. Refresh now?')
|
const agree = confirm('New version of the app is available. Refresh now?')
|
||||||
if (agree) {
|
if (agree) {
|
||||||
if (registration.waiting) {
|
if (registration.waiting) {
|
||||||
// let waiting Service Worker know it should became active
|
// let waiting Service Worker know it should became active
|
||||||
|
refresh = true
|
||||||
registration.waiting.postMessage({ type: 'SKIP_WAITING' })
|
registration.waiting.postMessage({ type: 'SKIP_WAITING' })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -23,19 +26,18 @@ if ('serviceWorker' in navigator) {
|
|||||||
if (newRegestration) {
|
if (newRegestration) {
|
||||||
// wait until the new Service worker is actually installed (ready to take over)
|
// wait until the new Service worker is actually installed (ready to take over)
|
||||||
newRegestration.addEventListener('statechange', () => {
|
newRegestration.addEventListener('statechange', () => {
|
||||||
if (registration.waiting) {
|
if (registration.waiting && navigator.serviceWorker.controller) {
|
||||||
invokeServiceWorkerUpdateFlow(registration)
|
invokeServiceWorkerUpdateFlow(registration)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
let refreshing = false
|
|
||||||
// detect controller change and refresh the page
|
// detect controller change and refresh the page
|
||||||
navigator.serviceWorker.addEventListener('controllerchange', () => {
|
navigator.serviceWorker.addEventListener('controllerchange', () => {
|
||||||
if (!refreshing) {
|
if (refresh) {
|
||||||
window.location.reload()
|
window.location.reload()
|
||||||
refreshing = true
|
refresh = false
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -12,7 +12,9 @@ import '@/assets/styles/dialogs.css'
|
|||||||
import '@/assets/styles/tooltips.css'
|
import '@/assets/styles/tooltips.css'
|
||||||
import '@/assets/styles/messages.css'
|
import '@/assets/styles/messages.css'
|
||||||
|
|
||||||
import '../registerServiceWorker'
|
if (!['localhost', '127.0.0.1'].includes(location.hostname)) {
|
||||||
|
import('../registerServiceWorker') // eslint-disable-line no-unused-expressions
|
||||||
|
}
|
||||||
|
|
||||||
Vue.use(VuePlugin)
|
Vue.use(VuePlugin)
|
||||||
Vue.use(VModal)
|
Vue.use(VModal)
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ module.exports = {
|
|||||||
{ from: 'LICENSE', to: './' }
|
{ from: 'LICENSE', to: './' }
|
||||||
]),
|
]),
|
||||||
new WorkboxPlugin.GenerateSW({
|
new WorkboxPlugin.GenerateSW({
|
||||||
|
exclude: [/\.map$/, 'LICENSE', 'queries.json'],
|
||||||
clientsClaim: true,
|
clientsClaim: true,
|
||||||
skipWaiting: false,
|
skipWaiting: false,
|
||||||
maximumFileSizeToCacheInBytes: 40000000
|
maximumFileSizeToCacheInBytes: 40000000
|
||||||
|
|||||||
Reference in New Issue
Block a user