mirror of
https://github.com/woodchen-ink/nezha-dash-v1.git
synced 2025-07-18 09:31:55 +08:00
fix: remove pwa deps
This commit is contained in:
parent
73cc1b64b9
commit
396133893e
@ -6,7 +6,6 @@ import Server from "./pages/Server";
|
||||
import ServerDetail from "./pages/ServerDetail";
|
||||
import NotFound from "./pages/NotFound";
|
||||
import ErrorPage from "./pages/ErrorPage";
|
||||
import ReloadPrompt from "./components/ReloadPrompt";
|
||||
|
||||
const App: React.FC = () => {
|
||||
return (
|
||||
@ -21,7 +20,6 @@ const App: React.FC = () => {
|
||||
<Route path="*" element={<NotFound />} />
|
||||
</Routes>
|
||||
<Footer />
|
||||
<ReloadPrompt />
|
||||
</main>
|
||||
</div>
|
||||
</Router>
|
||||
|
@ -1,49 +0,0 @@
|
||||
import { useRegisterSW } from "virtual:pwa-register/react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { toast } from "sonner";
|
||||
|
||||
function ReloadPrompt() {
|
||||
const { t } = useTranslation();
|
||||
|
||||
const {
|
||||
needRefresh: [needRefresh, setNeedRefresh],
|
||||
updateServiceWorker,
|
||||
} = useRegisterSW({
|
||||
onRegisteredSW(swUrl) {
|
||||
console.log(
|
||||
`SW Registered: ${swUrl} (Version: ${import.meta.env.VITE_GIT_HASH})`,
|
||||
);
|
||||
},
|
||||
onRegisterError(error) {
|
||||
console.log("SW registration error", error);
|
||||
},
|
||||
onOfflineReady() {
|
||||
toast.success(t("pwa.offlineReady"));
|
||||
},
|
||||
});
|
||||
|
||||
const close = () => {
|
||||
setNeedRefresh(false);
|
||||
};
|
||||
|
||||
const update = () => {
|
||||
updateServiceWorker(true);
|
||||
};
|
||||
|
||||
if (!needRefresh) {
|
||||
return null;
|
||||
}
|
||||
|
||||
toast.message(`${t("pwa.newContent")} (${import.meta.env.VITE_GIT_HASH})`, {
|
||||
action: {
|
||||
label: t("pwa.reload"),
|
||||
onClick: () => update(),
|
||||
},
|
||||
onDismiss: close,
|
||||
duration: Infinity,
|
||||
});
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
export default ReloadPrompt;
|
27
src/vite-env.d.ts
vendored
27
src/vite-env.d.ts
vendored
@ -1,27 +0,0 @@
|
||||
/// <reference types="vite/client" />
|
||||
|
||||
declare module "virtual:pwa-register/react" {
|
||||
import type { Dispatch, SetStateAction } from "react";
|
||||
|
||||
export interface RegisterSWOptions {
|
||||
immediate?: boolean;
|
||||
onNeedRefresh?: () => void;
|
||||
onOfflineReady?: () => void;
|
||||
onRegistered?: (
|
||||
registration: ServiceWorkerRegistration | undefined,
|
||||
) => void;
|
||||
onRegisteredSW?: (
|
||||
swScriptUrl: string,
|
||||
registration: ServiceWorkerRegistration | undefined,
|
||||
) => void;
|
||||
onRegisterError?: (error) => void;
|
||||
}
|
||||
|
||||
export interface RegisterSWHook {
|
||||
needRefresh: [boolean, Dispatch<SetStateAction<boolean>>];
|
||||
offlineReady: [boolean, Dispatch<SetStateAction<boolean>>];
|
||||
updateServiceWorker: (reloadPage?: boolean) => Promise<void>;
|
||||
}
|
||||
|
||||
export function useRegisterSW(options?: RegisterSWOptions): RegisterSWHook;
|
||||
}
|
@ -19,9 +19,7 @@ export default defineConfig({
|
||||
define: {
|
||||
"import.meta.env.VITE_GIT_HASH": JSON.stringify(getGitHash()),
|
||||
},
|
||||
plugins: [
|
||||
react(),
|
||||
],
|
||||
plugins: [react()],
|
||||
resolve: {
|
||||
alias: {
|
||||
"@": path.resolve(__dirname, "./src"),
|
||||
|
Loading…
x
Reference in New Issue
Block a user