mirror of
https://github.com/kiwix/kiwix-js-pwa.git
synced 2025-09-08 11:48:26 -04:00
Simplify code for Native FS checking
Former-commit-id: d89b12ef023c4b64d6d769904c1093c36f9927f9 [formerly 3f4f9a089b6b1c455f80f42ac183479e31514115] [formerly 2afa51b968234f44fdb7297666dedf94eda082e7 [formerly 2a3d31d5df16ab053c6bc072b2fe544b4ef203a3]] Former-commit-id: 272c55ebf3a898b052cb7dfd32ea27145c5ecdb4 [formerly 7d0f819c1cd5d529132048f1f601e9cd7585c551] Former-commit-id: 0f62022e238c5c3e5a1941cb9bfab14e7b702145
This commit is contained in:
parent
7bc08fa346
commit
64d60645ee
@ -824,30 +824,14 @@ define(['jquery', 'zimArchiveLoader', 'uiUtil', 'util', 'cache', 'images', 'cook
|
||||
cache.idxDB('pickedFileHandle', function(val) {
|
||||
if (val) {
|
||||
var handle = val;
|
||||
// Check if we have persmission to open
|
||||
handle.requestPermission({mode: 'read'}).then(function(readPermission) {
|
||||
if (readPermission === 'granted') {
|
||||
processNativeFileHandle(handle);
|
||||
} else {
|
||||
pickFileNativeFS();
|
||||
}
|
||||
}).catch(function(err) {
|
||||
console.error('Unable to load previously picked file', err);
|
||||
pickFileNativeFS();
|
||||
cache.verifyPermission(handle, false).then(function(status) {
|
||||
if (status) processNativeFileHandle(handle);
|
||||
});
|
||||
// handle.queryPermission({mode: 'read'}).then(function(permission) {
|
||||
// if (permission === 'granted') {
|
||||
// processNativeFileHandle(handle);
|
||||
// } else if (permission === 'prompt') {
|
||||
// // Do nothing
|
||||
// }
|
||||
// }).catch(function(err) {
|
||||
// console.error('Unable to load previously picked file', err);
|
||||
// });
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
document.getElementById('btnAbout').addEventListener('click', function () {
|
||||
var btnAboutElement = document.getElementById('btnAbout');
|
||||
if (/glyphicon-print/.test(btnAboutElement.innerHTML)) {
|
||||
|
@ -625,6 +625,27 @@ define(['q', 'uiUtil'], function(Q, uiUtil) {
|
||||
return string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Provide
|
||||
*
|
||||
* @param {Object} fileHandle The file handle that we wish to verify with the Native Filesystem API
|
||||
* @param {Boolean} withWrite Indicates read only or read/write persmissions
|
||||
* @returns {Promise<Boolean>} A Promise for a Boolean value indicating whether permission has been granted or not
|
||||
*/
|
||||
function verifyPermission(fileHandle, withWrite) {
|
||||
var opts = withWrite ? { mode: 'readwrite' } : {};
|
||||
return fileHandle.queryPermission(opts).then(function(permission) {
|
||||
if (permission === "granted") return true;
|
||||
return fileHandle.requestPermission(opts).then(function(permission) {
|
||||
if (permission === 'granted') return true;
|
||||
console.error('Permission for ' + fileHandle.name + ' was not granted: ' + permission);
|
||||
return false;
|
||||
}).catch(function(error) {
|
||||
console.error('There was an error reading previously picked file ' + fileHandle.name, error);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Wraps a semaphor in a Promise. A function can signal that it is done by setting a sempahor to true,
|
||||
* if it has first set it to false at the outset of the procedure. Ensure no other functions use the same
|
||||
@ -676,6 +697,7 @@ define(['q', 'uiUtil'], function(Q, uiUtil) {
|
||||
clear: clear,
|
||||
wait: wait,
|
||||
getItemFromCacheOrZIM: getItemFromCacheOrZIM,
|
||||
replaceAssetRefsWithUri: replaceAssetRefsWithUri
|
||||
replaceAssetRefsWithUri: replaceAssetRefsWithUri,
|
||||
verifyPermission: verifyPermission
|
||||
};
|
||||
});
|
Loading…
x
Reference in New Issue
Block a user