[snowflake/master] Save webextension toggle state

commit 2cd69f6f25539e5975511ca1ee226d30185f6af5 Author: Cecylia Bocovich <cohosh@torproject.org> Date: Tue Jul 2 11:51:47 2019 -0400 Save webextension toggle state Save whether the snowflake extension is currently enabled in local storage so that users do not need to opt-in again every time the browser is restarted --- proxy/ui.coffee | 14 ++++++++++++++ proxy/webext/manifest.json | 3 ++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/proxy/ui.coffee b/proxy/ui.coffee index f9361ea..ec8d4d5 100644 --- a/proxy/ui.coffee +++ b/proxy/ui.coffee @@ -59,6 +59,7 @@ class WebExtUI extends UI constructor: -> @initStats() + @initToggle() chrome.runtime.onConnect.addListener @onConnect initStats: -> @@ -69,6 +70,18 @@ class WebExtUI extends UI @postActive() ), 60 * 60 * 1000 + 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" + ) + catch + log "Toggle state not yet saved" + postActive: -> @port?.postMessage active: @active @@ -90,6 +103,7 @@ class WebExtUI extends UI path: 32: "icons/status-" + (if @enabled then "on" else "off") + ".png" @postActive() + storing = chrome.storage.local.set({"snowflake-enabled":@enabled}, () -> log "Stored toggle state") onDisconnect: (port) => @port = null diff --git a/proxy/webext/manifest.json b/proxy/webext/manifest.json index cd7d250..0da349f 100644 --- a/proxy/webext/manifest.json +++ b/proxy/webext/manifest.json @@ -13,5 +13,6 @@ }, "default_title": "Snowflake", "default_popup": "popup.html" - } + }, + "permissions": ["storage"] }
participants (1)
-
cohosh@torproject.org