chore: pwa update prompt
This commit is contained in:
parent
1566c0ffcb
commit
022c9d1eac
@ -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
10
src/pwa.ts
Normal 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
8
src/vite-env.d.ts
vendored
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user