Move toggle initiation init-webext.coffee

Prevents repeat calls to update() on startup
This commit is contained in:
Cecylia Bocovich 2019-07-03 17:12:01 -04:00
parent 6210b5ea7f
commit 4494dbd3ca
2 changed files with 12 additions and 12 deletions

View file

@ -24,7 +24,7 @@ init = () ->
snowflake = new Snowflake config, ui, broker
log '== snowflake proxy =='
update()
ui.initToggle()
update = () ->
if !ui.enabled

View file

@ -59,7 +59,6 @@ class WebExtUI extends UI
constructor: ->
@initStats()
@initToggle()
chrome.runtime.onConnect.addListener @onConnect
initStats: ->
@ -71,16 +70,13 @@ class WebExtUI extends UI
), 60 * 60 * 1000
initToggle: ->
try
getting = chrome.storage.local.get("snowflake-enabled", (result) =>
if result['snowflake-enabled'] != undefined
@enabled = result['snowflake-enabled']
@setEnabled @enabled
else
log "Toggle state not yet saved"
@setEnabled @enabled
)
catch
log "Error retrieving toggle state"
postActive: ->
@port?.postMessage
@ -114,6 +110,10 @@ class WebExtUI extends UI
chrome.browserAction.setIcon
path:
32: "icons/status-running.png"
else
chrome.browserAction.setIcon
path:
32: "icons/status-on.png"
setEnabled: (enabled) ->
update()