1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
import { useRegisterSW } from 'virtual:pwa-register/vue';
import { NButton, useNotification } from 'naive-ui';
import { h, type Component } from 'vue';
import { whenever } from '@vueuse/core';
export default function () {
const notification = useNotification();
const { needRefresh, updateServiceWorker } = useRegisterSW();
whenever(
needRefresh,
() => {
notification.create({
title: 'A new version is out!',
content: 'Reload the page to refresh the cache and get the newest version of it-tools',
closable: true,
onClose: () => {
needRefresh.value = false;
return true;
},
action: () =>
h(
NButton as Component,
{ onClick: updateServiceWorker, type: 'primary', secondary: true },
{ default: () => 'Reload' },
),
});
},
{ immediate: true },
);
}
|