From 541e2ab292be219d377413774db988650297060b Mon Sep 17 00:00:00 2001 From: Jaifroid Date: Sun, 30 Aug 2020 09:21:28 +0100 Subject: [PATCH] Prevent loading error when packaged file name has changed Former-commit-id: 97d5de30a155025db8ad5857e032eec69779d1b5 [formerly c666363343d4f60df0538a68d9769aebe3ec5279 [formerly 2a1ca5bad90d5b511b93e9548a631891d291e1f8]] Former-commit-id: 6d45fbbf3e93c6d6fa14f7d7cf5ec9b1b05056f0 Former-commit-id: b01a714c8cfcde213e5bec0d1532c681645845d5 --- www/js/app.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/www/js/app.js b/www/js/app.js index fc153287..319283eb 100644 --- a/www/js/app.js +++ b/www/js/app.js @@ -1738,19 +1738,21 @@ define(['jquery', 'zimArchiveLoader', 'uiUtil', 'util', 'cache', 'images', 'cook setLocalArchiveFromArchiveList(); } else { // 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 + // Let's first check if this is a Store UWP/PWA that has a different archive package from that last selected + // (or from that indicated in init.js) if (typeof Windows !== 'undefined' && typeof Windows.Storage !== 'undefined' && - params.storedFile === params.packagedFile && cookies.getItem('lastSelectedArchive') !== params.storedFile) { + params.packagedFile && cookies.getItem('lastSelectedArchive') !== params.packagedFile) { // 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); + params.storedFile = archiveDirectories[0]; + params.fileVersion = ~params.fileVersion.indexOf(params.storedFile.replace(/\.zim\w?\w?$/i, '')) ? params.fileVersion : params.storedFile; + setLocalArchiveFromArchiveList(params.storedFile); } 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.

'; + if (document.getElementById('configuration').style.display == 'none') + document.getElementById('btnConfigure').click(); document.getElementById('alert-content').innerHTML = message; $('#alertModal').off('hide.bs.modal'); $('#alertModal').on('hide.bs.modal', function () { @@ -1760,8 +1762,6 @@ define(['jquery', 'zimArchiveLoader', 'uiUtil', 'util', 'cache', 'images', 'cook backdrop: 'static', keyboard: true }); - if (document.getElementById('configuration').style.display == 'none') - document.getElementById('btnConfigure').click(); } } }