diff --git a/proxy/init-webext.coffee b/proxy/init-webext.coffee index 20b8bc3..7ff59ba 100644 --- a/proxy/init-webext.coffee +++ b/proxy/init-webext.coffee @@ -24,6 +24,7 @@ init = () -> snowflake = new Snowflake config, ui, broker log '== snowflake proxy ==' + update() update = () -> if !ui.enabled diff --git a/proxy/ui.coffee b/proxy/ui.coffee index 7a41f32..e6896ec 100644 --- a/proxy/ui.coffee +++ b/proxy/ui.coffee @@ -4,7 +4,7 @@ All of Snowflake's DOM manipulation and inputs. class UI active: false - enabled: false + enabled: true setStatus: (msg) -> @@ -73,14 +73,14 @@ class WebExtUI extends UI initToggle: -> try getting = chrome.storage.local.get("snowflake-enabled", (result) => - @enabled = result['snowflake-enabled'] - update() - chrome.browserAction.setIcon - path: - 32: "icons/status-" + (if @enabled then "on" else "off") + ".png" + if result['snowflake-enabled'] != undefined + @enabled = result['snowflake-enabled'] + @setEnabled @enabled + else + log "Toggle state not yet saved" ) catch - log "Toggle state not yet saved" + log "Error retrieving toggle state" postActive: -> @port?.postMessage @@ -98,10 +98,7 @@ class WebExtUI extends UI onMessage: (m) => @enabled = m.enabled - update() - chrome.browserAction.setIcon - path: - 32: "icons/status-" + (if @enabled then "on" else "off") + ".png" + @setEnabled @enabled @postActive() storing = chrome.storage.local.set({ "snowflake-enabled": @enabled }, () -> log "Stored toggle state") @@ -117,3 +114,10 @@ class WebExtUI extends UI chrome.browserAction.setIcon path: 32: "icons/status-running.png" + + setEnabled: (enabled) -> + update() + chrome.browserAction.setIcon + path: + 32: "icons/status-" + (if enabled then "on" else "off") + ".png" + diff --git a/proxy/webext/manifest.json b/proxy/webext/manifest.json index 0da349f..fa2bc5f 100644 --- a/proxy/webext/manifest.json +++ b/proxy/webext/manifest.json @@ -9,7 +9,7 @@ }, "browser_action": { "default_icon": { - "32": "icons/status-off.png" + "32": "icons/status-on.png" }, "default_title": "Snowflake", "default_popup": "popup.html" diff --git a/proxy/webext/popup.html b/proxy/webext/popup.html index 1074333..9837595 100644 --- a/proxy/webext/popup.html +++ b/proxy/webext/popup.html @@ -7,14 +7,14 @@