mirror of
https://github.com/CorentinTh/it-tools.git
synced 2025-07-19 21:29:37 +02:00
33 lines
908 B
TypeScript
33 lines
908 B
TypeScript
|
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 },
|
||
|
);
|
||
|
}
|