diff --git a/www/js/app.js b/www/js/app.js index b3fe577a0..8b3ee5466 100644 --- a/www/js/app.js +++ b/www/js/app.js @@ -834,10 +834,10 @@ function initServiceWorkerMessaging () { } }; // Send the init message to the ServiceWorker - if (navigator.serviceWorker.controller) { + if (navigator.serviceWorker.controller) { console.log('Initializing SW messaging...'); - navigator.serviceWorker.controller.postMessage({ - action: 'init' + navigator.serviceWorker.controller.postMessage({ + action: 'init' }); } else if (serviceWorkerRegistration) { // If this is the first time we are initiating the SW, allow Promises to complete by delaying potential reload till next tick @@ -848,9 +848,9 @@ function initServiceWorkerMessaging () { console.error('The Service Worker is not controlling the current page! We have to reload.'); // Turn off failsafe, as this is a controlled reboot settingsStore.setItem('lastPageLoad', 'rebooting', Infinity); - window.location.reload(); - } + window.location.reload(); } +} /** * Sets the given injection mode. @@ -907,7 +907,7 @@ function setContentInjectionMode (value) { // We should empty it and turn it off to prevent unnecessary space usage if ('caches' in window && isMessageChannelAvailable()) { if (isServiceWorkerAvailable() && navigator.serviceWorker.controller) { - var channel = new MessageChannel(); + var channel = new MessageChannel(); navigator.serviceWorker.controller.postMessage({ action: { assetsCache: 'disable' } }, [channel.port2]); @@ -1301,7 +1301,7 @@ function setLocalArchiveFromArchiveList () { function resetCssCache () { // Reset the cssCache if an archive is loaded if (selectedArchive) selectedArchive.cssCache = new Map(); - } +} let webKitFileList = null @@ -1349,7 +1349,7 @@ function displayFileSelect () { localStorage.setItem('previousZimFileName', e.target.value); if (params.isFileSystemApiSupported) { return abstractFilesystemAccess.getSelectedZimFromCache(e.target.value).then(function (files) { - setLocalArchiveFromFileList(files); + setLocalArchiveFromFileList(files); }).catch(function (err) { console.error(err); return uiUtil.systemAlert(translateUI.t('dialog-fielhandle-fail-message') || 'We were unable to retrieve a file handle for the selected archive. Please pick the file or folder again.', @@ -1884,30 +1884,30 @@ function readArticle (dirEntry) { * @param {Event} event The event object of the message channel */ function handleMessageChannelMessage (event) { - // We received a message from the ServiceWorker - // The ServiceWorker asks for some content - var title = event.data.title; - var messagePort = event.ports[0]; - var readFile = function (dirEntry) { - if (dirEntry === null) { - console.error('Title ' + title + ' not found in archive.'); - messagePort.postMessage({ action: 'giveContent', title: title, content: '' }); - } else if (dirEntry.isRedirect) { - var redirectPath = dirEntry.redirectPath; - // Ask the ServiceWorker to send an HTTP redirect to the browser. - // We could send the final content directly, but it is necessary to let the browser know in which directory it ends up. - // Else, if the redirect URL is in a different directory than the original URL, - // the relative links in the HTML content would fail. See #312 - messagePort.postMessage({ action: 'sendRedirect', title: title, redirectUrl: redirectPath }); - } else { - var message = { action: 'giveContent', title: title, content: dirEntry.content, mimetype: dirEntry.mimetype }; - messagePort.postMessage(message); - } - }; - selectedArchive.callLibzimWorker({ action: 'getEntryByPath', path: title, follow: false }).then(readFile).catch(function () { - messagePort.postMessage({ action: 'giveContent', title: title, content: new Uint8Array() }); - }); + // We received a message from the ServiceWorker + // The ServiceWorker asks for some content + var title = event.data.title; + var messagePort = event.ports[0]; + var readFile = function (dirEntry) { + if (dirEntry === null) { + console.error('Title ' + title + ' not found in archive.'); + messagePort.postMessage({ action: 'giveContent', title: title, content: '' }); + } else if (dirEntry.isRedirect) { + var redirectPath = dirEntry.redirectPath; + // Ask the ServiceWorker to send an HTTP redirect to the browser. + // We could send the final content directly, but it is necessary to let the browser know in which directory it ends up. + // Else, if the redirect URL is in a different directory than the original URL, + // the relative links in the HTML content would fail. See #312 + messagePort.postMessage({ action: 'sendRedirect', title: title, redirectUrl: redirectPath }); + } else { + var message = { action: 'giveContent', title: title, content: dirEntry.content, mimetype: dirEntry.mimetype }; + messagePort.postMessage(message); } + }; + selectedArchive.callLibzimWorker({ action: 'getEntryByPath', path: title, follow: false }).then(readFile).catch(function () { + messagePort.postMessage({ action: 'giveContent', title: title, content: new Uint8Array() }); + }); +} // Compile some regular expressions needed to modify links // Pattern to find a ZIM URL (with its namespace) - see https://wiki.openzim.org/wiki/ZIM_file_format#Namespaces