From c51d33799eb56675292b65ef0cc04ef97ba02f6f Mon Sep 17 00:00:00 2001 From: Jez Ng Date: Wed, 18 Jan 2012 22:37:05 +0800 Subject: Add migration code for old localStorage values. Finish up the wrapping of localStorage. All background code should now modify localStorage via settings.js rather than doing it directly. --- background/settings.js | 15 +++++++++++++++ background_page.html | 11 +++-------- lib/utils.js | 8 ++++++++ manifest.json | 2 +- options.html | 1 + 5 files changed, 28 insertions(+), 9 deletions(-) diff --git a/background/settings.js b/background/settings.js index 4792429d..51ac053c 100644 --- a/background/settings.js +++ b/background/settings.js @@ -35,6 +35,19 @@ var settings = { nextPatterns: "next,more,>,\u2192,\xbb,\u226b,>>", }, + init: function() { + // settingsVersion was introduced in v1.31, and is used to coordinate data migration. We do not use + // previousVersion as it is used to coordinate the display of the upgrade message, and is not updated + // early enough when the extension loads. + // 1.31 was also the version where we converted all localStorage values to JSON. + if (!this.has("settingsVersion")) { + for (var key in localStorage) { + localStorage[key] = JSON.stringify(localStorage[key]); + } + this.set("settingsVersion", utils.getCurrentVersion()); + } + }, + get: function(key) { if (!(key in localStorage)) return this.defaultSettings[key]; @@ -59,3 +72,5 @@ var settings = { }, }; + +settings.init(); diff --git a/background_page.html b/background_page.html index 7f8bb2a6..d72f3fc9 100644 --- a/background_page.html +++ b/background_page.html @@ -5,12 +5,7 @@