From 8246e6dd854c7b27711717a22e5385f84e8bcf72 Mon Sep 17 00:00:00 2001 From: YuzeTT Date: Thu, 16 Nov 2023 18:34:44 +0800 Subject: [PATCH] chore: add update button --- src/components/Navbar.tsx | 38 +++++++++++++++++++++++++++++++++----- 1 file changed, 33 insertions(+), 5 deletions(-) diff --git a/src/components/Navbar.tsx b/src/components/Navbar.tsx index 8d7b170..b743f52 100644 --- a/src/components/Navbar.tsx +++ b/src/components/Navbar.tsx @@ -3,6 +3,8 @@ // import list from '../utils/router'; // import { useState } from 'react' // import { Alert } from 'antd'; +import { useEffect, useState } from "react"; + import { motion } from "framer-motion" import isVip from "../utils/isVip" @@ -35,6 +37,27 @@ export default function Navbar() { // const [showText , setShowText] = useState(false) // const location = useLocation() // const tag = list.done.find((e)=> e.url === location.pathname) + + const [registration, setRegistration] = useState(null); + + useEffect(() => { + // Check if service worker is supported + if ('serviceWorker' in navigator) { + // Register the service worker + navigator.serviceWorker.register('/sw.js').then((reg) => { + setRegistration(reg); + }); + } + }, []); + + const updateServiceWorker = () => { + if (registration) { + registration.update(); + } else { + console.log('无更新'); + } + }; + return (
@@ -60,12 +83,17 @@ export default function Navbar() { } */} {/* */} - + {registration? +
+
+ {/*
有更新可用!
*/} +
有更新:v0.4.3
+
+ +
:'' + } + {/*
-
- {/* -