chore: pwa update prompt
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
鲁树人 2023-10-11 23:06:09 +01:00
parent 558fa12dd8
commit 7b3e81dd2a
3 changed files with 20 additions and 1 deletions

View File

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