diff options
| author | Jez Ng | 2012-01-18 22:37:05 +0800 |
|---|---|---|
| committer | Jez Ng | 2012-01-26 02:48:00 -0500 |
| commit | c51d33799eb56675292b65ef0cc04ef97ba02f6f (patch) | |
| tree | 9ee7afd7593842fa91f28d0d1a59bdee4b562368 | |
| parent | 4ad21d921120dba576a75d432b1e2bf4d42f51e3 (diff) | |
| download | vimium-c51d33799eb56675292b65ef0cc04ef97ba02f6f.tar.bz2 | |
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.
| -rw-r--r-- | background/settings.js | 15 | ||||
| -rw-r--r-- | background_page.html | 11 | ||||
| -rw-r--r-- | lib/utils.js | 8 | ||||
| -rw-r--r-- | manifest.json | 2 | ||||
| -rw-r--r-- | 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 @@ <script type="text/javascript" src="lib/utils.js"></script> <script type="text/javascript" src="background/settings.js"></script> <script type="text/javascript" charset="utf-8"> - // Chromium #15242 will make this XHR request to access the manifest unnecessary. - var manifestRequest = new XMLHttpRequest(); - manifestRequest.open("GET", chrome.extension.getURL("manifest.json"), false); - manifestRequest.send(null); - - var currentVersion = JSON.parse(manifestRequest.responseText).version; + var currentVersion = utils.getCurrentVersion(); var tabQueue = {}; // windowId -> Array var openTabs = {}; // tabId -> object with various tab properties @@ -617,7 +612,7 @@ // installs. if (!settings.get("previousVersion")) settings.set("previousVersion", currentVersion); - return compareVersions(currentVersion, localStorage.previousVersion) == 1; + return compareVersions(currentVersion, settings.get("previousVersion")) == 1; } function openOptionsPageInNewTab() { @@ -695,7 +690,7 @@ // In version 1.22, we changed the mapping for "d" and "u" to be scroll page down/up instead of close // and restore tab. For existing users, we want to preserve existing behavior for them by adding some // custom key mappings on their behalf. - if (localStorage.previousVersion == "1.21") { + if (settings.get("previousVersion") == "1.21") { var customKeyMappings = settings.get("keyMappings") || ""; if ((keyToCommandRegistry["d"] || {}).command == "scrollPageDown") customKeyMappings += "\nmap d removeTab"; diff --git a/lib/utils.js b/lib/utils.js index df325138..8aada3a1 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -1,4 +1,12 @@ var utils = { + getCurrentVersion: function() { + // Chromium #15242 will make this XHR request to access the manifest unnecessary. + var manifestRequest = new XMLHttpRequest(); + manifestRequest.open("GET", chrome.extension.getURL("manifest.json"), false); + manifestRequest.send(null); + return JSON.parse(manifestRequest.responseText).version; + }, + /* * Takes a dot-notation object string and call the function * that it points to with the correct value for 'this'. diff --git a/manifest.json b/manifest.json index 23f80f77..2f863bc3 100644 --- a/manifest.json +++ b/manifest.json @@ -1,6 +1,6 @@ { "name": "Vimium", - "version": "1.30", + "version": "1.31", "description": "The Hacker's Browser. Vimium provides keyboard shortcuts for navigation and control in the spirit of Vim.", "icons": { "16": "icons/icon16.png", "48": "icons/icon48.png", diff --git a/options.html b/options.html index e4142b4d..02186412 100644 --- a/options.html +++ b/options.html @@ -1,6 +1,7 @@ <html> <head> <title>Vimium Options</title> + <script src="lib/utils.js"></script> <script src="background/settings.js"></script> <style type="text/css" media="screen"> body { |
