Skip to content

Commit

Permalink
[FIX] auto load zim on Folder select
Browse files Browse the repository at this point in the history
  • Loading branch information
Rishabhg71 committed Nov 5, 2023
1 parent a55d9d2 commit bb1d61b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
7 changes: 4 additions & 3 deletions www/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ function resizeIFrame () {
if (iframe.style.display === 'none') {
// We are in About or Configuration, so we only set the region height
region.style.height = window.innerHeight + 'px';
nestedFrame.style.height = window.innerHeight - 110 + 'px';
if (nestedFrame) nestedFrame.style.height = window.innerHeight - 110 + 'px';
} else {
// IE cannot retrieve computed headerStyles till the next paint, so we wait a few ticks
setTimeout(function () {
Expand Down Expand Up @@ -1348,7 +1348,7 @@ function displayFileSelect () {
console.debug(`File system api is ${params.isFileSystemApiSupported ? '' : 'not '}supported`);
console.debug(`Webkit directory api ${params.isWebkitDirApiSupported ? '' : 'not '}supported`);
console.debug(`Firefox os native file ${isFireFoxOsNativeFileApiAvailable ? '' : 'not '}support api`)
console.log('ASSSSS');

document.getElementById('openLocalFiles').style.display = 'block';
if ((params.isFileSystemApiSupported || params.isWebkitDirApiSupported) && !isPlatformMobilePhone) {
document.getElementById('chooseArchiveFromLocalStorage').style.display = '';
Expand Down Expand Up @@ -1393,7 +1393,8 @@ function displayFileSelect () {
// Handles Folder selection when showDirectoryPicker is supported
document.getElementById('folderSelect').addEventListener('click', async function (e) {
e.preventDefault();
await abstractFilesystemAccess.selectDirectoryFromPickerViaFileSystemApi()
const previousZimFiles = await abstractFilesystemAccess.selectDirectoryFromPickerViaFileSystemApi()
if (previousZimFiles.length !== 0) setLocalArchiveFromFileList(previousZimFiles);
})
}
if (params.isWebkitDirApiSupported && !params.isFileSystemApiSupported && !isFireFoxOsNativeFileApiAvailable) {
Expand Down
10 changes: 9 additions & 1 deletion www/js/lib/abstractFilesystemAccess.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,19 +130,27 @@ async function updateZimDropdownOptions (files, selectedFile) {

/**
* Opens the File System API to select a directory
* @returns {Promise<Array<File>>} Previously selected file if available in selected folder
*/
async function selectDirectoryFromPickerViaFileSystemApi () {
const handle = await window.showDirectoryPicker();
const fileNames = [];
const previousZimFile = []

const lastZimNameWithoutExtension = (localStorage.getItem('previousZimFileName') ?? '').replace(/\.zim\w\w$/i, '');
const regex = new RegExp(`\\${lastZimNameWithoutExtension}.zim\\w\\w$`, 'i');

for await (const entry of handle.values()) {
fileNames.push(entry.name);
if (regex.test(entry.name) || entry.name === (localStorage.getItem('previousZimFileName') ?? '')) previousZimFile.push(await entry.getFile());
}

localStorage.setItem('zimFilenames', fileNames.join('|'));
updateZimDropdownOptions(fileNames, '');
updateZimDropdownOptions(fileNames, previousZimFile.length !== 0 ? localStorage.getItem('previousZimFileName') : '');
cache.idxDB('zimFiles', handle, function () {
// save file in DB
});
return previousZimFile;
}

/**
Expand Down

0 comments on commit bb1d61b

Please sign in to comment.