diff options
| author | mrmr1993 | 2015-05-31 16:35:09 +0100 |
|---|---|---|
| committer | mrmr1993 | 2015-05-31 17:51:01 +0100 |
| commit | 0de6b076271b673d0e1dcc2b74b2ddd1646bf08e (patch) | |
| tree | c0e03c0c96ef2cc5057a983d142de579e5d7bf41 /content_scripts/vimium_frontend.coffee | |
| parent | 257a219fdfd33c49b565a93dff9d785824533d2a (diff) | |
| download | vimium-0de6b076271b673d0e1dcc2b74b2ddd1646bf08e.tar.bz2 | |
Rewrite settings as a tight wrapper around Settings, tweaks for tests
Diffstat (limited to 'content_scripts/vimium_frontend.coffee')
| -rw-r--r-- | content_scripts/vimium_frontend.coffee | 31 |
1 files changed, 6 insertions, 25 deletions
diff --git a/content_scripts/vimium_frontend.coffee b/content_scripts/vimium_frontend.coffee index c8c83029..c603e15f 100644 --- a/content_scripts/vimium_frontend.coffee +++ b/content_scripts/vimium_frontend.coffee @@ -65,37 +65,18 @@ settings = searchEngines: null init: -> - @port = chrome.runtime.connect name: "settings" - @port.onMessage.addListener (response) => @receiveMessage response + @port = true + Settings.init() - # If the port is closed, the background page has gone away (since we never close it ourselves). Stub the - # settings object so we don't keep trying to connect to the extension even though it's gone away. - @port.onDisconnect.addListener => - @port = null - for own property, value of this - # @get doesn't depend on @port, so we can continue to support it to try and reduce errors. - @[property] = (->) if "function" == typeof value and property != "get" - - get: (key) -> @values[key] + get: Settings.get.bind Settings set: (key, value) -> @init() unless @port + Settings.set key, value - @values[key] = value - @port.postMessage operation: "set", key: key, value: value - - load: -> - @init() unless @port - @port.postMessage operation: "fetch", values: @values - - receiveMessage: (response) -> - @values = response.values if response.values? - @values[response.key] = response.value if response.key? and response.value? - @isLoaded = true - listener() while listener = @eventListeners.load?.pop() + load: -> @init() unless @port - addEventListener: (eventName, callback) -> - (@eventListeners[eventName] ||= []).push callback + addEventListener: Settings.addEventListener.bind Settings # # Give this frame a unique (non-zero) id. |
