Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion packages/mapviewer/src/utils/offline/OfflineReadinessStatus.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ import SimpleWindow from '@/utils/components/SimpleWindow.vue'
// check for updates every hour
const period = 60 * 60 * 1000

const { withText = false } = defineProps<{
const { withText = false, autoReloadOnUpdate = true } = defineProps<{
withText?: boolean
/** Automatically reload the page when a new service worker takes control */
autoReloadOnUpdate?: boolean
}>()

const isServiceWorkerActive = ref(false)
Expand Down Expand Up @@ -76,6 +78,26 @@ const { offlineReady, needRefresh, updateServiceWorker } = useRegisterSW({
}
})
}

// Listen for when a new service worker takes control
if ('serviceWorker' in navigator) {
navigator.serviceWorker.addEventListener('controllerchange', () => {
log.info({
title: 'OfflineReadinessStatus',
titleColor: LogPreDefinedColor.Sky,
messages: ['New service worker has taken control'],
})

if (autoReloadOnUpdate) {
log.info({
title: 'OfflineReadinessStatus',
titleColor: LogPreDefinedColor.Sky,
messages: ['Auto-reloading page with new service worker'],
})
window.location.reload()
}
})
}
},
})

Expand Down
Loading