refactor(pwa): prompt for pwa update

This commit is contained in:
Corentin Thomasset 2023-03-01 21:46:23 +01:00
parent a771346250
commit 53ce079dff
No known key found for this signature in database
GPG key ID: DBD997E935996158
7 changed files with 80 additions and 6 deletions

View file

@ -0,0 +1,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 },
);
}