From 482dde9a72f18c9b9550e6d89f0350e290bdcf4b Mon Sep 17 00:00:00 2001 From: Yasien Mac Mini Date: Tue, 2 Jun 2026 10:36:42 +0200 Subject: [PATCH] service worker v4 --- mih_ui/web/flutter_bootstrap.js | 49 ++------------------------------- mih_ui/web/index.html | 40 +++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 47 deletions(-) diff --git a/mih_ui/web/flutter_bootstrap.js b/mih_ui/web/flutter_bootstrap.js index e65d7f16..3729212a 100644 --- a/mih_ui/web/flutter_bootstrap.js +++ b/mih_ui/web/flutter_bootstrap.js @@ -1,50 +1,5 @@ {{flutter_js}} {{flutter_build_config}} -const serviceWorkerVersion = '{{flutter_service_worker_version}}'; - -// 1. Let Flutter handle the service worker registration cleanly via its native loader -_flutter.loader.load({ - serviceWorkerSettings: { - serviceWorkerVersion: serviceWorkerVersion - } -}); - -// 2. Safely monitor the registration generated by Flutter without double-registering -if ('serviceWorker' in navigator) { - navigator.serviceWorker.ready.then((reg) => { - // If an updated worker is already waiting in the background - if (reg.waiting) { - showUpdatePrompt(reg); - } - - // Listen for new updates found while the user has the app open - reg.addEventListener('updatefound', () => { - const newWorker = reg.installing; - if (newWorker) { - newWorker.addEventListener('statechange', () => { - if (newWorker.state === 'installed' && navigator.serviceWorker.controller) { - showUpdatePrompt(reg); - } - }); - } - }); - }); - - // Guard against infinite reload loops when the controller shifts - let refreshing = false; - navigator.serviceWorker.addEventListener('controllerchange', () => { - if (!refreshing) { - refreshing = true; - window.location.reload(); - } - }); -} - -function showUpdatePrompt(reg) { - if (confirm('A new version of MIH is available. Refresh now to update?')) { - reg.unregister().then(function () { - window.location.reload(); // Unregister and reload to force clear the browser's cache - }); - } -} +// This is the default loader that Flutter 3.24 expects +_flutter.loader.load(); diff --git a/mih_ui/web/index.html b/mih_ui/web/index.html index 5fa4cd68..fad795ab 100644 --- a/mih_ui/web/index.html +++ b/mih_ui/web/index.html @@ -257,6 +257,46 @@ +