[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [pluggable-transports/snowflake-webext] 04/08: refactor: consturct `Popup` only once, not inside `onMessage`



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@xxxxxxxxxxxxxx>
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();
+    }
+  });
+};

-- 
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