From c72d8eceb3d638b04bbbcb3ba0f084c72960f4e5 Mon Sep 17 00:00:00 2001 From: Jaifroid Date: Wed, 9 Jun 2021 14:48:42 +0100 Subject: [PATCH] Try to sort out startup upgrade crashes once and for all Former-commit-id: 59feb3fcea96526f31840238879bad4f92d2ea5e [formerly 786e0f9a70944db79aaa9015d3e5cb4e51a4acd1 [formerly ab44f4804e65ca9d2957512b65ea1af7b56bb102]] Former-commit-id: 71980d80f9c0be53d09f427118adc9ed0087dcb6 Former-commit-id: 6381bfdb7cf236cd3c8f61ab0b6528d5946c797d --- www/js/app.js | 10 +++++----- www/js/init.js | 14 +++++++++++--- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/www/js/app.js b/www/js/app.js index 2edb0ad4..9d4ffc8e 100644 --- a/www/js/app.js +++ b/www/js/app.js @@ -1564,11 +1564,11 @@ define(['jquery', 'zimArchiveLoader', 'uiUtil', 'util', 'cache', 'images', 'sett firstRun = true; // If we have an update and the last selected archive is the packaged file, it is best not to preserve last read article - var packagedFileStub = params.packagedFile.replace(/_[\d-]+\.zim\w?\w?$/, ''); - if (~params.storedFile.indexOf(packagedFileStub)) { - params.lastPageVisit = ''; - params.storedFile = params.packagedFile; - } + // var packagedFileStub = params.packagedFile.replace(/_[\d-]+\.zim\w?\w?$/, ''); + // if (~params.storedFile.indexOf(packagedFileStub)) { + // params.lastPageVisit = ''; + // params.storedFile = params.packagedFile; + // } // THIS IS NOW DONE IN init.js // Update the installed version if (settingsStore.getItem('PWAInstalled')) { diff --git a/www/js/init.js b/www/js/init.js index 888a47a2..6e71075e 100644 --- a/www/js/init.js +++ b/www/js/init.js @@ -49,7 +49,7 @@ var params = {}; */ var appstate = {}; /******** UPDATE VERSION IN pwabuilder-sw.js TO MATCH VERSION AND CHECK PWASERVER BELOW!!!!!!! *******/ -params['version'] = "1.4.0-RC5"; //DEV: Manually update this version when there is a new release: it is compared to the Settings Store "version" in order to show first-time info, and the cookie is updated in app.js +params['version'] = "1.4.0-Wikivoyage"; //DEV: Manually update this version when there is a new release: it is compared to the Settings Store "version" in order to show first-time info, and the cookie is updated in app.js /******* UPDATE THIS ^^^^^^ IN service worker AND PWA-SERVER BELOW !! ********************/ params['packagedFile'] = getSetting('packagedFile') || "wikipedia_en_100_maxi_2021-05.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'] = "archives"; //The directory containing the packaged archive(s) (relative to app's root directory) @@ -101,9 +101,9 @@ params['storedFilePath'] = getSetting('lastSelectedArchivePath'); params.storedFilePath = params.storedFilePath ? decodeURIComponent(params.storedFilePath) : params.archivePath + '/' + params.packagedFile; params.storedFilePath = launchArguments ? launchArguments.files[0].path || '' : params.storedFilePath; params.originalPackagedFile = params.packagedFile; -params['localStorage'] = params['localStorage'] || ""; +params['localStorage'] = ""; params['pickedFile'] = launchArguments ? launchArguments.files[0] : ""; -params['pickedFolder'] = params['pickedFolder'] || ""; +params['pickedFolder'] = ""; params['themeChanged'] = params['themeChanged'] || false; params['printIntercept'] = false; params['printInterception'] = false; @@ -253,6 +253,14 @@ function getAppType() { } // Set up storage types +// First check that we have not simply upgraded the app and the packaged file +params.packagedFileStub = params.packagedFile ? params.packagedFile.replace(/_[\d-]+\.zim\w?\w?$/, ''): null; +if (params.packagedFileStub && params.version !== getSetting('version') && ~params.storedFile.indexOf(params.packagedFileStub)) { + console.log('The packaged archive has been upgraded: resetting file pointers to point to ' + params.packagedFile); + params.lastPageVisit = ''; + params.storedFile = params.packagedFile; + params.storedFilePath = params.archivePath + '/' + params.packagedFile; +} if (params.storedFile && typeof Windows !== 'undefined' && typeof Windows.Storage !== 'undefined') { //UWP Windows.ApplicationModel.Package.current.installedLocation.getFolderAsync(params.archivePath).done(function (folder) { params.localStorage = folder;