diff --git a/pwabuilder-sw.js b/pwabuilder-sw.js
index ea4c0221..f6098650 100644
--- a/pwabuilder-sw.js
+++ b/pwabuilder-sw.js
@@ -4,7 +4,7 @@
// App version number - ENSURE IT MATCHES VALUE IN init.js
// DEV: Changing this will cause the browser to recognize that the Service Worker has changed, and it will download and
// install a new copy
-const appVersion = '1.1.4-RP5';
+const appVersion = '1.1.4-RP6';
// Kiwix ZIM Archive Download Server in regex form
// DEV: The server URL is defined in init.js, but is not available to us in SW
diff --git a/www/index.html b/www/index.html
index 14d0d5fb..d7d9d48f 100644
--- a/www/index.html
+++ b/www/index.html
@@ -529,7 +529,7 @@
diff --git a/www/js/app.js b/www/js/app.js
index 03641589..9b00f2e3 100644
--- a/www/js/app.js
+++ b/www/js/app.js
@@ -1368,12 +1368,20 @@ define(['jquery', 'zimArchiveLoader', 'uiUtil', 'util', 'cache', 'images', 'sett
//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 (settingsStore.getItem('version') !== params.version) {
firstRun = true;
- // Make user re-pick file if we have upgraded (it's less confusing than filehandle errors)
- settingsStore.removeItem('listOfArchives');
+
+ // Make user re-pick file if we have upgraded (it's less confusing than filehandle errors) - NOT NEEDED, remove in due course
+ // settingsStore.removeItem('listOfArchives');
+
+ // Update the installed version
if (params.PWAInstalled) {
params.PWAInstalled = params.version;
settingsStore.setItem('PWAInstalled', params.PWAInstalled);
- }
+ }
+ // One-time cleanup of idxDB files to delete deprecated databases if possible
+ cache.idxDB('deleteNonCurrent', function (result) {
+ if (result === false) console.log('Unable to delete old idxDB databases (this is normal in non-Chromium browsers');
+ else console.log('Deleted ' + result + ' deprecated database(s).');
+ });
// On some platforms, bootstrap's jQuery functions have not been injected yet, so we have to run in a timeout
setTimeout(function () {
$('#myModal').modal({
diff --git a/www/js/init.js b/www/js/init.js
index 0aa42746..329f2da4 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 *******/
-params['version'] = "1.1.4-RP5"; //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.1.4-RP6"; //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 serveice worker!! ********************/
params['packagedFile'] = "wikipedia_en_100_maxi.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)
diff --git a/www/js/lib/cache.js b/www/js/lib/cache.js
index f70c4e2c..5d1be7fe 100644
--- a/www/js/lib/cache.js
+++ b/www/js/lib/cache.js
@@ -23,7 +23,8 @@
'use strict';
define(['q', 'settingsStore', 'uiUtil'], function(Q, settingsStore, uiUtil) {
- const CACHE = 'kiwix-precache-' + params.version; // Set the database or cache name here
+ const CACHEAPI = 'kiwix-precache-' + params.version; // Set the database or cache name here
+ const CACHEIDB = 'kiwix-assetsCache'; // For idxDB we don't want the name to change
var objStore = 'kiwix-assets'; // Name of the object store
// DEV: Regex below defines the permitted key types for the cache; add further types as needed
@@ -111,7 +112,7 @@ define(['q', 'settingsStore', 'uiUtil'], function(Q, settingsStore, uiUtil) {
case 'cacheAPI':
type = 'cacheAPI';
description = 'CacheAPI';
- caches.open(CACHE).then(function (cache) {
+ caches.open(CACHEAPI).then(function (cache) {
cache.keys().then(function (keys) {
callback({'type': type, 'description': description, 'count': keys.length});
});
@@ -134,7 +135,8 @@ define(['q', 'settingsStore', 'uiUtil'], function(Q, settingsStore, uiUtil) {
* on the database
*
* @param {String} keyOrCommand The key of the value to be written or read, or commands 'clear' (clears objStore),
- * 'count' (counts number of objects in objStore), 'delete' (deletes a record with key passed in valueOrCallback)
+ * 'count' (counts number of objects in objStore), 'delete' (deletes a record with key passed in valueOrCallback),
+ * 'deleteNonCurrent' (deletes all databases that do not match CACHEIDB - but only works in Chromium currently)
* @param {Variable} valueOrCallback The value to write, or a callback function for read and command transactions
* @param {Function} callback Callback for write transactions only
*/
@@ -145,9 +147,29 @@ define(['q', 'settingsStore', 'uiUtil'], function(Q, settingsStore, uiUtil) {
rtnFn(false);
return;
}
+
+ // Delete all non-curren IdxDB databases (only works in Chromium currently)
+ if (keyOrCommand === 'deleteNonCurrent') {
+ if (indexedDB.databases) {
+ var result = 0;
+ indexedDB.databases().then(function (dbs) {
+ dbs.forEach(function (db) {
+ if (db.name !== CACHEIDB) {
+ result++;
+ indexedDB.deleteDatabase(db.name);
+ }
+ });
+ }).then(function () {
+ rtnFn(result);
+ });
+ } else {
+ rtnFn(false);
+ }
+ return;
+ }
// Open (or create) the database
- var open = indexedDB.open(CACHE, 1);
+ var open = indexedDB.open(CACHEIDB, 1);
open.onerror = function(e) {
// Suppress error reporting if testing (older versions of Firefox support indexedDB but cannot use it with
@@ -222,14 +244,14 @@ define(['q', 'settingsStore', 'uiUtil'], function(Q, settingsStore, uiUtil) {
var rtnFn = callback || valueOrCallback;
// Process commands
if (keyOrCommand === 'clear') {
- caches.delete(CACHE).then(rtnFn);
+ caches.delete(CACHEAPI).then(rtnFn);
} else if (keyOrCommand === 'delete') {
- caches.open(CACHE).then(function(cache) {
+ caches.open(CACHEAPI).then(function(cache) {
cache.delete(value).then(rtnFn);
});
} else if (value === null) {
// Request retrieval of data
- caches.open(CACHE).then(function(cache) {
+ caches.open(CACHEAPI).then(function(cache) {
cache.match('../' + keyOrCommand).then(function(response) {
if (!response) {
rtnFn(null);
@@ -245,7 +267,7 @@ define(['q', 'settingsStore', 'uiUtil'], function(Q, settingsStore, uiUtil) {
});
} else {
// Request storing of data in cache
- caches.open(CACHE).then(function(cache) {
+ caches.open(CACHEAPI).then(function(cache) {
// Construct a Response from value
var response = new Response(value);
cache.put('../' + keyOrCommand, response).then(function() {