From 5603f83d0fbe569ec10b738e60d875ee6e61dad7 Mon Sep 17 00:00:00 2001 From: RG Date: Wed, 11 Oct 2023 18:40:10 +0530 Subject: [PATCH] [ADD] Zim File handler saving in indexDB --- www/js/app.js | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/www/js/app.js b/www/js/app.js index cc8013368..7b379c5aa 100644 --- a/www/js/app.js +++ b/www/js/app.js @@ -35,6 +35,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 cache from './lib/cache.js'; if (params.abort) { // If the app was loaded only to pass a message from the remote code, then we exit immediately @@ -156,6 +157,7 @@ function resizeIFrame () { document.addEventListener('DOMContentLoaded', function () { getDefaultLanguageAndTranslateApp(); resizeIFrame(); + loadPreviousZimFile(); }); window.addEventListener('resize', resizeIFrame); @@ -1243,6 +1245,26 @@ function resetCssCache () { } } +async function loadPreviousZimFile () { + const openFile = await uiUtil.systemAlert('Do you want to load the previously selected zim file?', 'Load previous zim file', true, 'No', 'Yes', 'No') + // .then(function (response) { + // }) + if (!openFile) return + // If a old zim file is already selected, we set it as the localArchive + cache.idxDB('files', async function (filesHandlers) { + // console.log("FILE HANDLE", a); + // refer to this article ; https://developer.chrome.com/articles/file-system-access/ + const files = []; + for (let index = 0; index < filesHandlers.length; index++) { + const fileHandler = filesHandlers[index]; + await fileHandler.requestPermission(); + files.push(await fileHandler.getFile()) + } + console.log(files); + setLocalArchiveFromFileList(files); + }) +} + /** * Displays the zone to select files from the archive */ @@ -1269,6 +1291,10 @@ function displayFileSelect () { window.showOpenFilePicker({ multiple: true }).then(function (fileHandle) { fileHandle[0].getFile().then(function (file) { setLocalArchiveFromFileList([file]); + + cache.idxDB('files', fileHandle, function (a) { + // console.log(a); + }) }); }); })