diff options
| author | mrmr1993 | 2015-04-27 16:35:58 +0100 | 
|---|---|---|
| committer | mrmr1993 | 2015-05-29 12:05:59 +0100 | 
| commit | 960ccc627c4e55a7bdc53eead255270d9504a8bf (patch) | |
| tree | f2a0e6f216b957c58cfd0ef375121a5c27a6cdd0 /background_scripts | |
| parent | 9960e8f01ab8477151465af936d7cb14b84fb125 (diff) | |
| download | vimium-960ccc627c4e55a7bdc53eead255270d9504a8bf.tar.bz2 | |
Move Sync.storeAndPropagate to Settings.storeAndPropagate
This function does nothing related to Sync, and only affects Settings.
Diffstat (limited to 'background_scripts')
| -rw-r--r-- | background_scripts/settings.coffee | 43 | 
1 files changed, 19 insertions, 24 deletions
diff --git a/background_scripts/settings.coffee b/background_scripts/settings.coffee index 5442a1cf..81bc8589 100644 --- a/background_scripts/settings.coffee +++ b/background_scripts/settings.coffee @@ -5,10 +5,6 @@  # * Sync.fetchAsync() polls chrome.storage.sync at startup, similarly propagating  #   changes to localStorage and into vimium's internal state.  # -# Changes are propagated into vimium's state using the same mechanism -# (Settings.performPostUpdateHook) that is used when options are changed on -# the options page. -#  # The effect is best-effort synchronization of vimium options/settings between  # chrome/vimium instances.  # @@ -33,30 +29,12 @@ root.Sync = Sync =      @storage.get null, (items) =>        unless chrome.runtime.lastError          for own key, value of items -          @storeAndPropagate key, value +          Settings.storeAndPropagate key, value if @shouldSyncKey key    # Asynchronous message from synced storage.    handleStorageUpdate: (changes, area) ->      for own key, change of changes -      @storeAndPropagate key, change?.newValue - -  # Only ever called from asynchronous synced-storage callbacks (fetchAsync and handleStorageUpdate). -  storeAndPropagate: (key, value) -> -    return unless key of Settings.defaults -    return if not @shouldSyncKey key -    return if value and key of localStorage and localStorage[key] is value -    defaultValue = Settings.defaults[key] -    defaultValueJSON = JSON.stringify(defaultValue) - -    if value and value != defaultValueJSON -      # Key/value has been changed to non-default value at remote instance. -      localStorage[key] = value -      Settings.performPostUpdateHook key, JSON.parse(value) -    else -      # Key has been reset to default value at remote instance. -      if key of localStorage -        delete localStorage[key] -      Settings.performPostUpdateHook key, defaultValue +      Settings.storeAndPropagate key, change?.newValue if @shouldSyncKey key    # Only called synchronously from within vimium, never on a callback.    # No need to propagate updates to the rest of vimium, that's already been done. @@ -112,6 +90,23 @@ root.Settings = Settings =    performPostUpdateHook: (key, value) ->      @postUpdateHooks[key] value if @postUpdateHooks[key] +  # Only ever called from asynchronous synced-storage callbacks (fetchAsync and handleStorageUpdate). +  storeAndPropagate: (key, value) -> +    return unless key of @defaults +    return if value and key of localStorage and localStorage[key] is value +    defaultValue = @defaults[key] +    defaultValueJSON = JSON.stringify(defaultValue) + +    if value and value != defaultValueJSON +      # Key/value has been changed to non-default value at remote instance. +      localStorage[key] = value +      @performPostUpdateHook key, JSON.parse(value) +    else +      # Key has been reset to default value at remote instance. +      if key of localStorage +        delete localStorage[key] +      @performPostUpdateHook key, defaultValue +    # options.coffee and options.html only handle booleans and strings; therefore all defaults must be booleans    # or strings    defaults:  | 
