1
0
Fork 0
mirror of https://github.com/sussy-code/smov.git synced 2024-12-29 16:07:40 +01:00

cache busting pwa

This commit is contained in:
mrjvs 2023-02-24 20:12:20 +01:00
parent 63b9adf7d8
commit 444c751b78
6 changed files with 715 additions and 588 deletions

View file

@ -33,6 +33,7 @@
"dev": "vite",
"build": "vite build",
"test": "vitest run",
"serve": "serve",
"lint": "eslint --ext .tsx,.ts src",
"lint:fix": "eslint --fix --ext .tsx,.ts src",
"lint:report": "eslint --ext .tsx,.ts --output-file eslint_report.json --format json src"
@ -80,6 +81,7 @@
"postcss": "^8.4.20",
"prettier": "^2.5.1",
"prettier-plugin-tailwindcss": "^0.1.7",
"serve": "^14.2.0",
"tailwind-scrollbar": "^2.0.1",
"tailwindcss": "^3.2.4",
"typescript": "^4.6.4",
@ -87,6 +89,7 @@
"vite-plugin-checker": "^0.5.6",
"vite-plugin-package-version": "^1.0.2",
"vite-plugin-pwa": "^0.14.4",
"vitest": "^0.28.5"
"vitest": "^0.28.5",
"workbox-window": "^6.5.4"
}
}

4
serve.json Normal file
View file

@ -0,0 +1,4 @@
{
"public": "dist",
"rewrites": [{ "source": "*", "destination": "/index.html" }]
}

View file

@ -3,6 +3,7 @@ import ReactDOM from "react-dom";
import { BrowserRouter, HashRouter } from "react-router-dom";
import { ErrorBoundary } from "@/components/layout/ErrorBoundary";
import { conf } from "@/setup/config";
import { registerSW } from "virtual:pwa-register";
import App from "@/setup/App";
import "@/setup/ga";
@ -19,6 +20,11 @@ if (key) {
(window as any).initMW(conf().PROXY_URLS, key);
}
initializeChromecast();
registerSW({
onNeedRefresh() {
window.location.reload();
},
});
const LazyLoadedApp = React.lazy(async () => {
await initializeStores();

View file

@ -1,5 +1,4 @@
import { Redirect, Route, Switch } from "react-router-dom";
import { useRegisterSW } from "virtual:pwa-register/react";
import { BookmarkContextProvider } from "@/state/bookmark";
import { WatchedContextProvider } from "@/state/watched";
@ -13,66 +12,12 @@ import { VideoTesterView } from "@/views/developer/VideoTesterView";
import { ProviderTesterView } from "@/views/developer/ProviderTesterView";
import { EmbedTesterView } from "@/views/developer/EmbedTesterView";
function ReloadPrompt() {
const {
offlineReady: [offlineReady, setOfflineReady],
needRefresh: [needRefresh, setNeedRefresh],
updateServiceWorker,
} = useRegisterSW({
onRegistered(r) {
// eslint-disable-next-line prefer-template
console.log("SW Registered: " + r);
},
onRegisterError(error) {
console.log("SW registration error", error);
},
});
const close = () => {
setOfflineReady(false);
setNeedRefresh(false);
};
return (
<div className="ReloadPrompt-container">
{(offlineReady || needRefresh) && (
<div className="ReloadPrompt-toast">
<div className="ReloadPrompt-message">
{offlineReady ? (
<span>App ready to work offline</span>
) : (
<span>
New content available, click on reload button to update.
</span>
)}
</div>
{needRefresh && (
<button
type="button"
className="ReloadPrompt-toast-button"
onClick={() => updateServiceWorker(true)}
>
Reload
</button>
)}
<button
type="button"
className="ReloadPrompt-toast-button"
onClick={() => close()}
>
Close
</button>
</div>
)}
</div>
);
}
// TODO add "you are offline" status bar
function App() {
return (
<WatchedContextProvider>
<BookmarkContextProvider>
<ReloadPrompt />
<Switch>
{/* functional routes */}
<Route exact path="/v2-migration" component={V2MigrationView} />

View file

@ -11,8 +11,8 @@ export default defineConfig({
VitePWA({
registerType: "autoUpdate",
injectRegister: "inline",
devOptions: {
enabled: true,
workbox: {
skipWaiting: true,
},
includeAssets: [
"favicon.ico",

1227
yarn.lock

File diff suppressed because it is too large Load diff