mirror of
https://github.com/sussy-code/smov.git
synced 2024-12-20 14:37:43 +01:00
cache busting pwa
This commit is contained in:
parent
63b9adf7d8
commit
444c751b78
6 changed files with 715 additions and 588 deletions
|
@ -33,6 +33,7 @@
|
||||||
"dev": "vite",
|
"dev": "vite",
|
||||||
"build": "vite build",
|
"build": "vite build",
|
||||||
"test": "vitest run",
|
"test": "vitest run",
|
||||||
|
"serve": "serve",
|
||||||
"lint": "eslint --ext .tsx,.ts src",
|
"lint": "eslint --ext .tsx,.ts src",
|
||||||
"lint:fix": "eslint --fix --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"
|
"lint:report": "eslint --ext .tsx,.ts --output-file eslint_report.json --format json src"
|
||||||
|
@ -80,6 +81,7 @@
|
||||||
"postcss": "^8.4.20",
|
"postcss": "^8.4.20",
|
||||||
"prettier": "^2.5.1",
|
"prettier": "^2.5.1",
|
||||||
"prettier-plugin-tailwindcss": "^0.1.7",
|
"prettier-plugin-tailwindcss": "^0.1.7",
|
||||||
|
"serve": "^14.2.0",
|
||||||
"tailwind-scrollbar": "^2.0.1",
|
"tailwind-scrollbar": "^2.0.1",
|
||||||
"tailwindcss": "^3.2.4",
|
"tailwindcss": "^3.2.4",
|
||||||
"typescript": "^4.6.4",
|
"typescript": "^4.6.4",
|
||||||
|
@ -87,6 +89,7 @@
|
||||||
"vite-plugin-checker": "^0.5.6",
|
"vite-plugin-checker": "^0.5.6",
|
||||||
"vite-plugin-package-version": "^1.0.2",
|
"vite-plugin-package-version": "^1.0.2",
|
||||||
"vite-plugin-pwa": "^0.14.4",
|
"vite-plugin-pwa": "^0.14.4",
|
||||||
"vitest": "^0.28.5"
|
"vitest": "^0.28.5",
|
||||||
|
"workbox-window": "^6.5.4"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
4
serve.json
Normal file
4
serve.json
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
{
|
||||||
|
"public": "dist",
|
||||||
|
"rewrites": [{ "source": "*", "destination": "/index.html" }]
|
||||||
|
}
|
|
@ -3,6 +3,7 @@ import ReactDOM from "react-dom";
|
||||||
import { BrowserRouter, HashRouter } from "react-router-dom";
|
import { BrowserRouter, HashRouter } from "react-router-dom";
|
||||||
import { ErrorBoundary } from "@/components/layout/ErrorBoundary";
|
import { ErrorBoundary } from "@/components/layout/ErrorBoundary";
|
||||||
import { conf } from "@/setup/config";
|
import { conf } from "@/setup/config";
|
||||||
|
import { registerSW } from "virtual:pwa-register";
|
||||||
|
|
||||||
import App from "@/setup/App";
|
import App from "@/setup/App";
|
||||||
import "@/setup/ga";
|
import "@/setup/ga";
|
||||||
|
@ -19,6 +20,11 @@ if (key) {
|
||||||
(window as any).initMW(conf().PROXY_URLS, key);
|
(window as any).initMW(conf().PROXY_URLS, key);
|
||||||
}
|
}
|
||||||
initializeChromecast();
|
initializeChromecast();
|
||||||
|
registerSW({
|
||||||
|
onNeedRefresh() {
|
||||||
|
window.location.reload();
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
const LazyLoadedApp = React.lazy(async () => {
|
const LazyLoadedApp = React.lazy(async () => {
|
||||||
await initializeStores();
|
await initializeStores();
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
import { Redirect, Route, Switch } from "react-router-dom";
|
import { Redirect, Route, Switch } from "react-router-dom";
|
||||||
import { useRegisterSW } from "virtual:pwa-register/react";
|
|
||||||
import { BookmarkContextProvider } from "@/state/bookmark";
|
import { BookmarkContextProvider } from "@/state/bookmark";
|
||||||
import { WatchedContextProvider } from "@/state/watched";
|
import { WatchedContextProvider } from "@/state/watched";
|
||||||
|
|
||||||
|
@ -13,66 +12,12 @@ import { VideoTesterView } from "@/views/developer/VideoTesterView";
|
||||||
import { ProviderTesterView } from "@/views/developer/ProviderTesterView";
|
import { ProviderTesterView } from "@/views/developer/ProviderTesterView";
|
||||||
import { EmbedTesterView } from "@/views/developer/EmbedTesterView";
|
import { EmbedTesterView } from "@/views/developer/EmbedTesterView";
|
||||||
|
|
||||||
function ReloadPrompt() {
|
// TODO add "you are offline" status bar
|
||||||
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>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
function App() {
|
function App() {
|
||||||
return (
|
return (
|
||||||
<WatchedContextProvider>
|
<WatchedContextProvider>
|
||||||
<BookmarkContextProvider>
|
<BookmarkContextProvider>
|
||||||
<ReloadPrompt />
|
|
||||||
<Switch>
|
<Switch>
|
||||||
{/* functional routes */}
|
{/* functional routes */}
|
||||||
<Route exact path="/v2-migration" component={V2MigrationView} />
|
<Route exact path="/v2-migration" component={V2MigrationView} />
|
||||||
|
|
|
@ -11,8 +11,8 @@ export default defineConfig({
|
||||||
VitePWA({
|
VitePWA({
|
||||||
registerType: "autoUpdate",
|
registerType: "autoUpdate",
|
||||||
injectRegister: "inline",
|
injectRegister: "inline",
|
||||||
devOptions: {
|
workbox: {
|
||||||
enabled: true,
|
skipWaiting: true,
|
||||||
},
|
},
|
||||||
includeAssets: [
|
includeAssets: [
|
||||||
"favicon.ico",
|
"favicon.ico",
|
||||||
|
|
Loading…
Reference in a new issue