revert
This commit is contained in:
@@ -365,7 +365,7 @@
|
|||||||
var serviceWorkerVersion = '{{flutter_service_worker_version}}';
|
var serviceWorkerVersion = '{{flutter_service_worker_version}}';
|
||||||
var scriptLoaded = false;
|
var scriptLoaded = false;
|
||||||
|
|
||||||
function loadMainDartJs(isUpdate) {
|
function loadMainDartJs() {
|
||||||
console.log('Loading app...');
|
console.log('Loading app...');
|
||||||
if (scriptLoaded) {
|
if (scriptLoaded) {
|
||||||
return;
|
return;
|
||||||
@@ -380,17 +380,6 @@
|
|||||||
onEntrypointLoaded: function (engineInitializer) {
|
onEntrypointLoaded: function (engineInitializer) {
|
||||||
engineInitializer.initializeEngine().then(function (appRunner) {
|
engineInitializer.initializeEngine().then(function (appRunner) {
|
||||||
appRunner.runApp();
|
appRunner.runApp();
|
||||||
|
|
||||||
// --- NEW PROMPT LOCATION ---
|
|
||||||
if (isUpdate) {
|
|
||||||
// Only show prompt AFTER the old app (the one currently running) has loaded
|
|
||||||
console.log('New app version installed. Prompting for reload.');
|
|
||||||
if (confirm('A new version of the app is available. Refresh now to update?')) {
|
|
||||||
window.location.reload();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// ---------------------------
|
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -400,7 +389,7 @@
|
|||||||
function getCleanVersion(version) {
|
function getCleanVersion(version) {
|
||||||
return version.replace(/"/g, '');
|
return version.replace(/"/g, '');
|
||||||
}
|
}
|
||||||
|
|
||||||
if ('serviceWorker' in navigator) {
|
if ('serviceWorker' in navigator) {
|
||||||
var startLoad = new Date();
|
var startLoad = new Date();
|
||||||
// Service workers are supported. Use them.
|
// Service workers are supported. Use them.
|
||||||
@@ -410,16 +399,22 @@
|
|||||||
|
|
||||||
navigator.serviceWorker.register(serviceWorkerUrl)
|
navigator.serviceWorker.register(serviceWorkerUrl)
|
||||||
.then((reg) => {
|
.then((reg) => {
|
||||||
|
|
||||||
// Flag to track if this registration resulted in an update
|
|
||||||
let isUpdateInstallation = false;
|
|
||||||
|
|
||||||
function waitForActivation(serviceWorker) {
|
function waitForActivation(serviceWorker) {
|
||||||
serviceWorker.addEventListener('statechange', () => {
|
serviceWorker.addEventListener('statechange', () => {
|
||||||
if (serviceWorker.state == 'activated') {
|
if (serviceWorker.state == 'activated') {
|
||||||
console.log('Installed new service worker.');
|
console.log('Installed new service worker.');
|
||||||
// Pass the update flag to loadMainDartJs
|
loadMainDartJs();
|
||||||
loadMainDartJs(isUpdateInstallation);
|
// Optional: Prompt user to reload for the new version to take effect
|
||||||
|
// The user is currently running the OLD cached version of the app.
|
||||||
|
// This prompt is generally preferred over the previous logic.
|
||||||
|
if (navigator.serviceWorker.controller) {
|
||||||
|
// Only prompt if this isn't the first time loading.
|
||||||
|
console.log('New app version activated. Prompting for reload.');
|
||||||
|
// You can replace this confirm with a better UI notification.
|
||||||
|
if (confirm('A new version of the app is available. Refresh now to update?')) {
|
||||||
|
window.location.reload();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -430,27 +425,26 @@
|
|||||||
console.log('Active Service Worker Version: ' + (currentSWVersion || 'None'));
|
console.log('Active Service Worker Version: ' + (currentSWVersion || 'None'));
|
||||||
const isMatch = currentSWVersion === cleanServiceWorkerVersion;
|
const isMatch = currentSWVersion === cleanServiceWorkerVersion;
|
||||||
console.log('Latest Service Worker Installed: ' + isMatch);
|
console.log('Latest Service Worker Installed: ' + isMatch);
|
||||||
|
|
||||||
if (!reg.active && (reg.installing || reg.waiting)) {
|
if (!reg.active && (reg.installing || reg.waiting)) {
|
||||||
// First time load: wait for activation.
|
// First time load: wait for activation.
|
||||||
console.log('No Service Worker Available - Installing New Service Worker.');
|
console.log('No Service Worker Available - Installing New Service Worker.');
|
||||||
waitForActivation(reg.installing || reg.waiting);
|
waitForActivation(reg.installing || reg.waiting);
|
||||||
} else if (!isMatch) {
|
} else if (!isMatch) {
|
||||||
// New version available: force update.
|
// New version available: force update.
|
||||||
isUpdateInstallation = true; // Set flag when update is initiated
|
|
||||||
console.log('New service worker available. Updating and waiting for activation.');
|
console.log('New service worker available. Updating and waiting for activation.');
|
||||||
reg.update();
|
reg.update();
|
||||||
waitForActivation(reg.installing);
|
waitForActivation(reg.installing);
|
||||||
} else {
|
} else {
|
||||||
// Existing service worker is still good.
|
// Existing service worker is still good.
|
||||||
console.log('Service Worker up-to-date, Loading app.');
|
console.log('Service Worker up-to-date, Loading app.');
|
||||||
loadMainDartJs(false); // No update, pass false
|
loadMainDartJs();
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
console.error('Service Worker registration failed:', error);
|
console.error('Service Worker registration failed:', error);
|
||||||
loadMainDartJs(false); // Fallback if registration fails completely
|
loadMainDartJs(); // Fallback if registration fails completely
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
// If service worker doesn't succeed in a reasonable amount of time,
|
// If service worker doesn't succeed in a reasonable amount of time,
|
||||||
@@ -460,7 +454,7 @@
|
|||||||
console.warn(
|
console.warn(
|
||||||
'Failed to load app from a service worker. Falling back to plain <script> tag.',
|
'Failed to load app from a service worker. Falling back to plain <script> tag.',
|
||||||
);
|
);
|
||||||
loadMainDartJs(false);
|
loadMainDartJs();
|
||||||
}
|
}
|
||||||
}, 500);
|
}, 500);
|
||||||
var finishLoad = new Date();
|
var finishLoad = new Date();
|
||||||
@@ -471,12 +465,13 @@
|
|||||||
else {
|
else {
|
||||||
// Service workers not supported. Just drop the <script> tag.
|
// Service workers not supported. Just drop the <script> tag.
|
||||||
console.log('Service Workers Not Supported. Loading app directly.');
|
console.log('Service Workers Not Supported. Loading app directly.');
|
||||||
loadMainDartJs(false);
|
loadMainDartJs();
|
||||||
}
|
}
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<script id="pdfjs-lib" src="//cdnjs.cloudflare.com/ajax/libs/pdf.js/3.2.146/pdf.min.js" defer=""></script>
|
<script id="pdfjs-lib" src="//cdnjs.cloudflare.com/ajax/libs/pdf.js/3.2.146/pdf.min.js" defer=""></script>
|
||||||
<script id="pdfjs-worker" type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/pdf.js/3.2.146/pdf.worker.min.js" defer=""></script>
|
<script id="pdfjs-worker" type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/pdf.js/3.2.146/pdf.worker.min.js" defer=""></script>
|
||||||
<!--------------------->
|
<!--------------------->
|
||||||
|
|||||||
Reference in New Issue
Block a user