This is an automated email from the git hooks/post-receive script.
shelikhoo pushed a change to branch main in repository pluggable-transports/snowflake-webext.
from 37c58b7 bump version to 0.6.3 new 604eee1 refactor: use a separate directory for webext dist files new 3ee7398 feat: add option to keep running when browser is closed new d24e6bb fix: don't include 'background' permission in Gecko (Firefox) build new dbccf7d refactor: consturct `Popup` only once, not inside `onMessage` new 18a9521 improvement: revoke 'background' permission when "Enabled" is off new c124752 improvement: make the "runInBackground" string localizable new 512ccde refactor: get "enabled" button wrapper by id, not class name new 3bf4593 fix: "run in background" not working if "enabled" was never toggled
The 8 revisions listed above as "new" are entirely new to this repository and will be described in separate emails. The revisions listed as "add" were already present in the repository and have only been added to this reference.
Summary of changes: .eslintignore | 2 +- .gitignore | 7 +-- LICENSE | 1 + README.md | 28 +++++++--- init-webext.js | 79 ++++++++++++++++++++++++---- make.js | 55 +++++++++++++++---- static/_locales/en_US/messages.json | 3 ++ static/embed.css | 4 ++ static/embed.html | 10 +++- static/popup.js | 49 ++++++++++++++--- webext/embed.js | 46 +++++++++------- webext/{manifest.json => manifest_base.json} | 0 12 files changed, 226 insertions(+), 58 deletions(-) rename webext/{manifest.json => manifest_base.json} (100%)
This is an automated email from the git hooks/post-receive script.
shelikhoo pushed a commit to branch main in repository pluggable-transports/snowflake-webext.
commit 604eee1fb9a0114e27bb40bd8a341e4198a62c94 Author: WofWca wofwca@protonmail.com AuthorDate: Fri Jun 17 21:09:34 2022 +0300
refactor: use a separate directory for webext dist files --- .eslintignore | 2 +- .gitignore | 7 +------ LICENSE | 1 + README.md | 4 ++-- make.js | 11 ++++++----- 5 files changed, 11 insertions(+), 14 deletions(-)
diff --git a/.eslintignore b/.eslintignore index c249199..7875026 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1,6 +1,6 @@ build/ +build-webext/ test/ -webext/snowflake.js snowflake-library.js
# FIXME: Whittle these away diff --git a/.gitignore b/.gitignore index cbd3202..95c2b84 100644 --- a/.gitignore +++ b/.gitignore @@ -5,14 +5,9 @@ .DS_Store test build +/build-webext node_modules snowflake-library.js spec/support -webext/snowflake.js -webext/popup.js -webext/embed.html -webext/embed.css -webext/assets/ -webext/_locales/ ignore/ npm-debug.log diff --git a/LICENSE b/LICENSE index 42f6296..096d6e3 100644 --- a/LICENSE +++ b/LICENSE @@ -4,6 +4,7 @@ ================================================================================ Copyright (c) 2016, Serene Han, Arlo Breault Copyright (c) 2019-2020, The Tor Project, Inc +Copyright (c) 2022, WofWca wofwca@protonmail.com
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: diff --git a/README.md b/README.md index 90ce21b..d6a508a 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,7 @@ npm install npm run webext ```
-and then load the `webext/` directory as an unpacked extension. +and then load the `build-webext/` directory as an unpacked extension. * https://developer.mozilla.org/en-US/docs/Tools/about:debugging#Loading_a_tem... * https://developer.chrome.com/extensions/getstarted#manifest
@@ -122,7 +122,7 @@ npm run pack-webext x.y.z git push origin master git push origin --tags
-# Upload the generated webext.zip (and source.zip) to the webextension stores, +# Upload the generated build-webext.zip (and source.zip) to the webextension stores, # 1. https://addons.mozilla.org/en-US/developers/addon/torproject-snowflake/versi... # 2. https://chrome.google.com/webstore/devconsole/
diff --git a/make.js b/make.js index 46857db..d3a4af1 100755 --- a/make.js +++ b/make.js @@ -164,8 +164,9 @@ task('build', 'build the snowflake proxy', function() { });
task('webext', 'build the webextension', function() { - const outDir = 'webext'; - execSync(`git clean -f -x -d ${outDir}/`); + const outDir = 'build-webext'; + execSync(`rm -rf ${outDir} && mkdir ${outDir}`); + execSync(`cp -r webext/. ${outDir}/`); execSync(`cp -r ${STATIC}/{${SHARED_FILES.join(',')}} ${outDir}/`, { shell: '/bin/bash' }); copyTranslations(outDir); concatJS(outDir, 'webext', 'snowflake.js', ''); @@ -187,7 +188,7 @@ var updateVersion = function(file, version) { task('pack-webext', 'pack the webextension for deployment', function() { try { execSync(`rm -f source.zip`); - execSync(`rm -f webext/webext.zip`); + execSync(`rm -f build-webext.zip`); } catch (error) { //Usually this happens because the zip files were removed previously console.log('Error removing zip files'); @@ -210,11 +211,11 @@ task('pack-webext', 'pack the webextension for deployment', function() { } execSync(`git archive -o source.zip HEAD .`); execSync(`npm run webext`); - execSync(`cd webext && zip -Xr webext.zip ./*`); + execSync(`cd build-webext && zip -Xr ../build-webext.zip ./*`); });
task('clean', 'remove all built files', function() { - execSync('rm -rf build test spec/support'); + execSync('rm -rf build build-webext test spec/support'); });
task('library', 'build the library', function() {
This is an automated email from the git hooks/post-receive script.
shelikhoo pushed a commit to branch main in repository pluggable-transports/snowflake-webext.
commit 3ee7398e92eda56cbcf01b0363c9c57108451e4b Author: WofWca wofwca@protonmail.com AuthorDate: Fri Jun 17 21:53:01 2022 +0300
feat: add option to keep running when browser is closed
Closes #6 This however makes it not work in Gecko (Firefox). Need to make separate builds for different browsers. --- static/embed.css | 4 ++++ static/embed.html | 8 ++++++++ static/popup.js | 30 ++++++++++++++++++++++++++++++ webext/manifest.json | 3 +++ 4 files changed, 45 insertions(+)
diff --git a/static/embed.css b/static/embed.css index 162521a..33b7300 100644 --- a/static/embed.css +++ b/static/embed.css @@ -122,6 +122,10 @@ input:checked + .slider:before { transform: translateX(13px); }
+.display-none { + display: none; +} + /* Dark Mode */ @media (prefers-color-scheme: dark) { body { diff --git a/static/embed.html b/static/embed.html index 6cc6a88..3add406 100644 --- a/static/embed.html +++ b/static/embed.html @@ -24,6 +24,14 @@ <span class="slider round"></span> </label> </div> + <!-- `display-none` is to be removed when appropriate --> + <div id="run-in-background-wrapper" class="display-none b button"> + <label for="run-in-background">Keep running when the browser is closed</label> + <label class="switch"> + <input id="run-in-background" type="checkbox" /> + <span class="slider round"></span> + </label> + </div> <div class="b learn"> <a target="_blank" href="https://snowflake.torproject.org/">__MSG_popupLearnMore__</a> </div> diff --git a/static/popup.js b/static/popup.js index 3edaeeb..2625201 100644 --- a/static/popup.js +++ b/static/popup.js @@ -1,3 +1,4 @@ +/* global chrome */ /* exported Popup */
// Add or remove a class from elem.classList, depending on cond. @@ -25,6 +26,35 @@ class Popup { this.statusdesc = document.getElementById('statusdesc'); this.img = document.getElementById('statusimg'); this.button = document.querySelector('.button'); + // if (SUPPORTS_WEBEXT_OPTIONAL_BACKGROUND_PERMISSION) + { + /** @type {HTMLInputElement} */ + const runInBackgroundInput = document.getElementById('run-in-background'); + document.getElementById('run-in-background-wrapper').classList.remove('display-none'); + { + // Two-way bind the input to the permission. + new Promise(r => chrome.permissions.contains({ permissions: ['background'] }, r)) + .then(contains => runInBackgroundInput.checked = contains); + chrome.permissions.onAdded.addListener(({ permissions }) => { + if (permissions.includes('background')) { + runInBackgroundInput.checked = true; + } + }); + chrome.permissions.onRemoved.addListener(({ permissions }) => { + if (permissions.includes('background')) { + runInBackgroundInput.checked = false; + } + }); + runInBackgroundInput.addEventListener('change', event => { + if (event.target.checked) { + new Promise(r => chrome.permissions.request({ permissions: ['background'] }, r)) + .then(granted => event.target.checked = granted); + } else { + chrome.permissions.remove({ permissions: ['background'] }); + } + }); + } + } } setEnabled(enabled) { setClass(this.img, 'on', enabled); diff --git a/webext/manifest.json b/webext/manifest.json index 6de42ab..2c6b032 100644 --- a/webext/manifest.json +++ b/webext/manifest.json @@ -24,5 +24,8 @@ }, "permissions": [ "storage" + ], + "optional_permissions": [ + "background" ] } \ No newline at end of file
This is an automated email from the git hooks/post-receive script.
shelikhoo pushed a commit to branch main in repository pluggable-transports/snowflake-webext.
commit d24e6bb6dbc74a2eb590dfab327cc61006d89c9d Author: WofWca wofwca@protonmail.com AuthorDate: Thu Aug 18 16:20:05 2022 +0300
fix: don't include 'background' permission in Gecko (Firefox) build --- README.md | 26 +++++++++++----- make.js | 45 ++++++++++++++++++++++++---- static/popup.js | 7 +++-- webext/{manifest.json => manifest_base.json} | 3 -- 4 files changed, 63 insertions(+), 18 deletions(-)
diff --git a/README.md b/README.md index d6a508a..0bd6461 100644 --- a/README.md +++ b/README.md @@ -20,10 +20,22 @@ which outputs to the `build/` directory.
### Building the webextension
-``` -npm install -npm run webext -``` +1. + ``` + npm install + ``` +2. + * For Gecko (e.g. Firefox): + + ```bash + npm run webext gecko + ``` + + * For Chromium (e.g. Chrome, Edge) + + ```bash + npm run webext chromium + ```
and then load the `build-webext/` directory as an unpacked extension. * https://developer.mozilla.org/en-US/docs/Tools/about:debugging#Loading_a_tem... @@ -122,9 +134,9 @@ npm run pack-webext x.y.z git push origin master git push origin --tags
-# Upload the generated build-webext.zip (and source.zip) to the webextension stores, -# 1. https://addons.mozilla.org/en-US/developers/addon/torproject-snowflake/versi... -# 2. https://chrome.google.com/webstore/devconsole/ +# Upload the generated build-webext-chromium.zip, build-webext-gecko.zip (and source.zip) to the webextension stores, respectively, +# 1. https://chrome.google.com/webstore/devconsole/ +# 2. https://addons.mozilla.org/en-US/developers/addon/torproject-snowflake/versi...
# This time, really clean, because we don't want any extraneous files uploaded git clean -f -d -x diff --git a/make.js b/make.js index d3a4af1..63e4cb6 100755 --- a/make.js +++ b/make.js @@ -163,14 +163,43 @@ task('build', 'build the snowflake proxy', function() { console.log('Snowflake prepared.'); });
-task('webext', 'build the webextension', function() { +const browserEngines = ['chromium', 'gecko']; +function buildWebext(browserEngine) { + const definitions = { + // Gecko currently doesn't support it: + // https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/manif... + SUPPORTS_WEBEXT_OPTIONAL_BACKGROUND_PERMISSION: browserEngine === 'chromium', + }; const outDir = 'build-webext'; execSync(`rm -rf ${outDir} && mkdir ${outDir}`); execSync(`cp -r webext/. ${outDir}/`); execSync(`cp -r ${STATIC}/{${SHARED_FILES.join(',')}} ${outDir}/`, { shell: '/bin/bash' }); + for (const [key, value] of Object.entries(definitions)) { + execSync(`sed -i "s/${key}/${value}/g" ${outDir}/popup.js`); + } + { + const manfestBasePath = `${outDir}/manifest_base.json`; + const manifest = JSON.parse(readFileSync(manfestBasePath, 'utf-8')); + if (definitions.SUPPORTS_WEBEXT_OPTIONAL_BACKGROUND_PERMISSION) { + manifest.optional_permissions = ['background']; + } + writeFileSync( + `${outDir}/manifest.json`, + JSON.stringify(manifest, undefined, ' '), + 'utf-8' + ); + execSync(`rm ${manfestBasePath}`); + } copyTranslations(outDir); concatJS(outDir, 'webext', 'snowflake.js', ''); console.log('Webextension prepared.'); +} +task('webext', 'build the webextension', function() { + const browserEngine = process.argv[3]; + if (!(browserEngines.includes(browserEngine))) { + throw new Error(`You must provide browser engine string: ${browserEngines.join('|')}`); + } + buildWebext(browserEngine); });
task('node', 'build the node binary', function() { @@ -188,7 +217,9 @@ var updateVersion = function(file, version) { task('pack-webext', 'pack the webextension for deployment', function() { try { execSync(`rm -f source.zip`); - execSync(`rm -f build-webext.zip`); + for (const browserEngine of browserEngines) { + execSync(`rm -f build-webext-${browserEngine}.zip`); + } } catch (error) { //Usually this happens because the zip files were removed previously console.log('Error removing zip files'); @@ -197,7 +228,7 @@ task('pack-webext', 'pack the webextension for deployment', function() { var version = process.argv[3]; console.log(version); updateVersion('./package.json', version); - updateVersion('./webext/manifest.json', version); + updateVersion('./webext/manifest_base.json', version); execSync(`git commit -am "bump version to ${version}"`); try { execSync(`git tag webext-${version}`); @@ -205,13 +236,15 @@ task('pack-webext', 'pack the webextension for deployment', function() { console.log('Error creating git tag'); // Revert changes execSync(`git reset HEAD~`); - execSync(`git checkout ./webext/manifest.json`); + execSync(`git checkout ./webext/manifest_base.json`); execSync(`git submodule update`); return; } execSync(`git archive -o source.zip HEAD .`); - execSync(`npm run webext`); - execSync(`cd build-webext && zip -Xr ../build-webext.zip ./*`); + for (const browserEngine of browserEngines) { + execSync(`npm run webext ${browserEngine}`); + execSync(`cd build-webext && zip -Xr ../build-webext-${browserEngine}.zip ./*`); + } });
task('clean', 'remove all built files', function() { diff --git a/static/popup.js b/static/popup.js index 2625201..fc4c0e7 100644 --- a/static/popup.js +++ b/static/popup.js @@ -26,8 +26,11 @@ class Popup { this.statusdesc = document.getElementById('statusdesc'); this.img = document.getElementById('statusimg'); this.button = document.querySelector('.button'); - // if (SUPPORTS_WEBEXT_OPTIONAL_BACKGROUND_PERMISSION) - { + if ( + typeof SUPPORTS_WEBEXT_OPTIONAL_BACKGROUND_PERMISSION !== 'undefined' + // eslint-disable-next-line no-undef + && SUPPORTS_WEBEXT_OPTIONAL_BACKGROUND_PERMISSION + ) { /** @type {HTMLInputElement} */ const runInBackgroundInput = document.getElementById('run-in-background'); document.getElementById('run-in-background-wrapper').classList.remove('display-none'); diff --git a/webext/manifest.json b/webext/manifest_base.json similarity index 91% rename from webext/manifest.json rename to webext/manifest_base.json index 2c6b032..6de42ab 100644 --- a/webext/manifest.json +++ b/webext/manifest_base.json @@ -24,8 +24,5 @@ }, "permissions": [ "storage" - ], - "optional_permissions": [ - "background" ] } \ No newline at end of file
This is an automated email from the git hooks/post-receive script.
shelikhoo pushed a commit to branch main in repository pluggable-transports/snowflake-webext.
commit dbccf7d6dcfb6caab7a904ba2849642a0bceed82 Author: WofWca wofwca@protonmail.com AuthorDate: Mon Jun 20 21:01:20 2022 +0300
refactor: consturct `Popup` only once, not inside `onMessage` --- webext/embed.js | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-)
diff --git a/webext/embed.js b/webext/embed.js index c108f82..b41d266 100644 --- a/webext/embed.js +++ b/webext/embed.js @@ -1,32 +1,33 @@ /* global chrome, Popup */
-// Fill i18n in HTML window.onload = () => { + // Fill i18n in HTML Popup.fill(document.body, (m) => { return chrome.i18n.getMessage(m); }); -};
-const port = chrome.runtime.connect({ - name: "popup" -}); + const port = chrome.runtime.connect({ + name: "popup" + });
-port.onMessage.addListener((m) => { - const { clients, enabled, total, missingFeature } = m; const popup = new Popup( (...args) => chrome.i18n.getMessage(...args), (event) => port.postMessage({ enabled: event.target.checked }), () => port.postMessage({ retry: true }) );
- if (missingFeature) { - popup.missingFeature(missingFeature); - return; - } + port.onMessage.addListener((m) => { + const { clients, enabled, total, missingFeature } = m; + + if (missingFeature) { + popup.missingFeature(missingFeature); + return; + }
- if (enabled) { - popup.turnOn(clients, total); - } else { - popup.turnOff(); - } -}); + if (enabled) { + popup.turnOn(clients, total); + } else { + popup.turnOff(); + } + }); +};
This is an automated email from the git hooks/post-receive script.
shelikhoo pushed a commit to branch main in repository pluggable-transports/snowflake-webext.
commit 18a95215421d1d912cf945d97239a90083a765ae Author: WofWca wofwca@protonmail.com AuthorDate: Tue Jun 21 22:46:45 2022 +0300
improvement: revoke 'background' permission when "Enabled" is off --- init-webext.js | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++------- make.js | 9 ++++--- static/popup.js | 42 ++++++++++++++++++--------------- webext/embed.js | 11 ++++++++- 4 files changed, 104 insertions(+), 31 deletions(-)
diff --git a/init-webext.js b/init-webext.js index cde7d5f..003fb7f 100644 --- a/init-webext.js +++ b/init-webext.js @@ -5,6 +5,40 @@ UI */
+ +/** + * Decide whether we need to request or revoke the 'background' permission, and + * set the `runInBackground` storage value appropriately. + * @param {boolean | undefined} enabledSetting + * @param {boolean | undefined} runInBackgroundSetting + */ +function maybeChangeBackgroundPermission(enabledSetting, runInBackgroundSetting) { + const needBackgroundPermission = + runInBackgroundSetting + // When the extension is disabled, we need the permission to be revoked because + // otherwise it'll keep the browser process running for no reason. + && enabledSetting; + // Yes, this is called even if the permission is already in the state we need + // it to be in (granted/removed). + new Promise(r => { + chrome.permissions[needBackgroundPermission ? "request" : "remove"]( + { permissions: ['background'] }, + r + ); + }) + .then(success => { + // Currently the resolve value is `true` even when the permission was alrady granted + // before it was requested (already removed before it was revoked). TODO Need to make + // sure it's the desired behavior and if it needs to change. + // https://developer.chrome.com/docs/extensions/reference/permissions/#method-r... + // https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/p... + // https://github.com/mdn/content/pull/17516 + if (success) { + chrome.storage.local.set({ runInBackground: runInBackgroundSetting }); + } + }); +} + class WebExtUI extends UI {
constructor() { @@ -94,15 +128,38 @@ class WebExtUI extends UI { if (m.retry) { // FIXME: Can set a retrying state here this.tryProbe(); - return; + } else if (m.enabled != undefined) { + (new Promise((resolve) => { + chrome.storage.local.set({ "snowflake-enabled": m.enabled }, resolve); + })) + .then(() => { + log("Stored toggle state"); + this.initToggle(); + }); + if ( + typeof SUPPORTS_WEBEXT_OPTIONAL_BACKGROUND_PERMISSION !== 'undefined' + // eslint-disable-next-line no-undef + && SUPPORTS_WEBEXT_OPTIONAL_BACKGROUND_PERMISSION + ) { + new Promise(r => chrome.storage.local.get({ runInBackground: false }, r)) + .then(storage => { + maybeChangeBackgroundPermission(m.enabled, storage.runInBackground); + }); + } + } else if (m.runInBackground != undefined) { + if ( + typeof SUPPORTS_WEBEXT_OPTIONAL_BACKGROUND_PERMISSION !== 'undefined' + // eslint-disable-next-line no-undef + && SUPPORTS_WEBEXT_OPTIONAL_BACKGROUND_PERMISSION + ) { + new Promise(r => chrome.storage.local.get({ "snowflake-enabled": false }, r)) + .then(storage => { + maybeChangeBackgroundPermission(storage["snowflake-enabled"], m.runInBackground); + }); + } + } else { + log("Unrecognized message"); } - (new Promise((resolve) => { - chrome.storage.local.set({ "snowflake-enabled": m.enabled }, resolve); - })) - .then(() => { - log("Stored toggle state"); - this.initToggle(); - }); }
onDisconnect() { diff --git a/make.js b/make.js index 63e4cb6..6116257 100755 --- a/make.js +++ b/make.js @@ -174,9 +174,6 @@ function buildWebext(browserEngine) { execSync(`rm -rf ${outDir} && mkdir ${outDir}`); execSync(`cp -r webext/. ${outDir}/`); execSync(`cp -r ${STATIC}/{${SHARED_FILES.join(',')}} ${outDir}/`, { shell: '/bin/bash' }); - for (const [key, value] of Object.entries(definitions)) { - execSync(`sed -i "s/${key}/${value}/g" ${outDir}/popup.js`); - } { const manfestBasePath = `${outDir}/manifest_base.json`; const manifest = JSON.parse(readFileSync(manfestBasePath, 'utf-8')); @@ -192,6 +189,12 @@ function buildWebext(browserEngine) { } copyTranslations(outDir); concatJS(outDir, 'webext', 'snowflake.js', ''); + for (const [key, value] of Object.entries(definitions)) { + const commandStart = `sed -i "s/${key}/${value}/g" ${outDir}`; + execSync(`${commandStart}/popup.js`); + execSync(`${commandStart}/embed.js`); + execSync(`${commandStart}/snowflake.js`); + } console.log('Webextension prepared.'); } task('webext', 'build the webextension', function() { diff --git a/static/popup.js b/static/popup.js index fc4c0e7..fa7b8ed 100644 --- a/static/popup.js +++ b/static/popup.js @@ -11,7 +11,10 @@ function setClass(elem, className, cond) { }
class Popup { - constructor(getMsgFunc, changeFunc, retryFunc) { + /** + * @param {() => void} [onRunInBackgroundChange] + */ + constructor(getMsgFunc, changeFunc, retryFunc, onRunInBackgroundChange) { this.getMsgFunc = getMsgFunc; this.enabled = document.getElementById('enabled'); this.enabled.addEventListener('change', changeFunc); @@ -34,26 +37,27 @@ class Popup { /** @type {HTMLInputElement} */ const runInBackgroundInput = document.getElementById('run-in-background'); document.getElementById('run-in-background-wrapper').classList.remove('display-none'); - { - // Two-way bind the input to the permission. - new Promise(r => chrome.permissions.contains({ permissions: ['background'] }, r)) - .then(contains => runInBackgroundInput.checked = contains); - chrome.permissions.onAdded.addListener(({ permissions }) => { - if (permissions.includes('background')) { - runInBackgroundInput.checked = true; - } + { // Two-way bind the input to the permission. + runInBackgroundInput.addEventListener('change', ({ target }) => { + onRunInBackgroundChange(target.checked); + // The permission request may be rejected, so only update the checkbox value inside + // the event listeners below. TODO Don't know if it's ok in terms of accessibility. + // Also maybe it's better looking in general to toggle the checkbox and toggle it back + // if the request is rejected. + target.checked = !target.checked; }); - chrome.permissions.onRemoved.addListener(({ permissions }) => { - if (permissions.includes('background')) { - runInBackgroundInput.checked = false; - } + + // The storage is the source of truth for `runInBackground`, not + // `chrome.permissions.contains({ permissions: ['background'] }`, because when the "Enabled" + // checkbox is off, we (may) revoke that permission. + new Promise(r => chrome.storage.local.get({ runInBackground: false }, r)) + .then(({ runInBackground }) => { + runInBackgroundInput.checked = runInBackground; }); - runInBackgroundInput.addEventListener('change', event => { - if (event.target.checked) { - new Promise(r => chrome.permissions.request({ permissions: ['background'] }, r)) - .then(granted => event.target.checked = granted); - } else { - chrome.permissions.remove({ permissions: ['background'] }); + chrome.storage.local.onChanged.addListener(changes => { + const runInBackgroundChange = changes.runInBackground; + if (runInBackgroundChange) { + runInBackgroundInput.checked = runInBackgroundChange.newValue; } }); } diff --git a/webext/embed.js b/webext/embed.js index b41d266..90dbe46 100644 --- a/webext/embed.js +++ b/webext/embed.js @@ -13,7 +13,16 @@ window.onload = () => { const popup = new Popup( (...args) => chrome.i18n.getMessage(...args), (event) => port.postMessage({ enabled: event.target.checked }), - () => port.postMessage({ retry: true }) + () => port.postMessage({ retry: true }), + ( + ( + typeof SUPPORTS_WEBEXT_OPTIONAL_BACKGROUND_PERMISSION !== 'undefined' + // eslint-disable-next-line no-undef + && SUPPORTS_WEBEXT_OPTIONAL_BACKGROUND_PERMISSION + ) + ? (newValue) => port.postMessage({ runInBackground: newValue }) + : undefined + ) );
port.onMessage.addListener((m) => {
This is an automated email from the git hooks/post-receive script.
shelikhoo pushed a commit to branch main in repository pluggable-transports/snowflake-webext.
commit c124752b29f63d295bc7cfe65477459f8db63daa Author: WofWca wofwca@protonmail.com AuthorDate: Fri Jun 24 21:02:44 2022 +0300
improvement: make the "runInBackground" string localizable --- static/_locales/en_US/messages.json | 3 +++ static/embed.html | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-)
diff --git a/static/_locales/en_US/messages.json b/static/_locales/en_US/messages.json index 62c16db..1343805 100644 --- a/static/_locales/en_US/messages.json +++ b/static/_locales/en_US/messages.json @@ -5,6 +5,9 @@ "popupEnabled": { "message": "Enabled" }, + "popupRunInBackground": { + "message": "Keep running when the browser is closed" + }, "popupLearnMore": { "message": "Learn more" }, diff --git a/static/embed.html b/static/embed.html index 3add406..b0c4a95 100644 --- a/static/embed.html +++ b/static/embed.html @@ -26,7 +26,7 @@ </div> <!-- `display-none` is to be removed when appropriate --> <div id="run-in-background-wrapper" class="display-none b button"> - <label for="run-in-background">Keep running when the browser is closed</label> + <label for="run-in-background">__MSG_popupRunInBackground__</label> <label class="switch"> <input id="run-in-background" type="checkbox" /> <span class="slider round"></span>
This is an automated email from the git hooks/post-receive script.
shelikhoo pushed a commit to branch main in repository pluggable-transports/snowflake-webext.
commit 512ccde626a316335be0027550fbe0702da596e0 Author: WofWca wofwca@protonmail.com AuthorDate: Fri Jul 15 14:54:31 2022 +0300
refactor: get "enabled" button wrapper by id, not class name
As there are now two element with class "button" --- static/embed.html | 2 +- static/popup.js | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/static/embed.html b/static/embed.html index b0c4a95..be0e420 100644 --- a/static/embed.html +++ b/static/embed.html @@ -17,7 +17,7 @@ <p id="statusdesc"></p> <button type="button" id="retry">__MSG_popupRetry__</button> </div> - <div class="b button"> + <div id="enabled-wrapper" class="b button"> <label id="toggle" for="enabled">__MSG_popupEnabled__</label> <label class="switch"> <input id="enabled" type="checkbox" /> diff --git a/static/popup.js b/static/popup.js index fa7b8ed..05bf4f8 100644 --- a/static/popup.js +++ b/static/popup.js @@ -28,7 +28,7 @@ class Popup { this.statustext = document.getElementById('statustext'); this.statusdesc = document.getElementById('statusdesc'); this.img = document.getElementById('statusimg'); - this.button = document.querySelector('.button'); + this.enabledWrapper = document.getElementById('enabled-wrapper'); if ( typeof SUPPORTS_WEBEXT_OPTIONAL_BACKGROUND_PERMISSION !== 'undefined' // eslint-disable-next-line no-undef @@ -76,8 +76,8 @@ class Popup { this.statusdesc.innerText = desc; setClass(this.statusdesc, 'error', error); } - setButton(hide) { - this.button.style.display = hide ? 'none' : 'block'; + setEnabledWrapper(hide) { + this.enabledWrapper.style.display = hide ? 'none' : 'block'; } setRetry(display) { this.retry.style.display = display ? 'inline-block' : 'none'; @@ -109,7 +109,7 @@ class Popup { this.setStatusDesc((total > 0) ? this.getMsgFunc('popupDescOn', String(total)) : ''); this.setEnabled(true); this.setActive(this.active); - this.setButton(false); + this.setEnabledWrapper(false); this.setRetry(false); } turnOff(desc, error, retry) { @@ -118,7 +118,7 @@ class Popup { this.setStatusDesc(desc ? this.getMsgFunc(desc) : '', error); this.setEnabled(false); this.setActive(false); - this.setButton(error); + this.setEnabledWrapper(error); this.setRetry(retry); } missingFeature(desc) {
This is an automated email from the git hooks/post-receive script.
shelikhoo pushed a commit to branch main in repository pluggable-transports/snowflake-webext.
commit 3bf4593379c27e39311787e45d389085b69a31a5 Author: WofWca wofwca@protonmail.com AuthorDate: Thu Aug 18 15:13:57 2022 +0300
fix: "run in background" not working if "enabled" was never toggled --- init-webext.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/init-webext.js b/init-webext.js index 003fb7f..3bbdfde 100644 --- a/init-webext.js +++ b/init-webext.js @@ -39,6 +39,10 @@ function maybeChangeBackgroundPermission(enabledSetting, runInBackgroundSetting) }); }
+// If you want to gonna change this to `false`, double-check everything as some code +// may still be assuming it to be `true`. +const DEFAULT_ENABLED = true; + class WebExtUI extends UI {
constructor() { @@ -152,7 +156,7 @@ class WebExtUI extends UI { // eslint-disable-next-line no-undef && SUPPORTS_WEBEXT_OPTIONAL_BACKGROUND_PERMISSION ) { - new Promise(r => chrome.storage.local.get({ "snowflake-enabled": false }, r)) + new Promise(r => chrome.storage.local.get({ "snowflake-enabled": DEFAULT_ENABLED }, r)) .then(storage => { maybeChangeBackgroundPermission(storage["snowflake-enabled"], m.runInBackground); }); @@ -202,7 +206,7 @@ class WebExtUI extends UI {
WebExtUI.prototype.port = null;
-WebExtUI.prototype.enabled = true; +WebExtUI.prototype.enabled = DEFAULT_ENABLED;
/* Entry point.
tor-commits@lists.torproject.org