This commit is contained in:
2026-09-06 04:04:59 +03:00
commit 83a975ba3c
44 changed files with 6558 additions and 0 deletions
+57
View File
@@ -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,
})
}
},
)
}