|
|
|
@ -5,30 +5,34 @@ import { useRegisterSW } from 'virtual:pwa-register/react';
|
|
|
|
|
|
|
|
|
|
// console.log(pwaInfo, 'pwaInfo');
|
|
|
|
|
|
|
|
|
|
function ReloadPrompt() {
|
|
|
|
|
function ReloadPrompt({ force }) {
|
|
|
|
|
|
|
|
|
|
const {
|
|
|
|
|
offlineReady: [offlineReady, setOfflineReady],
|
|
|
|
|
needRefresh: [needRefresh, setNeedRefresh],
|
|
|
|
|
updateServiceWorker,
|
|
|
|
|
} = useRegisterSW({
|
|
|
|
|
onRegistered(r) {
|
|
|
|
|
r &&
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
console.log('Checking for sw update, onRegistered', `__BUILD_DATE__`, `__APP_VERSION__`);
|
|
|
|
|
r.update();
|
|
|
|
|
|
|
|
|
|
setInterval(() => {
|
|
|
|
|
r.update();
|
|
|
|
|
}, 1000 * 60 * 60 * 8);
|
|
|
|
|
}, 1000 * 3);
|
|
|
|
|
},
|
|
|
|
|
onRegisteredSW(swUrl, r) {
|
|
|
|
|
// console.log(`Service Worker at: ${swUrl}`);
|
|
|
|
|
// @ts-expect-error just ignore
|
|
|
|
|
// if (reloadSW === 'true') {
|
|
|
|
|
r &&
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
console.log('Checking for sw update, ', `__BUILD_DATE__`, `__APP_VERSION__`);
|
|
|
|
|
console.log('Checking for sw update, onRegisteredSW', `__BUILD_DATE__`, `__APP_VERSION__`);
|
|
|
|
|
r.update();
|
|
|
|
|
|
|
|
|
|
setInterval(() => {
|
|
|
|
|
r.update();
|
|
|
|
|
}, 1000 * 60 * 60 * 8);
|
|
|
|
|
}, 1000 * 3);
|
|
|
|
|
// } else {
|
|
|
|
|
// eslint-disable-next-line prefer-template
|
|
|
|
|
// console.log('SW Registered: ' + r);
|
|
|
|
|
// }
|
|
|
|
|
},
|
|
|
|
|
onRegisterError(error) {
|
|
|
|
|
console.log('SW registration error', error);
|
|
|
|
@ -43,9 +47,9 @@ function ReloadPrompt() {
|
|
|
|
|
return (
|
|
|
|
|
<>
|
|
|
|
|
{/* {offlineReady && (<span>{APP_VERSION}</span>) } */}
|
|
|
|
|
{needRefresh && (
|
|
|
|
|
<a className=' text-sky-600 px-2' onClick={() => updateServiceWorker(true)}>
|
|
|
|
|
有新版本~点击更新🚀
|
|
|
|
|
{ (force || needRefresh) && (
|
|
|
|
|
<a className=' text-sky-600 pr-2' onClick={() => updateServiceWorker(true)}>
|
|
|
|
|
系统更新{needRefresh && '🚀'}
|
|
|
|
|
</a>
|
|
|
|
|
)}
|
|
|
|
|
</>
|
|
|
|
|