diff --git a/src/components/Navbar.tsx b/src/components/Navbar.tsx index b743f52..3a5fd4c 100644 --- a/src/components/Navbar.tsx +++ b/src/components/Navbar.tsx @@ -39,22 +39,24 @@ export default function Navbar() { // const tag = list.done.find((e)=> e.url === location.pathname) const [registration, setRegistration] = useState(null); + const [updateAvailable, setUpdateAvailable] = useState(false); useEffect(() => { - // Check if service worker is supported if ('serviceWorker' in navigator) { - // Register the service worker navigator.serviceWorker.register('/sw.js').then((reg) => { setRegistration(reg); + + reg.addEventListener('controllerchange', () => { + setUpdateAvailable(true); + }); }); } }, []); const updateServiceWorker = () => { if (registration) { - registration.update(); - } else { - console.log('无更新'); + registration.update() + setUpdateAvailable(false) } }; @@ -83,14 +85,14 @@ export default function Navbar() { } */} {/* */} - {registration? + {updateAvailable&&
{/*
有更新可用!
*/}
有更新:v0.4.3
-
:'' + } {/*