Restructured some of the scanning logic on initial startup

Former-commit-id: 8b0b472cbcc3805844dc750afb16a2c7c5714dac [formerly d1fe338ae00e424475e1c59606c1173788f331c5]
Former-commit-id: a38089a760db595fc0ec28faf65565ddbeae638e
This commit is contained in:
Jaifroid 2017-08-23 22:53:44 +01:00
parent 4b9ededf16
commit ebadc9b091
5 changed files with 130 additions and 46 deletions

View File

@ -32,7 +32,7 @@
<AppXManifest Include="C:\Users\geoff\Source\Repos\kiwix-js-windows\bin\Release\AppxManifest.xml"> <AppXManifest Include="C:\Users\geoff\Source\Repos\kiwix-js-windows\bin\Release\AppxManifest.xml">
<PackagePath>AppxManifest.xml</PackagePath> <PackagePath>AppxManifest.xml</PackagePath>
<ReRegisterAppIfChanged>true</ReRegisterAppIfChanged> <ReRegisterAppIfChanged>true</ReRegisterAppIfChanged>
<Modified>2017-08-23T13:15:45.669</Modified> <Modified>2017-08-23T21:52:36.698</Modified>
</AppXManifest> </AppXManifest>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
@ -603,11 +603,11 @@
</AppxPackagedFile> </AppxPackagedFile>
<AppxPackagedFile Include="C:\Users\geoff\Source\Repos\kiwix-js-windows\www\js\app.js"> <AppxPackagedFile Include="C:\Users\geoff\Source\Repos\kiwix-js-windows\www\js\app.js">
<PackagePath>www\js\app.js</PackagePath> <PackagePath>www\js\app.js</PackagePath>
<Modified>2017-08-23T13:14:12.160</Modified> <Modified>2017-08-23T21:52:28.917</Modified>
</AppxPackagedFile> </AppxPackagedFile>
<AppxPackagedFile Include="C:\Users\geoff\Source\Repos\kiwix-js-windows\www\js\init.js"> <AppxPackagedFile Include="C:\Users\geoff\Source\Repos\kiwix-js-windows\www\js\init.js">
<PackagePath>www\js\init.js</PackagePath> <PackagePath>www\js\init.js</PackagePath>
<Modified>2017-08-23T13:15:28.105</Modified> <Modified>2017-08-23T21:44:15.407</Modified>
</AppxPackagedFile> </AppxPackagedFile>
<AppxPackagedFile Include="C:\Users\geoff\Source\Repos\kiwix-js-windows\www\js\lib\abstractFilesystemAccess.js"> <AppxPackagedFile Include="C:\Users\geoff\Source\Repos\kiwix-js-windows\www\js\lib\abstractFilesystemAccess.js">
<PackagePath>www\js\lib\abstractFilesystemAccess.js</PackagePath> <PackagePath>www\js\lib\abstractFilesystemAccess.js</PackagePath>
@ -1528,7 +1528,7 @@
<AppxPackagedFile Include="C:\Users\geoff\Source\Repos\kiwix-js-windows\bin\Release\ReverseMap\resources.pri"> <AppxPackagedFile Include="C:\Users\geoff\Source\Repos\kiwix-js-windows\bin\Release\ReverseMap\resources.pri">
<PackagePath>resources.pri</PackagePath> <PackagePath>resources.pri</PackagePath>
<ReRegisterAppIfChanged>true</ReRegisterAppIfChanged> <ReRegisterAppIfChanged>true</ReRegisterAppIfChanged>
<Modified>2017-08-23T10:02:58.575</Modified> <Modified>2017-08-23T20:53:00.126</Modified>
</AppxPackagedFile> </AppxPackagedFile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

View File

@ -190,15 +190,20 @@ define(['jquery', 'zimArchiveLoader', 'util', 'uiUtil', 'cookies', 'abstractFile
}); });
$('#btnRescanDeviceStorage').on("click", function (e) { $('#btnRescanDeviceStorage').on("click", function (e) {
document.getElementById('returntoArticle_top').innerHTML = "";
document.getElementById('returntoArticle_bottom').innerHTML = "";
//Stop app from jumping straight into to first archive if user initiated the scan (to give user a chance to select the archive manually)
params['rescan'] = true;
//Reload any ZIM files in local storage (whcih the usar can't otherwise select with the filepicker)
if (params['localStorage']) { if (params['localStorage']) {
scanUWPFolderforArchives(params['localStorage']); scanUWPFolderforArchives(params['localStorage']);
return;
} }
if (storages.length) { if (storages.length) {
searchForArchivesInStorage(); searchForArchivesInStorage();
} else { } else {
displayFileSelect(); displayFileSelect();
$('archiveFiles').click(); //$('archiveFiles').click();
$('btnConfigure').click();
} }
}); });
// Bottom bar : // Bottom bar :
@ -308,6 +313,20 @@ define(['jquery', 'zimArchiveLoader', 'util', 'uiUtil', 'cookies', 'abstractFile
$('#searchingForArticles').hide(); $('#searchingForArticles').hide();
return false; return false;
}); });
// TODO: I've set up two event listeners below because the archive list doesn't "change" if there is only one element in it
// See if this can be simplified.... (but note that keyboard users might not click)
$('#archiveList').on('change', function () {
console.log("***Archive List change event fired")
setLocalArchiveFromArchiveList()
});
$('#archiveList').on('click', function () {
console.log("***Archive List click event fired: checking length of options list")
var comboArchiveList = document.getElementById('archiveList');
if (comboArchiveList.options.length == 1) {
console.log("***Only one item, so, fire away...");
setLocalArchiveFromArchiveList();
}
});
$('input:radio[name=contentInjectionMode]').on('change', function (e) { $('input:radio[name=contentInjectionMode]').on('change', function (e) {
if (checkWarnServiceWorkerMode(this.value)) { if (checkWarnServiceWorkerMode(this.value)) {
document.getElementById('returntoArticle_top').innerHTML = ""; document.getElementById('returntoArticle_top').innerHTML = "";
@ -381,7 +400,7 @@ define(['jquery', 'zimArchiveLoader', 'util', 'uiUtil', 'cookies', 'abstractFile
document.getElementById('cssUIDarkThemeCheck').checked = params['cssUITheme'] == 'dark' ? true : false; document.getElementById('cssUIDarkThemeCheck').checked = params['cssUITheme'] == 'dark' ? true : false;
cssUIThemeSet(params['cssUITheme']); cssUIThemeSet(params['cssUITheme']);
$('input:radio[name=cssInjectionMode]').filter('[value="' + params['cssSource'] + '"]').prop('checked', true); $('input:radio[name=cssInjectionMode]').filter('[value="' + params['cssSource'] + '"]').prop('checked', true);
//First run of new version code //Code below triggers display of modal info box if app is run for the first time, or it has been upgraded to new version
if (cookies.getItem('version') != params['version']) { if (cookies.getItem('version') != params['version']) {
document.getElementById('myModal').style.display = "block"; document.getElementById('myModal').style.display = "block";
document.getElementsByClassName("close")[0].onclick = function () { document.getElementsByClassName("close")[0].onclick = function () {
@ -583,7 +602,7 @@ define(['jquery', 'zimArchiveLoader', 'util', 'uiUtil', 'cookies', 'abstractFile
populateDropDownListOfArchives(directories); populateDropDownListOfArchives(directories);
} }
else { else {
if (storages.length) { if (storages.length || params['localStorage']) {
searchForArchivesInStorage(); searchForArchivesInStorage();
} else { } else {
displayFileSelect(); displayFileSelect();
@ -602,7 +621,11 @@ define(['jquery', 'zimArchiveLoader', 'util', 'uiUtil', 'cookies', 'abstractFile
// If DeviceStorage is available, we look for archives in it // If DeviceStorage is available, we look for archives in it
$("#btnConfigure").click(); $("#btnConfigure").click();
$('#scanningForArchives').show(); $('#scanningForArchives').show();
zimArchiveLoader.scanForArchives(storages, populateDropDownListOfArchives); if (params['localStorage'] && typeof Windows !== 'undefined' && typeof Windows.Storage !== 'undefined') {
scanUWPFolderforArchives(params['localStorage']);
} else {
zimArchiveLoader.scanForArchives(storages, populateDropDownListOfArchives);
}
} }
if ($.isFunction(navigator.getDeviceStorages)) { if ($.isFunction(navigator.getDeviceStorages)) {
@ -612,7 +635,8 @@ define(['jquery', 'zimArchiveLoader', 'util', 'uiUtil', 'cookies', 'abstractFile
}); });
} }
if (Windows && Windows.Storage || (storages !== null && storages.length > 0)) { if ((storages !== null && storages.length > 0) ||
(typeof Windows !== 'undefined' && typeof Windows.Storage !== 'undefined')) {
// Make a fake first access to device storage, in order to ask the user for confirmation if necessary. // Make a fake first access to device storage, in order to ask the user for confirmation if necessary.
// This way, it is only done once at this moment, instead of being done several times in callbacks // This way, it is only done once at this moment, instead of being done several times in callbacks
// After that, we can start looking for archives // After that, we can start looking for archives
@ -682,10 +706,10 @@ define(['jquery', 'zimArchiveLoader', 'util', 'uiUtil', 'cookies', 'abstractFile
// Store the list of archives in a cookie, to avoid rescanning at each start // Store the list of archives in a cookie, to avoid rescanning at each start
cookies.setItem("listOfArchives", archiveDirectories.join('|'), Infinity); cookies.setItem("listOfArchives", archiveDirectories.join('|'), Infinity);
comboArchiveList.size = comboArchiveList.length; comboArchiveList.size = comboArchiveList.length;
//$('#archiveList').on('mouseup', setLocalArchiveFromArchiveList());
$('#archiveList').on('change', setLocalArchiveFromArchiveList); //$(comboArchiveList).on('click', setLocalArchiveFromArchiveList());
if (comboArchiveList.options.length > 0) { if (comboArchiveList.options.length > 0) {
var lastSelectedArchive = cookies.getItem("lastSelectedArchive"); var lastSelectedArchive = cookies.getItem("lastSelectedArchive") || params['storedFile'];
if (lastSelectedArchive !== null && lastSelectedArchive !== undefined && lastSelectedArchive !== "") { if (lastSelectedArchive !== null && lastSelectedArchive !== undefined && lastSelectedArchive !== "") {
// Attempt to select the corresponding item in the list, if it exists // Attempt to select the corresponding item in the list, if it exists
if ($("#archiveList option[value='" + lastSelectedArchive + "']").length > 0) { if ($("#archiveList option[value='" + lastSelectedArchive + "']").length > 0) {
@ -780,7 +804,12 @@ define(['jquery', 'zimArchiveLoader', 'util', 'uiUtil', 'cookies', 'abstractFile
//archiveDirectory = MSApp.createFileFromStorageFile(file); //archiveDirectory = MSApp.createFileFromStorageFile(file);
selectedArchive = zimArchiveLoader.loadArchiveFromDeviceStorage(selectedStorage, archiveDirectory, function (archive) { selectedArchive = zimArchiveLoader.loadArchiveFromDeviceStorage(selectedStorage, archiveDirectory, function (archive) {
// The archive is set : go back to home page to start searching // The archive is set : go back to home page to start searching
$('#btnHome').click(); if (params['rescan']) {
$('#btnConfigure').click()
params['rescan'] = false;
} else {
$('#btnHome').click();
}
}); });
} else { } else {
console.error("The picked file could not be found in the selected folder!"); console.error("The picked file could not be found in the selected folder!");
@ -816,11 +845,16 @@ define(['jquery', 'zimArchiveLoader', 'util', 'uiUtil', 'cookies', 'abstractFile
*/ */
function displayFileSelect() { function displayFileSelect() {
$('#openLocalFiles').show(); $('#openLocalFiles').show();
var comboArchiveList = document.getElementById('archiveList'); //TODO - check if this is necessary or if it causes the archiveList change event to fire
if (comboArchiveList.length > 0) { comboArchiveList.size = comboArchiveList.length; } //Make archive list combo box fit the number of files
//$('#archiveFile').on('change', setLocalArchiveFromFileSelect); //var comboArchiveList = document.getElementById('archiveList');
$('#archiveFile').on('click', pickFileUWP); //UWP FilePicker [kiwix-js-windows #3] //if (comboArchiveList.length > 0) { comboArchiveList.size = comboArchiveList.length; }
$('#archiveFiles').on('click', pickFolderUWP); //UWP FolderPicker if (typeof Windows !== 'undefined' && typeof Windows.Storage !== 'undefined') {
$('#archiveFile').on('click', pickFileUWP); //UWP FilePicker [kiwix-js-windows #3]
$('#archiveFiles').on('click', pickFolderUWP); //UWP FolderPicker
} else {
$('#archiveFile').on('change', setLocalArchiveFromFileSelect);
}
} }
function pickFileUWP() { //Support UWP FilePicker [kiwix-js-windows #3] function pickFileUWP() { //Support UWP FilePicker [kiwix-js-windows #3]
@ -850,11 +884,15 @@ define(['jquery', 'zimArchiveLoader', 'util', 'uiUtil', 'cookies', 'abstractFile
folderPicker.suggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.downloads; folderPicker.suggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.downloads;
folderPicker.fileTypeFilter.replaceAll([".zim", ".dat", ".idx", ".txt", ".zimaa"]); folderPicker.fileTypeFilter.replaceAll([".zim", ".dat", ".idx", ".txt", ".zimaa"]);
folderPicker.pickSingleFolderAsync().then(scanUWPFolderForArchives(folder)); folderPicker.pickSingleFolderAsync().done(function (folder) {
if (folder) {
scanUWPFolderforArchives(folder);
}
});
} }
function scanUWPFolderforArchives (folder) { function scanUWPFolderforArchives (folder) {
if (folder) { if (folder) {
// Application now has read/write access to all contents in the picked folder (including sub-folder contents) // Application now has read/write access to all contents in the picked folder (including sub-folder contents)
// Cache folder so the contents can be accessed at a later time // Cache folder so the contents can be accessed at a later time
Windows.Storage.AccessCache.StorageApplicationPermissions.futureAccessList.addOrReplace(params['falFolderToken'], folder); Windows.Storage.AccessCache.StorageApplicationPermissions.futureAccessList.addOrReplace(params['falFolderToken'], folder);
@ -862,7 +900,7 @@ define(['jquery', 'zimArchiveLoader', 'util', 'uiUtil', 'cookies', 'abstractFile
// Query the folder. // Query the folder.
var query = folder.createFileQuery(); var query = folder.createFileQuery();
query.getFilesAsync().done(function (files) { query.getFilesAsync().done(function (files) {
// Display file list with storage provider and availability. // Display file list
var archiveDisplay = document.getElementById('chooseArchiveFromLocalStorage'); var archiveDisplay = document.getElementById('chooseArchiveFromLocalStorage');
if (!files) { if (!files) {
archiveDisplay.style.display = "inline"; archiveDisplay.style.display = "inline";

View File

@ -32,11 +32,15 @@ params['cssTheme'] = getCookie('cssTheme') || 'light'; //Set default to 'light'
params['cssUITheme'] = getCookie('cssUITheme') || 'light'; //Set default to 'light' or 'dark' to use respective themes for UI params['cssUITheme'] = getCookie('cssUITheme') || 'light'; //Set default to 'light' or 'dark' to use respective themes for UI
params['imageDisplay'] = getCookie('imageDisplay') || true; //Set default to display images from Zim params['imageDisplay'] = getCookie('imageDisplay') || true; //Set default to display images from Zim
params['imageDisplay'] = params['imageDisplay'] == "false" ? false : (params['imageDisplay'] == "true" ? true : params['imageDisplay']); params['imageDisplay'] = params['imageDisplay'] == "false" ? false : (params['imageDisplay'] == "true" ? true : params['imageDisplay']);
params['useMathJax'] = params['useMathJax'] || true; //Set default to true to display math formulae with MathJax, false to use fallback SVG images params['useMathJax'] = params['useMathJax'] || true; //Set default to true to display math formulae with MathJax, false to use fallback SVG images only
params['storedFile'] = getCookie('lastSelectedArchive') || ""; //For packaged Kiwix JS (e.g. with Wikivoyage file), set this to the filename and place file in default storage params['storedFile'] = getCookie('lastSelectedArchive') || "wikipedia_en_ray_charles_2015-06.zimaa"; //For packaged Kiwix JS (e.g. with Wikivoyage file), set this to the filename (for split files, give the first chunk *.zimaa) and place file(s) in default storage
params['falFileToken'] = params['falFileToken'] || "zimfile"; params['falFileToken'] = params['falFileToken'] || "zimfile";
params['falFolderToken'] = params['falFolderToken'] || "zimfilestore"; params['falFolderToken'] = params['falFolderToken'] || "zimfilestore";
if (params['storedFile'] && Windows && Windows.Storage) { //UWP params['localStorage'] = params['localStorage'] || ""; //These will be set programmatically below
params['pickedFile'] = params['pickeFile'] || "";
params['pickedFolder'] = params['pickedFolder'] || "";
if (params['storedFile'] && typeof Windows !== 'undefined' && typeof Windows.Storage !== 'undefined') { //UWP
//DEV change "archives" below if you wish to store local archives in a different location in the installation package //DEV change "archives" below if you wish to store local archives in a different location in the installation package
Windows.ApplicationModel.Package.current.installedLocation.getFolderAsync("archives").done(function (folder) { Windows.ApplicationModel.Package.current.installedLocation.getFolderAsync("archives").done(function (folder) {
if (folder) params['localStorage'] = folder; if (folder) params['localStorage'] = folder;

View File

@ -190,15 +190,20 @@ define(['jquery', 'zimArchiveLoader', 'util', 'uiUtil', 'cookies', 'abstractFile
}); });
$('#btnRescanDeviceStorage').on("click", function (e) { $('#btnRescanDeviceStorage').on("click", function (e) {
document.getElementById('returntoArticle_top').innerHTML = "";
document.getElementById('returntoArticle_bottom').innerHTML = "";
//Stop app from jumping straight into to first archive if user initiated the scan (to give user a chance to select the archive manually)
params['rescan'] = true;
//Reload any ZIM files in local storage (whcih the usar can't otherwise select with the filepicker)
if (params['localStorage']) { if (params['localStorage']) {
scanUWPFolderforArchives(params['localStorage']); scanUWPFolderforArchives(params['localStorage']);
return;
} }
if (storages.length) { if (storages.length) {
searchForArchivesInStorage(); searchForArchivesInStorage();
} else { } else {
displayFileSelect(); displayFileSelect();
$('archiveFiles').click(); //$('archiveFiles').click();
$('btnConfigure').click();
} }
}); });
// Bottom bar : // Bottom bar :
@ -308,6 +313,20 @@ define(['jquery', 'zimArchiveLoader', 'util', 'uiUtil', 'cookies', 'abstractFile
$('#searchingForArticles').hide(); $('#searchingForArticles').hide();
return false; return false;
}); });
// TODO: I've set up two event listeners below because the archive list doesn't "change" if there is only one element in it
// See if this can be simplified.... (but note that keyboard users might not click)
$('#archiveList').on('change', function () {
console.log("***Archive List change event fired")
setLocalArchiveFromArchiveList()
});
$('#archiveList').on('click', function () {
console.log("***Archive List click event fired: checking length of options list")
var comboArchiveList = document.getElementById('archiveList');
if (comboArchiveList.options.length == 1) {
console.log("***Only one item, so, fire away...");
setLocalArchiveFromArchiveList();
}
});
$('input:radio[name=contentInjectionMode]').on('change', function (e) { $('input:radio[name=contentInjectionMode]').on('change', function (e) {
if (checkWarnServiceWorkerMode(this.value)) { if (checkWarnServiceWorkerMode(this.value)) {
document.getElementById('returntoArticle_top').innerHTML = ""; document.getElementById('returntoArticle_top').innerHTML = "";
@ -381,7 +400,7 @@ define(['jquery', 'zimArchiveLoader', 'util', 'uiUtil', 'cookies', 'abstractFile
document.getElementById('cssUIDarkThemeCheck').checked = params['cssUITheme'] == 'dark' ? true : false; document.getElementById('cssUIDarkThemeCheck').checked = params['cssUITheme'] == 'dark' ? true : false;
cssUIThemeSet(params['cssUITheme']); cssUIThemeSet(params['cssUITheme']);
$('input:radio[name=cssInjectionMode]').filter('[value="' + params['cssSource'] + '"]').prop('checked', true); $('input:radio[name=cssInjectionMode]').filter('[value="' + params['cssSource'] + '"]').prop('checked', true);
//First run of new version code //Code below triggers display of modal info box if app is run for the first time, or it has been upgraded to new version
if (cookies.getItem('version') != params['version']) { if (cookies.getItem('version') != params['version']) {
document.getElementById('myModal').style.display = "block"; document.getElementById('myModal').style.display = "block";
document.getElementsByClassName("close")[0].onclick = function () { document.getElementsByClassName("close")[0].onclick = function () {
@ -583,7 +602,7 @@ define(['jquery', 'zimArchiveLoader', 'util', 'uiUtil', 'cookies', 'abstractFile
populateDropDownListOfArchives(directories); populateDropDownListOfArchives(directories);
} }
else { else {
if (storages.length) { if (storages.length || params['localStorage']) {
searchForArchivesInStorage(); searchForArchivesInStorage();
} else { } else {
displayFileSelect(); displayFileSelect();
@ -602,7 +621,11 @@ define(['jquery', 'zimArchiveLoader', 'util', 'uiUtil', 'cookies', 'abstractFile
// If DeviceStorage is available, we look for archives in it // If DeviceStorage is available, we look for archives in it
$("#btnConfigure").click(); $("#btnConfigure").click();
$('#scanningForArchives').show(); $('#scanningForArchives').show();
zimArchiveLoader.scanForArchives(storages, populateDropDownListOfArchives); if (params['localStorage'] && typeof Windows !== 'undefined' && typeof Windows.Storage !== 'undefined') {
scanUWPFolderforArchives(params['localStorage']);
} else {
zimArchiveLoader.scanForArchives(storages, populateDropDownListOfArchives);
}
} }
if ($.isFunction(navigator.getDeviceStorages)) { if ($.isFunction(navigator.getDeviceStorages)) {
@ -612,7 +635,8 @@ define(['jquery', 'zimArchiveLoader', 'util', 'uiUtil', 'cookies', 'abstractFile
}); });
} }
if (Windows && Windows.Storage || (storages !== null && storages.length > 0)) { if ((storages !== null && storages.length > 0) ||
(typeof Windows !== 'undefined' && typeof Windows.Storage !== 'undefined')) {
// Make a fake first access to device storage, in order to ask the user for confirmation if necessary. // Make a fake first access to device storage, in order to ask the user for confirmation if necessary.
// This way, it is only done once at this moment, instead of being done several times in callbacks // This way, it is only done once at this moment, instead of being done several times in callbacks
// After that, we can start looking for archives // After that, we can start looking for archives
@ -682,10 +706,10 @@ define(['jquery', 'zimArchiveLoader', 'util', 'uiUtil', 'cookies', 'abstractFile
// Store the list of archives in a cookie, to avoid rescanning at each start // Store the list of archives in a cookie, to avoid rescanning at each start
cookies.setItem("listOfArchives", archiveDirectories.join('|'), Infinity); cookies.setItem("listOfArchives", archiveDirectories.join('|'), Infinity);
comboArchiveList.size = comboArchiveList.length; comboArchiveList.size = comboArchiveList.length;
//$('#archiveList').on('mouseup', setLocalArchiveFromArchiveList());
$('#archiveList').on('change', setLocalArchiveFromArchiveList); //$(comboArchiveList).on('click', setLocalArchiveFromArchiveList());
if (comboArchiveList.options.length > 0) { if (comboArchiveList.options.length > 0) {
var lastSelectedArchive = cookies.getItem("lastSelectedArchive"); var lastSelectedArchive = cookies.getItem("lastSelectedArchive") || params['storedFile'];
if (lastSelectedArchive !== null && lastSelectedArchive !== undefined && lastSelectedArchive !== "") { if (lastSelectedArchive !== null && lastSelectedArchive !== undefined && lastSelectedArchive !== "") {
// Attempt to select the corresponding item in the list, if it exists // Attempt to select the corresponding item in the list, if it exists
if ($("#archiveList option[value='" + lastSelectedArchive + "']").length > 0) { if ($("#archiveList option[value='" + lastSelectedArchive + "']").length > 0) {
@ -780,7 +804,12 @@ define(['jquery', 'zimArchiveLoader', 'util', 'uiUtil', 'cookies', 'abstractFile
//archiveDirectory = MSApp.createFileFromStorageFile(file); //archiveDirectory = MSApp.createFileFromStorageFile(file);
selectedArchive = zimArchiveLoader.loadArchiveFromDeviceStorage(selectedStorage, archiveDirectory, function (archive) { selectedArchive = zimArchiveLoader.loadArchiveFromDeviceStorage(selectedStorage, archiveDirectory, function (archive) {
// The archive is set : go back to home page to start searching // The archive is set : go back to home page to start searching
$('#btnHome').click(); if (params['rescan']) {
$('#btnConfigure').click()
params['rescan'] = false;
} else {
$('#btnHome').click();
}
}); });
} else { } else {
console.error("The picked file could not be found in the selected folder!"); console.error("The picked file could not be found in the selected folder!");
@ -816,11 +845,16 @@ define(['jquery', 'zimArchiveLoader', 'util', 'uiUtil', 'cookies', 'abstractFile
*/ */
function displayFileSelect() { function displayFileSelect() {
$('#openLocalFiles').show(); $('#openLocalFiles').show();
var comboArchiveList = document.getElementById('archiveList'); //TODO - check if this is necessary or if it causes the archiveList change event to fire
if (comboArchiveList.length > 0) { comboArchiveList.size = comboArchiveList.length; } //Make archive list combo box fit the number of files
//$('#archiveFile').on('change', setLocalArchiveFromFileSelect); //var comboArchiveList = document.getElementById('archiveList');
$('#archiveFile').on('click', pickFileUWP); //UWP FilePicker [kiwix-js-windows #3] //if (comboArchiveList.length > 0) { comboArchiveList.size = comboArchiveList.length; }
$('#archiveFiles').on('click', pickFolderUWP); //UWP FolderPicker if (typeof Windows !== 'undefined' && typeof Windows.Storage !== 'undefined') {
$('#archiveFile').on('click', pickFileUWP); //UWP FilePicker [kiwix-js-windows #3]
$('#archiveFiles').on('click', pickFolderUWP); //UWP FolderPicker
} else {
$('#archiveFile').on('change', setLocalArchiveFromFileSelect);
}
} }
function pickFileUWP() { //Support UWP FilePicker [kiwix-js-windows #3] function pickFileUWP() { //Support UWP FilePicker [kiwix-js-windows #3]
@ -850,11 +884,15 @@ define(['jquery', 'zimArchiveLoader', 'util', 'uiUtil', 'cookies', 'abstractFile
folderPicker.suggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.downloads; folderPicker.suggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.downloads;
folderPicker.fileTypeFilter.replaceAll([".zim", ".dat", ".idx", ".txt", ".zimaa"]); folderPicker.fileTypeFilter.replaceAll([".zim", ".dat", ".idx", ".txt", ".zimaa"]);
folderPicker.pickSingleFolderAsync().then(scanUWPFolderForArchives(folder)); folderPicker.pickSingleFolderAsync().done(function (folder) {
if (folder) {
scanUWPFolderforArchives(folder);
}
});
} }
function scanUWPFolderforArchives (folder) { function scanUWPFolderforArchives (folder) {
if (folder) { if (folder) {
// Application now has read/write access to all contents in the picked folder (including sub-folder contents) // Application now has read/write access to all contents in the picked folder (including sub-folder contents)
// Cache folder so the contents can be accessed at a later time // Cache folder so the contents can be accessed at a later time
Windows.Storage.AccessCache.StorageApplicationPermissions.futureAccessList.addOrReplace(params['falFolderToken'], folder); Windows.Storage.AccessCache.StorageApplicationPermissions.futureAccessList.addOrReplace(params['falFolderToken'], folder);
@ -862,7 +900,7 @@ define(['jquery', 'zimArchiveLoader', 'util', 'uiUtil', 'cookies', 'abstractFile
// Query the folder. // Query the folder.
var query = folder.createFileQuery(); var query = folder.createFileQuery();
query.getFilesAsync().done(function (files) { query.getFilesAsync().done(function (files) {
// Display file list with storage provider and availability. // Display file list
var archiveDisplay = document.getElementById('chooseArchiveFromLocalStorage'); var archiveDisplay = document.getElementById('chooseArchiveFromLocalStorage');
if (!files) { if (!files) {
archiveDisplay.style.display = "inline"; archiveDisplay.style.display = "inline";

View File

@ -32,11 +32,15 @@ params['cssTheme'] = getCookie('cssTheme') || 'light'; //Set default to 'light'
params['cssUITheme'] = getCookie('cssUITheme') || 'light'; //Set default to 'light' or 'dark' to use respective themes for UI params['cssUITheme'] = getCookie('cssUITheme') || 'light'; //Set default to 'light' or 'dark' to use respective themes for UI
params['imageDisplay'] = getCookie('imageDisplay') || true; //Set default to display images from Zim params['imageDisplay'] = getCookie('imageDisplay') || true; //Set default to display images from Zim
params['imageDisplay'] = params['imageDisplay'] == "false" ? false : (params['imageDisplay'] == "true" ? true : params['imageDisplay']); params['imageDisplay'] = params['imageDisplay'] == "false" ? false : (params['imageDisplay'] == "true" ? true : params['imageDisplay']);
params['useMathJax'] = params['useMathJax'] || true; //Set default to true to display math formulae with MathJax, false to use fallback SVG images params['useMathJax'] = params['useMathJax'] || true; //Set default to true to display math formulae with MathJax, false to use fallback SVG images only
params['storedFile'] = getCookie('lastSelectedArchive') || ""; //For packaged Kiwix JS (e.g. with Wikivoyage file), set this to the filename and place file in default storage params['storedFile'] = getCookie('lastSelectedArchive') || "wikipedia_en_ray_charles_2015-06.zimaa"; //For packaged Kiwix JS (e.g. with Wikivoyage file), set this to the filename (for split files, give the first chunk *.zimaa) and place file(s) in default storage
params['falFileToken'] = params['falFileToken'] || "zimfile"; params['falFileToken'] = params['falFileToken'] || "zimfile";
params['falFolderToken'] = params['falFolderToken'] || "zimfilestore"; params['falFolderToken'] = params['falFolderToken'] || "zimfilestore";
if (params['storedFile'] && Windows && Windows.Storage) { //UWP params['localStorage'] = params['localStorage'] || ""; //These will be set programmatically below
params['pickedFile'] = params['pickeFile'] || "";
params['pickedFolder'] = params['pickedFolder'] || "";
if (params['storedFile'] && typeof Windows !== 'undefined' && typeof Windows.Storage !== 'undefined') { //UWP
//DEV change "archives" below if you wish to store local archives in a different location in the installation package //DEV change "archives" below if you wish to store local archives in a different location in the installation package
Windows.ApplicationModel.Package.current.installedLocation.getFolderAsync("archives").done(function (folder) { Windows.ApplicationModel.Package.current.installedLocation.getFolderAsync("archives").done(function (folder) {
if (folder) params['localStorage'] = folder; if (folder) params['localStorage'] = folder;