Design
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
import { useRegisterSW } from 'virtual:pwa-register/vue'
|
||||
import { watch } from 'vue'
|
||||
|
||||
const intervalMS = import.meta.env.DEV ? 5 * 60 * 1000 : 60 * 60 * 1000
|
||||
|
||||
export function useUpdateApp() {
|
||||
const { needRefresh, updateServiceWorker } = useRegisterSW({
|
||||
onRegistered(r) {
|
||||
r &&
|
||||
setInterval(() => {
|
||||
r.update()
|
||||
}, intervalMS)
|
||||
},
|
||||
})
|
||||
const toast = useToast()
|
||||
|
||||
if (import.meta.env.DEV) console.log({ SWNeedRefresh: needRefresh.value })
|
||||
|
||||
async function close(e) {
|
||||
needRefresh.value = false
|
||||
e?.stopPropagation()
|
||||
}
|
||||
|
||||
// New version
|
||||
|
||||
watch(
|
||||
() => needRefresh,
|
||||
(n) => {
|
||||
if (n) {
|
||||
toast.add({
|
||||
title: 'Update',
|
||||
description:
|
||||
'A newer version of the app is available. Click the “Update” button to install.',
|
||||
duration: 0,
|
||||
icon: 'lucide:cloud-download',
|
||||
close: false,
|
||||
actions: [
|
||||
{
|
||||
icon: 'lucide:arrow-big-up-dash',
|
||||
label: 'Update',
|
||||
onClick: updateServiceWorker,
|
||||
color: 'error',
|
||||
},
|
||||
|
||||
{
|
||||
icon: 'lucide:x',
|
||||
label: 'Dismiss',
|
||||
onClick: close,
|
||||
variant: 'outline',
|
||||
},
|
||||
],
|
||||
onEscapeKeyDown: close,
|
||||
})
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user