diff --git a/AppImage/ProxMenux-1.2.3.AppImage b/AppImage/ProxMenux-1.2.3.AppImage index 5aaacf21..66283868 100755 Binary files a/AppImage/ProxMenux-1.2.3.AppImage and b/AppImage/ProxMenux-1.2.3.AppImage differ diff --git a/AppImage/ProxMenux-Monitor.AppImage.sha256 b/AppImage/ProxMenux-Monitor.AppImage.sha256 index ad1abc7d..a894706c 100644 --- a/AppImage/ProxMenux-Monitor.AppImage.sha256 +++ b/AppImage/ProxMenux-Monitor.AppImage.sha256 @@ -1 +1 @@ -7b5dd3ff6fe70a190caf00d1ce5198dfe1917af53d01ab4fd1a3908f3204c0ff ProxMenux-1.2.3.AppImage +b6c602eb3bc056e8d8baddab98cf87d3897b8ff974395c2a32e28cf89e0238be ProxMenux-1.2.3.AppImage diff --git a/AppImage/components/pwa-register.tsx b/AppImage/components/pwa-register.tsx index 4af78246..94196a59 100644 --- a/AppImage/components/pwa-register.tsx +++ b/AppImage/components/pwa-register.tsx @@ -12,63 +12,27 @@ import { useEffect } from "react" // PWA-installability check from no-to-yes. // // Mounted from app/layout.tsx so it runs on every route. -// -// On every `visibilitychange` back to visible we call -// `registration.update()`. Mobile browsers (Brave / Firefox -// Android/iOS) are aggressive about deferring the SW's -// scheduled 24h `sw.js` re-check to save battery, which -// stranded users on the pre-v2 SW after the Cache Storage -// fix shipped — they saw the dashboard freeze until they -// force-stopped the browser. Forcing an `update()` on every -// return-to-foreground brings the SW check inline with -// user attention so future SW_VERSION bumps propagate at -// the first regreso a la pestaña instead of hours later. // =========================================================== export function PwaRegister() { useEffect(() => { if (typeof window === "undefined") return if (!("serviceWorker" in navigator)) return - - let registration: ServiceWorkerRegistration | null = null - + // Wait for the load event to avoid competing with the + // initial render — the SW registration is not on the + // critical render path. const register = () => { navigator.serviceWorker .register("/sw.js", { scope: "/" }) - .then((reg) => { - registration = reg - }) .catch((err) => { // Surface the failure only in DevTools — silent in prod. console.warn("[pwa] service worker registration failed:", err) }) } - - const onVisible = () => { - if (document.visibilityState !== "visible") return - // Prefer the captured registration from the initial register() - // call; fall back to `getRegistration()` in case that promise - // hadn't resolved yet on the first visibility change. - if (registration) { - registration.update().catch(() => {}) - } else { - navigator.serviceWorker - .getRegistration() - .then((reg) => reg?.update().catch(() => {})) - .catch(() => {}) - } - } - if (document.readyState === "complete") { register() } else { window.addEventListener("load", register, { once: true }) - } - - document.addEventListener("visibilitychange", onVisible) - - return () => { - window.removeEventListener("load", register) - document.removeEventListener("visibilitychange", onVisible) + return () => window.removeEventListener("load", register) } }, []) return null diff --git a/AppImage/public/sw.js b/AppImage/public/sw.js index 2e1d5c9e..324873bf 100644 --- a/AppImage/public/sw.js +++ b/AppImage/public/sw.js @@ -8,14 +8,12 @@ // so we do NOT cache pages or API responses — caching them // would only cause stale-data bugs after an AppImage update. // -// The install / activate handlers wipe every cache in Cache -// Storage (no allow-list) so stale entries from any previous -// Monitor version — including ones that shared this SW's -// version name — cannot survive an upgrade and haunt the -// dashboard as frozen `/api/*` responses. +// The install / activate handlers clean up old SW caches from +// previous Monitor versions so a beta-to-stable upgrade never +// strands the browser on a cached old shell. // ========================================================== -const SW_VERSION = 'proxmenux-monitor-v2'; +const SW_VERSION = 'proxmenux-monitor-v1'; self.addEventListener('install', (event) => { // Take over as soon as installed; no skipWaiting handshake. @@ -24,19 +22,12 @@ self.addEventListener('install', (event) => { self.addEventListener('activate', (event) => { event.waitUntil((async () => { - // Scorched earth: wipe EVERY cache, regardless of name. This - // SW never writes to Cache Storage, so nothing here should - // ever be authoritative. The previous version kept caches - // that matched SW_VERSION exactly, which stranded old cached - // /api/* responses across upgrades and manifested as a - // dashboard that never refreshed until the user manually - // cleared Cache Storage from DevTools. - try { - const names = await caches.keys(); - await Promise.all(names.map((n) => caches.delete(n))); - } catch (_) { - // caches API unavailable — nothing to clean. - } + // Wipe any cache name that isn't ours — survives renames / + // version bumps without piling up stale entries. + const names = await caches.keys(); + await Promise.all( + names.filter((n) => n !== SW_VERSION).map((n) => caches.delete(n)) + ); await self.clients.claim(); })()); });