aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorStephen Blott2017-04-18 05:47:15 +0100
committerGitHub2017-04-18 05:47:15 +0100
commit8058a54fd5a6a2f0e1a62a3a66f837a07045396e (patch)
treea7e0949cd41b8fa8d03fa27140f8b815ec1d64c4 /lib
parent84723d7561d0cc12f54a6d388dcd505ddd6105ac (diff)
parentb0fc681480da40ec0bdb43773275ef7181c78cf1 (diff)
downloadvimium-8058a54fd5a6a2f0e1a62a3a66f837a07045396e.tar.bz2
Merge pull request #2476 from mrmr1993/firefox
Improve firefox support
Diffstat (limited to 'lib')
-rw-r--r--lib/settings.coffee22
1 files changed, 16 insertions, 6 deletions
diff --git a/lib/settings.coffee b/lib/settings.coffee
index e16261d0..51f6b504 100644
--- a/lib/settings.coffee
+++ b/lib/settings.coffee
@@ -10,9 +10,11 @@
#
# In all cases except Settings.defaults, values are stored as jsonified strings.
+storageArea = if chrome.storage.sync? then "sync" else "local"
+
Settings =
debug: false
- storage: chrome.storage.sync
+ storage: chrome.storage[storageArea]
cache: {}
isLoaded: false
onLoadedCallbacks: []
@@ -25,6 +27,14 @@ Settings =
@cache = if Utils.isBackgroundPage() then localStorage else extend {}, localStorage
@runOnLoadedCallbacks()
+ # Test chrome.storage.sync to see if it is enabled.
+ # NOTE(mrmr1993, 2017-04-18): currently the API is defined in FF, but it is disabled behind a flag in
+ # about:config. Every use sets chrome.runtime.lastError, so we use that to check whether we can use it.
+ chrome.storage.sync.get null, =>
+ if chrome.runtime.lastError
+ storageArea = "local"
+ @storage = chrome.storage[storageArea]
+
chrome.storage.local.get null, (localItems) =>
localItems = {} if chrome.runtime.lastError
@storage.get null, (syncedItems) =>
@@ -32,7 +42,7 @@ Settings =
@handleUpdateFromChromeStorage key, value for own key, value of extend localItems, syncedItems
chrome.storage.onChanged.addListener (changes, area) =>
- @propagateChangesFromChromeStorage changes if area == "sync"
+ @propagateChangesFromChromeStorage changes if area == storageArea
@runOnLoadedCallbacks()
@@ -71,9 +81,9 @@ Settings =
if @shouldSyncKey key
if shouldSetInSyncedStorage
setting = {}; setting[key] = @cache[key]
- @log " chrome.storage.sync.set(#{key})"
+ @log " chrome.storage.#{storageArea}.set(#{key})"
@storage.set setting
- if Utils.isBackgroundPage()
+ if Utils.isBackgroundPage() and storageArea == "sync"
# Remove options installed by the "copyNonDefaultsToChromeStorage-20150717" migration; see below.
@log " chrome.storage.local.remove(#{key})"
chrome.storage.local.remove key
@@ -98,7 +108,7 @@ Settings =
nuke: (key) ->
delete localStorage[key]
chrome.storage.local.remove key
- chrome.storage.sync.remove key
+ chrome.storage.sync?.remove key
# For development only.
log: (args...) ->
@@ -169,7 +179,7 @@ Settings =
# az: http://www.amazon.com/s/?field-keywords=%s Amazon
# qw: https://www.qwant.com/?q=%s Qwant
"""
- newTabUrl: "chrome://newtab"
+ newTabUrl: "about:newtab"
grabBackFocus: false
regexFindMode: false
waitForEnterForFilteredHints: false # Note: this defaults to true for new users; see below.