feat: initial commit
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
// Ported from legacy henza_pwa/src/Mixins/useRefresh.ts.
|
||||
// Auto-applies a waiting service worker as soon as one is available, so the
|
||||
// PWA self-updates instead of serving a stale precache indefinitely.
|
||||
import { unref, watchEffect } from 'vue'
|
||||
import { useRegisterSW } from 'virtual:pwa-register/vue'
|
||||
|
||||
export function useRefresh() {
|
||||
const { offlineReady, needRefresh, updateServiceWorker } = useRegisterSW()
|
||||
|
||||
const refreshApp = async () => {
|
||||
await updateServiceWorker()
|
||||
offlineReady.value = false
|
||||
needRefresh.value = false
|
||||
}
|
||||
|
||||
watchEffect(async () => (unref(offlineReady) || unref(needRefresh)) && (await refreshApp()))
|
||||
}
|
||||
Reference in New Issue
Block a user