chore: pwa update prompt

This commit is contained in:
鲁树人 2023-10-11 23:06:09 +01:00
parent 1566c0ffcb
commit 022c9d1eac
3 changed files with 20 additions and 1 deletions

View File

@ -1,3 +1,4 @@
import './pwa';
import React from 'react';
import ReactDOM from 'react-dom/client';
@ -13,5 +14,5 @@ SyntaxHighlighter.registerLanguage('bash', hljsSyntaxBash);
ReactDOM.createRoot(document.getElementById('root') as HTMLElement).render(
<React.StrictMode>
<AppRoot />
</React.StrictMode>
</React.StrictMode>,
);

10
src/pwa.ts Normal file
View File

@ -0,0 +1,10 @@
import { registerSW } from 'virtual:pwa-register';
const updateSW = registerSW({
onNeedRefresh() {
if (confirm('应用程序已更新,是否刷新?')) {
updateSW();
}
},
onOfflineReady() {},
});

8
src/vite-env.d.ts vendored
View File

@ -1 +1,9 @@
/// <reference types="vite/client" />
module 'virtual:pwa-register' {
/**
* See: {@link https://vite-pwa-org.netlify.app/guide/prompt-for-update.html}
*/
// eslint-disable-next-line @typescript-eslint/no-unused-vars
declare function registerSW(opts: unknown): () => void;
}