mirror of
https://github.com/kiwix/kiwix-js-pwa.git
synced 2025-09-11 13:18:21 -04:00
Simplify code for Native FS checking
Former-commit-id: 2afa51b968234f44fdb7297666dedf94eda082e7 [formerly 2a3d31d5df16ab053c6bc072b2fe544b4ef203a3] Former-commit-id: 3f4f9a089b6b1c455f80f42ac183479e31514115
This commit is contained in:
parent
a69d8e2119
commit
d89b12ef02
@ -824,30 +824,14 @@ define(['jquery', 'zimArchiveLoader', 'uiUtil', 'util', 'cache', 'images', 'cook
|
|||||||
cache.idxDB('pickedFileHandle', function(val) {
|
cache.idxDB('pickedFileHandle', function(val) {
|
||||||
if (val) {
|
if (val) {
|
||||||
var handle = val;
|
var handle = val;
|
||||||
// Check if we have persmission to open
|
cache.verifyPermission(handle, false).then(function(status) {
|
||||||
handle.requestPermission({mode: 'read'}).then(function(readPermission) {
|
if (status) processNativeFileHandle(handle);
|
||||||
if (readPermission === 'granted') {
|
|
||||||
processNativeFileHandle(handle);
|
|
||||||
} else {
|
|
||||||
pickFileNativeFS();
|
|
||||||
}
|
|
||||||
}).catch(function(err) {
|
|
||||||
console.error('Unable to load previously picked file', err);
|
|
||||||
pickFileNativeFS();
|
|
||||||
});
|
});
|
||||||
// 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 () {
|
document.getElementById('btnAbout').addEventListener('click', function () {
|
||||||
var btnAboutElement = document.getElementById('btnAbout');
|
var btnAboutElement = document.getElementById('btnAbout');
|
||||||
if (/glyphicon-print/.test(btnAboutElement.innerHTML)) {
|
if (/glyphicon-print/.test(btnAboutElement.innerHTML)) {
|
||||||
|
@ -625,6 +625,27 @@ define(['q', 'uiUtil'], function(Q, uiUtil) {
|
|||||||
return string;
|
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,
|
* 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
|
* 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,
|
clear: clear,
|
||||||
wait: wait,
|
wait: wait,
|
||||||
getItemFromCacheOrZIM: getItemFromCacheOrZIM,
|
getItemFromCacheOrZIM: getItemFromCacheOrZIM,
|
||||||
replaceAssetRefsWithUri: replaceAssetRefsWithUri
|
replaceAssetRefsWithUri: replaceAssetRefsWithUri,
|
||||||
|
verifyPermission: verifyPermission
|
||||||
};
|
};
|
||||||
});
|
});
|
Loading…
x
Reference in New Issue
Block a user