diff --git a/KiwixWebApp.jsproj b/KiwixWebApp.jsproj index eb25890f..557a85d1 100644 --- a/KiwixWebApp.jsproj +++ b/KiwixWebApp.jsproj @@ -60,7 +60,7 @@ 10.0.18362.0 10.0.10240.0 $(VersionNumberMajor).$(VersionNumberMinor) - en-gb + en-GB KiwixWebApp_StoreKey.pfx False False diff --git a/www/js/app.js b/www/js/app.js index 0efce8a7..233138e7 100644 --- a/www/js/app.js +++ b/www/js/app.js @@ -681,7 +681,7 @@ define(['jquery', 'zimArchiveLoader', 'uiUtil', 'util', 'utf8', 'images', 'cooki document.getElementById('libraryArea').style.borderColor = ''; document.getElementById('libraryArea').style.borderStyle = ''; var currentArchive = document.getElementById('currentArchive'); - if (params.packagedFile && params.storedFile && params.storedFile != params.packagedFile) { + if (params.packagedFile && params.storedFile && params.storedFile !== params.packagedFile) { currentArchive.innerHTML = "Currently loaded archive: " + params.storedFile.replace(/\.zim$/i, "") + ""; currentArchive.style.display = "block"; document.getElementById('downloadLinksText').style.display = "none"; @@ -691,9 +691,17 @@ define(['jquery', 'zimArchiveLoader', 'uiUtil', 'util', 'utf8', 'images', 'cooki document.getElementById('downloadLinksText').style.display = "block"; currentArchive.style.display = "none"; } - //else { - // document.getElementById('rescanStorage').style.display = "none"; - //} + // Populate version info + var versionSpans = document.getElementsByClassName('version'); + for (var i = 0; i < versionSpans.length; i++) { + versionSpans[i].innerHTML = i ? params.version : params.version.replace(/\s+.*$/, ""); + } + var fileVersionDivs = document.getElementsByClassName('fileVersion'); + for (i = 0; i < fileVersionDivs.length; i++) { + fileVersionDivs[i].innerHTML = i ? params.fileVersion.replace(/\s+.+$/, "") : params.fileVersion; + } + document.getElementById('logUpdate').innerHTML = document.getElementById('update').innerHTML.match(/]*>[\s\S]+/i); + document.getElementById('logFeatures').innerHTML = document.getElementById('features').innerHTML; // Show the selected content in the page $('#about').hide(); $('#configuration').hide(); @@ -1646,26 +1654,35 @@ define(['jquery', 'zimArchiveLoader', 'uiUtil', 'util', 'utf8', 'images', 'cooki cookies.setItem("lastSelectedArchive", lastSelectedArchive, Infinity); } // Set the localArchive as the last selected (if none has been selected previously, wait for user input) - //if (success || comboArchiveList.options.length == 1) { if (success) { setLocalArchiveFromArchiveList(); } else { - // We can't find lastSelectedArchive in the archive list, so let's ask the user to pick it - //uiUtil.systemAlert(lastSelectedArchive + ' could not be found in the known list of archives!'); - var message = '

We could not find the archive ' + lastSelectedArchive + '!

Please select its location...

'; - if (typeof Windows !== 'undefined' && typeof Windows.Storage !== 'undefined') - message += '

Note: If you drag-drop an archive into this UWP app, then it will have to be dragged again each time you launch the app. Try double-clicking on the archive instead, or select it using the controls on this page.

'; - document.getElementById('alert-content').innerHTML = message; - $('#alertModal').off('hide.bs.modal'); - $('#alertModal').on('hide.bs.modal', function () { - displayFileSelect(); - }); - $('#alertModal').modal({ - backdrop: 'static', - keyboard: true - }); - if (document.getElementById('configuration').style.display == 'none') - document.getElementById('btnConfigure').click(); + // We can't find lastSelectedArchive in the archive list + // Let's first check if this is a Store UWP/PWA that has a different archive package from that indicated in init.js + if (typeof Windows !== 'undefined' && typeof Windows.Storage !== 'undefined' && + params.storedFile === params.packagedFile && cookies.getItem('lastSelectedArchive') !== params.storedFile) { + // We didn't pick this file previously, so select first one in list + params.fileVersion = archiveDirectories[0]; + params.packagedFile = params.fileVersion; + params.storedFile = params.fileVersion; + setLocalArchiveFromArchiveList(params.fileVersion); + } else { + // It's genuinely no longer available, so let's ask the user to pick it + var message = '

We could not find the archive ' + lastSelectedArchive + '!

Please select its location...

'; + if (typeof Windows !== 'undefined' && typeof Windows.Storage !== 'undefined') + message += '

Note: If you drag-drop an archive into this UWP app, then it will have to be dragged again each time you launch the app. Try double-clicking on the archive instead, or select it using the controls on this page.

'; + document.getElementById('alert-content').innerHTML = message; + $('#alertModal').off('hide.bs.modal'); + $('#alertModal').on('hide.bs.modal', function () { + displayFileSelect(); + }); + $('#alertModal').modal({ + backdrop: 'static', + keyboard: true + }); + if (document.getElementById('configuration').style.display == 'none') + document.getElementById('btnConfigure').click(); + } } } } else { @@ -2013,6 +2030,9 @@ define(['jquery', 'zimArchiveLoader', 'uiUtil', 'util', 'utf8', 'images', 'cooki function loadPackagedArchive() { // Reload any ZIM files in local storage (whcih the user can't otherwise select with the filepicker) if (params.localStorage) { + // Reset params.packagedFile to its original value, in case we manipulated it previously + params.packagedFile = params.originalPackagedFile; + params.pickedFile = ''; params.storedFile = params.packagedFile || ''; params.pickedFolder = params.localStorage; scanUWPFolderforArchives(params.localStorage); diff --git a/www/js/init.js b/www/js/init.js index c03eb605..652b96d1 100644 --- a/www/js/init.js +++ b/www/js/init.js @@ -33,7 +33,7 @@ var state = {}; var params = {}; params['version'] = "0.9.9.97 Beta"; //DEV: This value is compared to the cookie "version" in order to show first-time info, and the cookie is updated in app.js params['packagedFile'] = "wikipedia_en_ray_charles.zim"; //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['archivePath'] = "archive"; //The directory containing the packaged archive(s) (relative to app's root directory) +params['archivePath'] = "archives"; //The directory containing the packaged archive(s) (relative to app's root directory) params['fileVersion'] = "wikipedia_en_ray_charles_maxi_2019-08.zim (14-Aug-2019)"; //Use generic name for actual file, and give version here params['cachedStartPage'] = false; //If you have cached the start page for quick start, give its URI here params['kiwixDownloadLink'] = "https://download.kiwix.org/zim/"; //Include final slash @@ -66,7 +66,8 @@ params['storedFile'] = getCookie('lastSelectedArchive') || params['packagedFile' params.storedFile = launchArguments ? launchArguments.files[0].name : params.storedFile; params['storedFilePath'] = getCookie('lastSelectedArchivePath'); params.storedFilePath = params.storedFilePath ? decodeURIComponent(params.storedFilePath) : params.archivePath + '/' + params.packagedFile; -params.storedFilePath = launchArguments ? launchArguments.files[0].path || '' : params.storedFilePath; +params.storedFilePath = launchArguments ? launchArguments.files[0].path || '' : params.storedFilePath; +params.originalPackagedFile = params.packagedFile; params['falFileToken'] = params['falFileToken'] || "zimfile"; //UWP support params['falFolderToken'] = params['falFolderToken'] || "zimfilestore"; //UWP support params['localStorage'] = params['localStorage'] || ""; @@ -125,33 +126,21 @@ document.getElementById('hideToolbarsCheck').indeterminate = params.hideToolbars document.getElementById('hideToolbarsCheck').readOnly = params.hideToolbars === "top"; document.getElementById('hideToolbarsState').innerHTML = (params.hideToolbars === "top" ? "top" : params.hideToolbars ? "both" : "never"); -var versionSpans = document.getElementsByClassName('version'); -for (var i = 0; i < versionSpans.length; i++) { - versionSpans[i].innerHTML = i ? params.version : params.version.replace(/\s+.*$/, ""); -} -var fileVersionDivs = document.getElementsByClassName('fileVersion'); -for (i = 0; i < fileVersionDivs.length; i++) { - fileVersionDivs[i].innerHTML = i ? params.fileVersion.replace(/\s+.+$/, "") : params.fileVersion; -} -document.getElementById('logUpdate').innerHTML = document.getElementById('update').innerHTML.match(/]*>[\s\S]+/i); -document.getElementById('logFeatures').innerHTML = document.getElementById('features').innerHTML; - //Set up packaged Electron app if (!params.pickedFile && params.storedFile && typeof window.fs !== 'undefined') { params.pickedFile = params.storedFile; } //Set up storage types 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 - Windows.ApplicationModel.Package.current.installedLocation.getFolderAsync("archives").done(function (folder) { - if (folder) params.localStorage = folder; + Windows.ApplicationModel.Package.current.installedLocation.getFolderAsync(params.archivePath).done(function (folder) { + params.localStorage = folder; }, function (err) { console.error("This app doesn't appear to have access to local storage!"); }); var futureAccessList = Windows.Storage.AccessCache.StorageApplicationPermissions.futureAccessList; if (futureAccessList.containsItem(params.falFolderToken)) { - futureAccessList.getFolderAsync(params.falFolderToken).then(function (folder) { - if (folder) params.pickedFolder = folder; + futureAccessList.getFolderAsync(params.falFolderToken).done(function (folder) { + params.pickedFolder = folder; }, function (err) { console.error("The previously picked folder is no longer accessible: " + err.message); }); @@ -165,7 +154,7 @@ if (params.storedFile && typeof Windows !== 'undefined' && typeof Windows.Storag if (!params.pickedFile && futureAccessList.containsItem(params.falFileToken)) { params.pickedFile = ''; futureAccessList.getFileAsync(params.falFileToken).done(function (file) { - if (file && file.name === params.storedFile) params.pickedFile = file; + if (file.name === params.storedFile) params.pickedFile = file; }, function (err) { console.error("The previously picked file is no longer accessible: " + err.message); });