[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [pluggable-transports/snowflake-webext] 02/08: feat: add option to keep running when browser is closed
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@xxxxxxxxxxxxxx>
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
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits