Skip to content

Commit

Permalink
[ADD] Zim File handler saving in indexDB
Browse files Browse the repository at this point in the history
  • Loading branch information
Rishabhg71 committed Oct 11, 2023
1 parent fc47c48 commit 4f01d0a
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions www/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -166,6 +167,7 @@ function resizeIFrame () {
document.addEventListener('DOMContentLoaded', function () {
getDefaultLanguageAndTranslateApp();
resizeIFrame();
loadPreviousZimFile();
});
window.addEventListener('resize', resizeIFrame);

Expand Down Expand Up @@ -1253,6 +1255,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
*/
Expand All @@ -1279,6 +1301,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);
})
});
});
})
Expand Down

0 comments on commit 4f01d0a

Please sign in to comment.