Removed zimArchiveLoader's dependency on uiUtil

Applied changes from the review
This commit is contained in:
Gaurav Agarwal 2022-02-25 16:16:47 +05:30
parent b5d6db09ed
commit 0fe5453445
2 changed files with 11 additions and 7 deletions

View File

@ -974,7 +974,10 @@ define(['jquery', 'zimArchiveLoader', 'uiUtil', 'settingsStore','abstractFilesys
// If DeviceStorage is available, we look for archives in it
$("#btnConfigure").click();
$('#scanningForArchives').show();
zimArchiveLoader.scanForArchives(storages, populateDropDownListOfArchives);
zimArchiveLoader.scanForArchives(storages, populateDropDownListOfArchives, function () {
// callbackError function is called in case of an error
uiUtil.systemAlert(message, label).then(populateDropDownListOfArchives(null));
});
}
if ($.isFunction(navigator.getDeviceStorages)) {

View File

@ -20,8 +20,8 @@
* along with Kiwix (file LICENSE-GPLv3.txt). If not, see <http://www.gnu.org/licenses/>
*/
'use strict';
define(['zimArchive', 'jquery', 'uiUtil'],
function(zimArchive, jQuery, uiUtil) {
define(['zimArchive', 'jquery'],
function(zimArchive, jQuery) {
/**
* Create a ZIMArchive from DeviceStorage location
@ -58,8 +58,9 @@ define(['zimArchive', 'jquery', 'uiUtil'],
*
* @param {Array.<DeviceStorage>} storages List of DeviceStorage instances
* @param {callbackPathList} callbackFunction Function to call with the list of directories where archives are found
* @param {callbackPathList} callbackError Function to call in case of an error
*/
function scanForArchives(storages, callbackFunction) {
function scanForArchives(storages, callbackFunction, callbackError) {
var directories = [];
var promises = jQuery.map(storages, function(storage) {
return storage.scanForArchives()
@ -70,12 +71,12 @@ define(['zimArchive', 'jquery', 'uiUtil'],
});
jQuery.when.apply(null, promises).then(function() {
callbackFunction(directories);
}, function(error) {
uiUtil.systemAlert("Error scanning your device storage : " + error
}).catch(function (error) {
callbackError("Error scanning your device storage : " + error
+ ". If you're using the Firefox OS Simulator, please put the archives in "
+ "a 'fake-sdcard' directory inside your Firefox profile "
+ "(ex : ~/.mozilla/firefox/xxxx.default/extensions/fxos_2_x_simulator@mozilla.org/"
+ "profile/fake-sdcard/wikipedia_en_ray_charles_2015-06.zim)", "Error reading Device Storage").then(function() { callbackFunction(null); });
+ "profile/fake-sdcard/wikipedia_en_ray_charles_2015-06.zim)", "Error reading Device Storage");
});
};