update pdf plugin

This commit is contained in:
2024-10-02 15:34:58 +02:00
parent fe4d3d1fd6
commit 4beb76b9dc

View File

@@ -96,6 +96,10 @@
document.body.style.background = "transparent"; document.body.style.background = "transparent";
} }
</script> </script>
<!-- Splash screen -->
<!-- <script>
var dartPdfJsBaseUrl = "https://cdnjs.cloudflare.com/ajax/libs/pdf.js/3.2.146/";
</script> -->
<!---------------------> <!--------------------->
</head> </head>
@@ -141,119 +145,119 @@
}); });
</script> --> </script> -->
<script defer> <script defer>
var serviceWorkerVersion = '{{flutter_service_worker_version}}'; var serviceWorkerVersion = '{{flutter_service_worker_version}}';
var scriptLoaded = false; var scriptLoaded = false;
function loadMainDartJs() { function loadMainDartJs() {
console.log('Loading app...'); console.log('Loading app...');
if (scriptLoaded) { if (scriptLoaded) {
return; return;
} }
scriptLoaded = true; scriptLoaded = true;
{{flutter_js}} {{flutter_js}}
{{flutter_build_config}} {{flutter_build_config}}
_flutter.loader.load({ _flutter.loader.load({
serviceWorker: { serviceWorker: {
serviceWorkerVersion: serviceWorkerVersion, serviceWorkerVersion: serviceWorkerVersion,
}, },
onEntrypointLoaded: function (engineInitializer) { onEntrypointLoaded: function (engineInitializer) {
engineInitializer.initializeEngine().then(function (appRunner) { engineInitializer.initializeEngine().then(function (appRunner) {
appRunner.runApp(); appRunner.runApp();
});
}
}); });
} }
});
}
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.
window.addEventListener('load', function () { window.addEventListener('load', function () {
// Wait for registration to finish before dropping the <script> tag. // Wait for registration to finish before dropping the <script> tag.
// Otherwise, the browser will load the script multiple times, // Otherwise, the browser will load the script multiple times,
// potentially different versions. // potentially different versions.
var serviceWorkerUrl = 'flutter_service_worker.js?v=' + serviceWorkerVersion; var serviceWorkerUrl = 'flutter_service_worker.js?v=' + serviceWorkerVersion;
navigator.serviceWorker.register(serviceWorkerUrl) navigator.serviceWorker.register(serviceWorkerUrl)
.then((reg) => { .then((reg) => {
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.');
loadMainDartJs(); loadMainDartJs();
} }
}); });
} }
console.log('Active Service Worker URL: ' + reg.active.scriptURL); console.log('Active Service Worker URL: ' + reg.active.scriptURL);
const currentSWVersion = reg.active.scriptURL.split("=")[1].replaceAll("%22", "");; const currentSWVersion = reg.active.scriptURL.split("=")[1].replaceAll("%22", "");;
console.log('Active Service Worker Version: ' + serviceWorkerVersion.replaceAll("\"", "")); console.log('Active Service Worker Version: ' + serviceWorkerVersion.replaceAll("\"", ""));
console.log('Latest Service Worker Version: ' + currentSWVersion); console.log('Latest Service Worker Version: ' + currentSWVersion);
const isMatch = currentSWVersion === serviceWorkerVersion.replaceAll("\"", ""); const isMatch = currentSWVersion === serviceWorkerVersion.replaceAll("\"", "");
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)) {
// No active web worker and we have installed or are installing // No active web worker and we have installed or are installing
// one for the first time. Simply wait for it to activate. // one for the first time. Simply wait for it to activate.
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) {
// When the app updates the serviceWorkerVersion changes, so we // When the app updates the serviceWorkerVersion changes, so we
// need to ask the service worker to update. // need to ask the service worker to update.
console.log('New service worker available.'); console.log('New service worker available.');
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();
}
});
// If service worker doesn't succeed in a reasonable amount of time,
// fallback to plaint <script> tag.
setTimeout(() => {
if (!scriptLoaded) {
console.warn(
'Failed to load app from a service worker. Falling back to plain <script> tag.',
);
loadMainDartJs(); loadMainDartJs();
} }
}); }, 4000);
var finishLoad = new Date();
// If service worker doesn't succeed in a reasonable amount of time, var loadTime = (finishLoad.getTime() - startLoad.getTime());
// fallback to plaint <script> tag. console.log("Load Time: " + loadTime);
setTimeout(() => { });
if (!scriptLoaded) {
console.warn(
'Failed to load app from a service worker. Falling back to plain <script> tag.',
);
loadMainDartJs();
}
}, 4000);
var finishLoad = new Date();
var loadTime = (finishLoad.getTime() - startLoad.getTime());
console.log("Load Time: " + loadTime);
});
if (navigator.serviceWorker.state == 'activated') { if (navigator.serviceWorker.state == 'activated') {
console.log('Installed new service worker.'); console.log('Installed new service worker.');
loadMainDartJs(); loadMainDartJs();
// if there's an existing controller (previous Service Worker), show the prompt // if there's an existing controller (previous Service Worker), show the prompt
// you can tweak this and delay the notification once the page is load you can show a notification and ask for a new refresh // you can tweak this and delay the notification once the page is load you can show a notification and ask for a new refresh
if (navigator.serviceWorker.controller) { if (navigator.serviceWorker.controller) {
// you have a better UI here, reloading is not a great user experince here. // you have a better UI here, reloading is not a great user experince here.
const confirmed = alert('New version of the app is available. Refresh now'); const confirmed = alert('New version of the app is available. Refresh now');
if (confirmed == true) { if (confirmed == true) {
window.location.reload(); window.location.reload();
}
} }
} }
}
else {
// Service workers not supported. Just drop the <script> tag.
console.log('Service Not Supported.');
loadMainDartJs();
} }
} </script>
else {
// Service workers not supported. Just drop the <script> tag.
console.log('Service Not Supported.');
loadMainDartJs();
}
</script>
</body> </body>
<!-- File Picker & PDF viewer --> <!-- File Picker & PDF viewer -->
<script id="pdfjs-lib" src="//cdnjs.cloudflare.com/ajax/libs/pdf.js/2.11.338/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" <script id="pdfjs-worker" type="text/javascript"
src="//cdnjs.cloudflare.com/ajax/libs/pdf.js/2.11.338/pdf.worker.min.js" defer></script> src="//cdnjs.cloudflare.com/ajax/libs/pdf.js/3.2.146/pdf.worker.min.js" defer></script>
<!---------------------> <!--------------------->
</html> </html>