diff options
Diffstat (limited to 'lib/settings.coffee')
| -rw-r--r-- | lib/settings.coffee | 22 | 
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. | 
