From 779db26ecce88c8cfa3f43d1d08fcf4d2c568dd9 Mon Sep 17 00:00:00 2001 From: RG Date: Mon, 13 Nov 2023 20:59:12 +0530 Subject: [PATCH 01/13] [ADD] ui & component logic for libzim wasm mode --- www/index.html | 6 ++++++ www/js/app.js | 5 +++++ www/js/init.js | 3 +++ 3 files changed, 14 insertions(+) diff --git a/www/index.html b/www/index.html index 51696221c..91d512141 100644 --- a/www/index.html +++ b/www/index.html @@ -694,6 +694,12 @@

Expert settings

Bypass AppCache (disables offline use of PWA!) +
+ +

Reset the app to default settings and erase all caches:

Reset the app to default settings and erase all caches:

diff --git a/www/js/app.js b/www/js/app.js index 62068bde3..25875d75d 100644 --- a/www/js/app.js +++ b/www/js/app.js @@ -34,6 +34,7 @@ import uiUtil from './lib/uiUtil.js'; import settingsStore from './lib/settingsStore.js'; import abstractFilesystemAccess from './lib/abstractFilesystemAccess.js'; import translateUI from './lib/translateUI.js'; +import { type } from 'jquery'; if (params.abort) { // If the app was loaded only to pass a message from the remote code, then we exit immediately @@ -57,7 +58,7 @@ const ASSETS_CACHE = 'kiwixjs-assetsCache'; var appstate = {}; /** - * @type ZIMArchive + * @type ZIMArchive | null */ var selectedArchive = null; @@ -475,8 +476,20 @@ document.getElementById('bypassAppCacheCheck').addEventListener('change', functi refreshCacheStatus(); }); -document.getElementById('libzimWasmModeToggle').addEventListener('change', function () { - settingsStore.setItem('libzimWasmMode', this.checked); +document.getElementById('libzimModeSelect').addEventListener('change', function (e) { + // console.log(settingsStore.getItem('libzimMode')); + settingsStore.setItem('libzimMode', e.target.value); +}); + +document.getElementById('testButtonToBeRemoved').addEventListener('click', function (e) { + console.log('clicked on libzimModeSelect', selectedArchive); + if (selectedArchive !== null) { + console.log('calling function getDirEntryByPath', selectedArchive.isReady()); + // selectedArchive.callLibzimWorker({ action: 'getEntryByPath', path: 'Di' }) + selectedArchive.getEntryByPath('Home.html') // ✅ + // selectedArchive.search2('Di') + // selectedArchive.getDirEntryByPath('/') + } }); document.getElementById('disableDragAndDropCheck').addEventListener('change', function () { @@ -846,7 +859,8 @@ function initServiceWorkerMessaging () { // Until we find a way to tell where it is coming from, we allow the request through on all controlled clients and try to load the content console.warn('>>> Allowing passthrough of SW request to process Zimit video <<<'); } - handleMessageChannelMessage(event); + // handleMessageChannelMessage(event); + handleMessageChannelByWasm(event); } } else if (event.data.msg_type) { // Messages received from the ReplayWorker @@ -891,6 +905,57 @@ function initServiceWorkerMessaging () { } } +/** + * Function that handles a message of the messageChannel. + * It tries to read the content in the backend, and sends it back to the ServiceWorker + * + * @param {Event} event The event object of the message channel + */ +async function handleMessageChannelByWasm (event) { + // We received a message from the ServiceWorker + // The ServiceWorker asks for some content + const title = event.data.title; + const messagePort = event.ports[0]; + const ret = await selectedArchive.getEntryDirByWasm(title); + if (ret === null) { + console.error('Title ' + title + ' not found in archive.'); + messagePort.postMessage({ action: 'giveContent', title: title, content: '' }); + return + } + + // // Let's send the content to the ServiceWorker + var message = { action: 'giveContent', title: title, content: ret.content, mimetype: ret.mimetype }; + // messagePort.postMessage(message, [ret.content]); + messagePort.postMessage(message); + + // 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()) { + // selectedArchive.resolveRedirect(dirEntry, function (resolvedDirEntry) { + // var redirectURL = resolvedDirEntry.namespace + '/' + resolvedDirEntry.url; + // // 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: redirectURL }); + // }); + // } else { + // // Let's read the content in the ZIM file + // selectedArchive.readBinaryFile(dirEntry, function (fileDirEntry, content) { + // var mimetype = fileDirEntry.getMimetype(); + // // Let's send the content to the ServiceWorker + // var message = { action: 'giveContent', title: title, content: content.buffer, mimetype: mimetype }; + // messagePort.postMessage(message, [content.buffer]); + // }); + // } + // }; + // selectedArchive.getDirEntryByPath(title).then(readFile).catch(function () { + // messagePort.postMessage({ action: 'giveContent', title: title, content: new Uint8Array() }); + // }); +} + /** * Sets the given injection mode. * This involves registering (or re-enabling) the Service Worker if necessary diff --git a/www/js/init.js b/www/js/init.js index c9380ee1f..672ea6efb 100644 --- a/www/js/init.js +++ b/www/js/init.js @@ -55,7 +55,7 @@ * @property {string} cacheIDB - Name of the Indexed DB database * @property {boolean} isFileSystemApiSupported - A boolean indicating whether the FileSystem API is supported. * @property {boolean} isWebkitDirApiSupported - A boolean indicating whether the Webkit Directory API is supported. - * @property {boolean} libzimWasmMode - A boolean indicating whether the Libzim wasm mode is turned on. + * @property {"wasm-dev" | "wasm" | "asm" | "asm-dev" | "default"} libzimMode - A value indicating which libzim mode is selected. * @property {DecompressorAPI} decompressorAPI /** @@ -124,7 +124,7 @@ params['cacheAPI'] = 'kiwix-js'; // Sets name of the prefix used to identify the params['cacheIDB'] = 'kiwix-zim'; // Sets name of the Indexed DB database params['isFileSystemApiSupported'] = typeof window.showOpenFilePicker === 'function'; // Sets a boolean indicating whether the FileSystem API is supported params['isWebkitDirApiSupported'] = 'webkitdirectory' in document.createElement('input'); // Sets a boolean indicating whether the Webkit Directory API is supported -params['libzimWasmMode'] = getSetting('libzimWasmMode'); // Sets a boolean indicating whether the libzim WASM mode is turned on +params['libzimMode'] = getSetting('libzimMode') ?? 'default'; // Sets a value indicating which libzim mode is selected /** * Apply any override parameters that might be in the querystring. @@ -187,7 +187,7 @@ document.getElementById('useHomeKeyToFocusSearchBarCheck').checked = params.useH document.getElementById('openExternalLinksInNewTabsCheck').checked = params.openExternalLinksInNewTabs; document.getElementById('languageSelector').value = params.overrideBrowserLanguage || 'default'; document.getElementById('bypassAppCacheCheck').checked = !params.appCache; -document.getElementById('libzimWasmModeToggle').checked = params.libzimWasmMode; +document.getElementById('libzimModeSelect').value = params.libzimMode; document.getElementById('appVersion').textContent = 'Kiwix ' + params.appVersion; // This is a simplified version of code in settingsStore, because that module is not available in init.js diff --git a/www/js/lib/zimArchive.js b/www/js/lib/zimArchive.js index 7d2c3c5a3..1e1999ade 100644 --- a/www/js/lib/zimArchive.js +++ b/www/js/lib/zimArchive.js @@ -501,6 +501,16 @@ ZIMArchive.prototype.findDirEntriesFromFullTextSearch = function (search, dirEnt }); }; +ZIMArchive.prototype.getEntryDirByWasm = async function (path) { + // this.file.mainPage + // const cns = this.getContentNamespace() + // path = cns + '/' + path; + const ret = await this.callLibzimWorker({ action: 'getEntryByPath', path: path }); + // const r = await this.getDirEntryByPath(path) + // console.log(path, ret, r); + return ret; +} + /** * Calls the libzim Web Worker with the given parameters, and returns a Promise with its response * From 691cfffcc5595db45b4976604b3ddf8bcaebccb2 Mon Sep 17 00:00:00 2001 From: RG Date: Thu, 23 Nov 2023 00:44:04 +0530 Subject: [PATCH 03/13] Refactor code to readyCallback after libzim --- www/js/app.js | 54 +++++++++++----------------------------- www/js/init.js | 1 + www/js/lib/zimArchive.js | 6 ++++- 3 files changed, 21 insertions(+), 40 deletions(-) diff --git a/www/js/app.js b/www/js/app.js index 25875d75d..194a99262 100644 --- a/www/js/app.js +++ b/www/js/app.js @@ -34,7 +34,6 @@ import uiUtil from './lib/uiUtil.js'; import settingsStore from './lib/settingsStore.js'; import abstractFilesystemAccess from './lib/abstractFilesystemAccess.js'; import translateUI from './lib/translateUI.js'; -import { type } from 'jquery'; if (params.abort) { // If the app was loaded only to pass a message from the remote code, then we exit immediately @@ -916,44 +915,21 @@ async function handleMessageChannelByWasm (event) { // The ServiceWorker asks for some content const title = event.data.title; const messagePort = event.ports[0]; - const ret = await selectedArchive.getEntryDirByWasm(title); - if (ret === null) { - console.error('Title ' + title + ' not found in archive.'); - messagePort.postMessage({ action: 'giveContent', title: title, content: '' }); - return - } - - // // Let's send the content to the ServiceWorker - var message = { action: 'giveContent', title: title, content: ret.content, mimetype: ret.mimetype }; - // messagePort.postMessage(message, [ret.content]); - messagePort.postMessage(message); - - // 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()) { - // selectedArchive.resolveRedirect(dirEntry, function (resolvedDirEntry) { - // var redirectURL = resolvedDirEntry.namespace + '/' + resolvedDirEntry.url; - // // 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: redirectURL }); - // }); - // } else { - // // Let's read the content in the ZIM file - // selectedArchive.readBinaryFile(dirEntry, function (fileDirEntry, content) { - // var mimetype = fileDirEntry.getMimetype(); - // // Let's send the content to the ServiceWorker - // var message = { action: 'giveContent', title: title, content: content.buffer, mimetype: mimetype }; - // messagePort.postMessage(message, [content.buffer]); - // }); - // } - // }; - // selectedArchive.getDirEntryByPath(title).then(readFile).catch(function () { - // messagePort.postMessage({ action: 'giveContent', title: title, content: new Uint8Array() }); - // }); + try { + const ret = await selectedArchive.getEntryDirByWasm(title); + if (ret === null) { + console.error('Title ' + title + ' not found in archive.'); + messagePort.postMessage({ action: 'giveContent', title: title, content: '' }); + return + } + + // Let's send the content to the ServiceWorker + const message = { action: 'giveContent', title: title, content: ret.content, mimetype: ret.mimetype }; + messagePort.postMessage(message); + } catch (error) { + const message = { action: 'giveContent', title: title, content: new Uint8Array(), mimetype: '' }; + messagePort.postMessage(message); + } } /** diff --git a/www/js/init.js b/www/js/init.js index 672ea6efb..07f266bd1 100644 --- a/www/js/init.js +++ b/www/js/init.js @@ -125,6 +125,7 @@ params['cacheIDB'] = 'kiwix-zim'; // Sets name of the Indexed DB database params['isFileSystemApiSupported'] = typeof window.showOpenFilePicker === 'function'; // Sets a boolean indicating whether the FileSystem API is supported params['isWebkitDirApiSupported'] = 'webkitdirectory' in document.createElement('input'); // Sets a boolean indicating whether the Webkit Directory API is supported params['libzimMode'] = getSetting('libzimMode') ?? 'default'; // Sets a value indicating which libzim mode is selected +params['useLibzim'] = true; // Sets a value indicating which libzim mode is selected /** * Apply any override parameters that might be in the querystring. diff --git a/www/js/lib/zimArchive.js b/www/js/lib/zimArchive.js index 1e1999ade..480109dc2 100644 --- a/www/js/lib/zimArchive.js +++ b/www/js/lib/zimArchive.js @@ -146,12 +146,16 @@ function ZIMArchive (storage, path, callbackReady, callbackError) { if (that.file.fullTextIndex && (params.debugLibzimASM || !isSplitZim && typeof Atomics !== 'undefined' && // Note that Android and NWJS currently throw due to problems with Web Worker context !/Android/.test(params.appType) && !(window.nw && that.file._files[0].readMode === 'electron'))) { - var libzimReaderType = params.debugLibzimASM || ('WebAssembly' in self ? 'wasm' : 'asm'); + // var libzimReaderType = params.debugLibzimASM || ('WebAssembly' in self ? 'wasm' : 'asm'); + var libzimReaderType = params.debugLibzimASM || ('WebAssembly' in self ? 'wasm.dev' : 'asm.dev'); + console.log('Instantiating libzim ' + libzimReaderType + ' Web Worker...'); LZ = new Worker('js/lib/libzim-' + libzimReaderType + '.js'); that.callLibzimWorker({ action: 'init', files: that.file._files }).then(function () { that.libzimReady = 'ready'; params.searchProvider = 'fulltext: ' + libzimReaderType; + if (params.useLibzim) whenZimReady(); + // Update the API panel uiUtil.reportSearchProviderToAPIStatusPanel(params.searchProvider); }).catch(function (err) { From b240c5c4d841f349b9f2ff618d65c207bcaa9513 Mon Sep 17 00:00:00 2001 From: RG Date: Sun, 10 Dec 2023 20:53:48 +0530 Subject: [PATCH 04/13] Refactor content retrieval logic in handleMessageChannelByWasm function --- www/js/app.js | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/www/js/app.js b/www/js/app.js index 194a99262..300587815 100644 --- a/www/js/app.js +++ b/www/js/app.js @@ -920,9 +920,35 @@ async function handleMessageChannelByWasm (event) { if (ret === null) { console.error('Title ' + title + ' not found in archive.'); messagePort.postMessage({ action: 'giveContent', title: title, content: '' }); - return + return; + } + + if (ret.mimetype === 'unknown') { + const dirEntry = await new Promise((resolve, reject) => { + selectedArchive.getMainPageDirEntry((value) => { + resolve(value); + }); + }); + console.log(dirEntry); + if (dirEntry.redirect) { + const redirect = await new Promise((resolve, reject) => selectedArchive.resolveRedirect(dirEntry, (v) => resolve(v))); + const ret = await selectedArchive.getEntryDirByWasm(redirect.namespace + '/' + redirect.url); + const message = { action: 'giveContent', title: title, content: ret.content, mimetype: ret.mimetype }; + messagePort.postMessage(message); + return; + } } + // if (ret.redirect) { + // const redirect = await new Promise((resolve, reject) => selectedArchive.resolveRedirect(ret, (v) => resolve(v))); + // const ret = await selectedArchive.getEntryDirByWasm(redirect.namespace + '/' + redirect.url); + + // console.log(ret); + // const message = { action: 'giveContent', title: title, content: ret.content, mimetype: ret.mimetype }; + // messagePort.postMessage(message); + // return; + // } + // Let's send the content to the ServiceWorker const message = { action: 'giveContent', title: title, content: ret.content, mimetype: ret.mimetype }; messagePort.postMessage(message); From 7ee8b6f6da5d448a3c1bea73cb671f65eda413b8 Mon Sep 17 00:00:00 2001 From: RG Date: Tue, 12 Dec 2023 23:31:59 +0530 Subject: [PATCH 05/13] [ADD] load proper libzim when selected --- www/index.html | 5 ++--- www/js/app.js | 41 ++++++++++------------------------------ www/js/init.js | 3 ++- www/js/lib/zimArchive.js | 8 ++++---- 4 files changed, 18 insertions(+), 39 deletions(-) diff --git a/www/index.html b/www/index.html index 190478be2..69dfd62d6 100644 --- a/www/index.html +++ b/www/index.html @@ -701,10 +701,9 @@

Expert settings

- - + + -

Reset the app to default settings and erase all caches:

diff --git a/www/js/app.js b/www/js/app.js index 300587815..7cd0adcb1 100644 --- a/www/js/app.js +++ b/www/js/app.js @@ -478,17 +478,7 @@ document.getElementById('bypassAppCacheCheck').addEventListener('change', functi document.getElementById('libzimModeSelect').addEventListener('change', function (e) { // console.log(settingsStore.getItem('libzimMode')); settingsStore.setItem('libzimMode', e.target.value); -}); - -document.getElementById('testButtonToBeRemoved').addEventListener('click', function (e) { - console.log('clicked on libzimModeSelect', selectedArchive); - if (selectedArchive !== null) { - console.log('calling function getDirEntryByPath', selectedArchive.isReady()); - // selectedArchive.callLibzimWorker({ action: 'getEntryByPath', path: 'Di' }) - selectedArchive.getEntryByPath('Home.html') // ✅ - // selectedArchive.search2('Di') - // selectedArchive.getDirEntryByPath('/') - } + window.location.reload(); }); document.getElementById('disableDragAndDropCheck').addEventListener('change', function () { @@ -858,8 +848,8 @@ function initServiceWorkerMessaging () { // Until we find a way to tell where it is coming from, we allow the request through on all controlled clients and try to load the content console.warn('>>> Allowing passthrough of SW request to process Zimit video <<<'); } - // handleMessageChannelMessage(event); - handleMessageChannelByWasm(event); + if (params.useLibzim) handleMessageChannelByWasm(event); + else handleMessageChannelMessage(event); } } else if (event.data.msg_type) { // Messages received from the ReplayWorker @@ -906,7 +896,7 @@ function initServiceWorkerMessaging () { /** * Function that handles a message of the messageChannel. - * It tries to read the content in the backend, and sends it back to the ServiceWorker + * This function will deal with the messages if useLibzim is set to true * * @param {Event} event The event object of the message channel */ @@ -924,14 +914,13 @@ async function handleMessageChannelByWasm (event) { } if (ret.mimetype === 'unknown') { - const dirEntry = await new Promise((resolve, reject) => { - selectedArchive.getMainPageDirEntry((value) => { - resolve(value); - }); - }); - console.log(dirEntry); + // We have a redirect to follow + // this is still a bit flawed, as we do not check if the redirect or the file doesnt exist + // We have no way to know if the file exists or not, so we have to assume it does and its just a redirect + + const dirEntry = await new Promise((resolve, _reject) => selectedArchive.getMainPageDirEntry((value) => resolve(value))); if (dirEntry.redirect) { - const redirect = await new Promise((resolve, reject) => selectedArchive.resolveRedirect(dirEntry, (v) => resolve(v))); + const redirect = await new Promise((resolve, _reject) => selectedArchive.resolveRedirect(dirEntry, (v) => resolve(v))); const ret = await selectedArchive.getEntryDirByWasm(redirect.namespace + '/' + redirect.url); const message = { action: 'giveContent', title: title, content: ret.content, mimetype: ret.mimetype }; messagePort.postMessage(message); @@ -939,16 +928,6 @@ async function handleMessageChannelByWasm (event) { } } - // if (ret.redirect) { - // const redirect = await new Promise((resolve, reject) => selectedArchive.resolveRedirect(ret, (v) => resolve(v))); - // const ret = await selectedArchive.getEntryDirByWasm(redirect.namespace + '/' + redirect.url); - - // console.log(ret); - // const message = { action: 'giveContent', title: title, content: ret.content, mimetype: ret.mimetype }; - // messagePort.postMessage(message); - // return; - // } - // Let's send the content to the ServiceWorker const message = { action: 'giveContent', title: title, content: ret.content, mimetype: ret.mimetype }; messagePort.postMessage(message); diff --git a/www/js/init.js b/www/js/init.js index 07f266bd1..52cb2c7c5 100644 --- a/www/js/init.js +++ b/www/js/init.js @@ -55,6 +55,7 @@ * @property {string} cacheIDB - Name of the Indexed DB database * @property {boolean} isFileSystemApiSupported - A boolean indicating whether the FileSystem API is supported. * @property {boolean} isWebkitDirApiSupported - A boolean indicating whether the Webkit Directory API is supported. + * @property {boolean} useLibzim - A boolean indicating weather to use the libzim to load zim files. * @property {"wasm-dev" | "wasm" | "asm" | "asm-dev" | "default"} libzimMode - A value indicating which libzim mode is selected. * @property {DecompressorAPI} decompressorAPI @@ -125,7 +126,7 @@ params['cacheIDB'] = 'kiwix-zim'; // Sets name of the Indexed DB database params['isFileSystemApiSupported'] = typeof window.showOpenFilePicker === 'function'; // Sets a boolean indicating whether the FileSystem API is supported params['isWebkitDirApiSupported'] = 'webkitdirectory' in document.createElement('input'); // Sets a boolean indicating whether the Webkit Directory API is supported params['libzimMode'] = getSetting('libzimMode') ?? 'default'; // Sets a value indicating which libzim mode is selected -params['useLibzim'] = true; // Sets a value indicating which libzim mode is selected +params['useLibzim'] = params.libzimMode !== 'default'; // Sets a value indicating which libzim mode is selected /** * Apply any override parameters that might be in the querystring. diff --git a/www/js/lib/zimArchive.js b/www/js/lib/zimArchive.js index 480109dc2..8aacd2cec 100644 --- a/www/js/lib/zimArchive.js +++ b/www/js/lib/zimArchive.js @@ -145,11 +145,11 @@ function ZIMArchive (storage, path, callbackReady, callbackError) { var isSplitZim = /\.zima.$/i.test(that.file._files[0].name); if (that.file.fullTextIndex && (params.debugLibzimASM || !isSplitZim && typeof Atomics !== 'undefined' && // Note that Android and NWJS currently throw due to problems with Web Worker context - !/Android/.test(params.appType) && !(window.nw && that.file._files[0].readMode === 'electron'))) { - // var libzimReaderType = params.debugLibzimASM || ('WebAssembly' in self ? 'wasm' : 'asm'); - var libzimReaderType = params.debugLibzimASM || ('WebAssembly' in self ? 'wasm.dev' : 'asm.dev'); + !/Android/.test(params.appType) && !(window.nw && that.file._files[0].readMode === 'electron')) || params.useLibzim) { + var libzimReaderType = params.libzimMode; + if (libzimReaderType === 'default') libzimReaderType = 'WebAssembly' in self ? 'wasm.dev' : 'asm.dev'; - console.log('Instantiating libzim ' + libzimReaderType + ' Web Worker...'); + console.log('[DEBUG] Instantiating libzim ' + libzimReaderType + ' Web Worker...'); LZ = new Worker('js/lib/libzim-' + libzimReaderType + '.js'); that.callLibzimWorker({ action: 'init', files: that.file._files }).then(function () { that.libzimReady = 'ready'; From 079393fdbe87f508ec21c3cdfce1ca5a2d25604d Mon Sep 17 00:00:00 2001 From: RG Date: Tue, 12 Dec 2023 23:37:44 +0530 Subject: [PATCH 06/13] Fix issue with loading split ZIM archives in libzim --- www/js/lib/zimArchive.js | 1 + 1 file changed, 1 insertion(+) diff --git a/www/js/lib/zimArchive.js b/www/js/lib/zimArchive.js index 8aacd2cec..6922d209e 100644 --- a/www/js/lib/zimArchive.js +++ b/www/js/lib/zimArchive.js @@ -142,6 +142,7 @@ function ZIMArchive (storage, path, callbackReady, callbackError) { ]).then(function () { that.libzimReady = null; // There is currently an exception thrown in the libzim wasm if we attempt to load a split ZIM archive, so we work around + // In case of a split ZIM, It will not be loaded properly by libzim if libzim is enabled var isSplitZim = /\.zima.$/i.test(that.file._files[0].name); if (that.file.fullTextIndex && (params.debugLibzimASM || !isSplitZim && typeof Atomics !== 'undefined' && // Note that Android and NWJS currently throw due to problems with Web Worker context From 40ad4a5bbae2e23590dcf00092e7efb76df05a1c Mon Sep 17 00:00:00 2001 From: RG Date: Sun, 17 Dec 2023 02:22:36 +0530 Subject: [PATCH 07/13] [FIX] firefox test --- www/js/app.js | 8 ++++---- www/js/init.js | 2 +- www/js/lib/zimArchive.js | 11 ----------- 3 files changed, 5 insertions(+), 16 deletions(-) diff --git a/www/js/app.js b/www/js/app.js index 7cd0adcb1..ec62d2861 100644 --- a/www/js/app.js +++ b/www/js/app.js @@ -848,7 +848,7 @@ function initServiceWorkerMessaging () { // Until we find a way to tell where it is coming from, we allow the request through on all controlled clients and try to load the content console.warn('>>> Allowing passthrough of SW request to process Zimit video <<<'); } - if (params.useLibzim) handleMessageChannelByWasm(event); + if (params.useLibzim) handleMessageChannelByLibzim(event); else handleMessageChannelMessage(event); } } else if (event.data.msg_type) { @@ -900,13 +900,13 @@ function initServiceWorkerMessaging () { * * @param {Event} event The event object of the message channel */ -async function handleMessageChannelByWasm (event) { +async function handleMessageChannelByLibzim (event) { // We received a message from the ServiceWorker // The ServiceWorker asks for some content const title = event.data.title; const messagePort = event.ports[0]; try { - const ret = await selectedArchive.getEntryDirByWasm(title); + const ret = await selectedArchive.callLibzimWorker({ action: 'getEntryByPath', path: title }) if (ret === null) { console.error('Title ' + title + ' not found in archive.'); messagePort.postMessage({ action: 'giveContent', title: title, content: '' }); @@ -921,7 +921,7 @@ async function handleMessageChannelByWasm (event) { const dirEntry = await new Promise((resolve, _reject) => selectedArchive.getMainPageDirEntry((value) => resolve(value))); if (dirEntry.redirect) { const redirect = await new Promise((resolve, _reject) => selectedArchive.resolveRedirect(dirEntry, (v) => resolve(v))); - const ret = await selectedArchive.getEntryDirByWasm(redirect.namespace + '/' + redirect.url); + const ret = await selectedArchive.callLibzimWorker({ action: 'getEntryByPath', path: redirect.namespace + '/' + redirect.url }) const message = { action: 'giveContent', title: title, content: ret.content, mimetype: ret.mimetype }; messagePort.postMessage(message); return; diff --git a/www/js/init.js b/www/js/init.js index 52cb2c7c5..a950a0620 100644 --- a/www/js/init.js +++ b/www/js/init.js @@ -125,7 +125,7 @@ params['cacheAPI'] = 'kiwix-js'; // Sets name of the prefix used to identify the params['cacheIDB'] = 'kiwix-zim'; // Sets name of the Indexed DB database params['isFileSystemApiSupported'] = typeof window.showOpenFilePicker === 'function'; // Sets a boolean indicating whether the FileSystem API is supported params['isWebkitDirApiSupported'] = 'webkitdirectory' in document.createElement('input'); // Sets a boolean indicating whether the Webkit Directory API is supported -params['libzimMode'] = getSetting('libzimMode') ?? 'default'; // Sets a value indicating which libzim mode is selected +params['libzimMode'] = getSetting('libzimMode') || 'default'; // Sets a value indicating which libzim mode is selected params['useLibzim'] = params.libzimMode !== 'default'; // Sets a value indicating which libzim mode is selected /** diff --git a/www/js/lib/zimArchive.js b/www/js/lib/zimArchive.js index 6922d209e..275198a48 100644 --- a/www/js/lib/zimArchive.js +++ b/www/js/lib/zimArchive.js @@ -156,7 +156,6 @@ function ZIMArchive (storage, path, callbackReady, callbackError) { that.libzimReady = 'ready'; params.searchProvider = 'fulltext: ' + libzimReaderType; if (params.useLibzim) whenZimReady(); - // Update the API panel uiUtil.reportSearchProviderToAPIStatusPanel(params.searchProvider); }).catch(function (err) { @@ -506,16 +505,6 @@ ZIMArchive.prototype.findDirEntriesFromFullTextSearch = function (search, dirEnt }); }; -ZIMArchive.prototype.getEntryDirByWasm = async function (path) { - // this.file.mainPage - // const cns = this.getContentNamespace() - // path = cns + '/' + path; - const ret = await this.callLibzimWorker({ action: 'getEntryByPath', path: path }); - // const r = await this.getDirEntryByPath(path) - // console.log(path, ret, r); - return ret; -} - /** * Calls the libzim Web Worker with the given parameters, and returns a Promise with its response * From 80628aabdbaaf7856bcc2ca7c6e56608f82e65b6 Mon Sep 17 00:00:00 2001 From: RG Date: Mon, 18 Dec 2023 20:12:23 +0530 Subject: [PATCH 08/13] [CHANGE] checkbox for libzim | cleanup for dropdown --- www/index.html | 10 ++++++++-- www/js/app.js | 9 +++++++-- www/js/init.js | 5 +++-- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/www/index.html b/www/index.html index 69dfd62d6..77489df03 100644 --- a/www/index.html +++ b/www/index.html @@ -696,9 +696,15 @@

Expert settings

+
+
-