From b552d41772ec11f2cd8381c610e9966550082fbe Mon Sep 17 00:00:00 2001 From: Lesley Norton Date: Fri, 22 Oct 2021 15:25:37 -0500 Subject: [PATCH] Additional review refactoring --- src/js/background/mozillaVpnBackground.js | 4 ++-- src/js/mozillaVpn.js | 13 ++++++------- src/js/popup.js | 3 +-- 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/src/js/background/mozillaVpnBackground.js b/src/js/background/mozillaVpnBackground.js index 106ac33..8a12730 100644 --- a/src/js/background/mozillaVpnBackground.js +++ b/src/js/background/mozillaVpnBackground.js @@ -44,11 +44,11 @@ const MozillaVPN_Background = { this.maybeInitPort(); }, - async getConnectionStatus() { + getConnectionStatus() { return this._connected; }, - async getInstallationStatus() { + getInstallationStatus() { return this._installed; }, diff --git a/src/js/mozillaVpn.js b/src/js/mozillaVpn.js index f95964b..3f6a78d 100644 --- a/src/js/mozillaVpn.js +++ b/src/js/mozillaVpn.js @@ -38,7 +38,6 @@ const MozillaVPN = { }, async setStatusIndicatorIcons(mozillaVpnInstalled) { - const mozillaVpnConnected = await browser.runtime.sendMessage({ method: "MozillaVPN_getConnectionStatus" }); const statusIconEls = document.querySelectorAll(".moz-vpn-connection-status-indicator"); @@ -56,6 +55,7 @@ const MozillaVPN = { const connectedIndicatorSrc = "url(./img/moz-vpn-connected.svg)"; const disconnectedIndicatorSrc = "url(./img/moz-vpn-disconnected.svg)"; + const mozillaVpnConnected = await browser.runtime.sendMessage({ method: "MozillaVPN_getConnectionStatus" }); const connectionStatusStringId = mozillaVpnConnected ? "moz-vpn-connected" : "moz-vpn-disconnected"; const connectionStatusLocalizedString = browser.i18n.getMessage(connectionStatusStringId); @@ -127,9 +127,9 @@ const MozillaVPN = { }, async getProxies(identities) { + const proxies = {}; const mozillaVpnInstalled = await browser.runtime.sendMessage({ method: "MozillaVPN_getInstallationStatus" }); - const proxies = {}; if (mozillaVpnInstalled) { for (const identity of identities) { try { @@ -151,9 +151,8 @@ const MozillaVPN = { }; }, - async getProxyWarnings(proxyObj) { - const mozillaVpnConnected = await browser.runtime.sendMessage({ method: "MozillaVPN_getConnectionStatus" }); + async getProxyWarnings(proxyObj) { if (!proxyObj) { return ""; } @@ -164,15 +163,13 @@ const MozillaVPN = { return ""; } + const mozillaVpnConnected = await browser.runtime.sendMessage({ method: "MozillaVPN_getConnectionStatus" }); if (typeof(proxy.mozProxyEnabled) !== "undefined" && !mozillaVpnConnected) { return "proxy-unavailable"; } }, async getFlag(proxyObj) { - const mozillaVpnConnected = await browser.runtime.sendMessage({ method: "MozillaVPN_getConnectionStatus" }); - const mozillaVpnInstalled = await browser.runtime.sendMessage({ method: "MozillaVPN_getInstallationStatus" }); - const flag = { imgCode: "default", elemClasses: "display-none", @@ -184,10 +181,12 @@ const MozillaVPN = { } const { proxy } = proxyObj; + const mozillaVpnInstalled = await browser.runtime.sendMessage({ method: "MozillaVPN_getInstallationStatus" }); if (typeof(proxy) === "undefined" || !mozillaVpnInstalled) { return flag; } + const mozillaVpnConnected = await browser.runtime.sendMessage({ method: "MozillaVPN_getConnectionStatus" }); if (mozillaVpnInstalled && typeof(proxy.cityName) !== "undefined") { flag.imgCode = proxy.countryCode.toUpperCase(); flag.imgAlt = proxy.cityName; diff --git a/src/js/popup.js b/src/js/popup.js index b6063d1..fa14383 100644 --- a/src/js/popup.js +++ b/src/js/popup.js @@ -1588,8 +1588,6 @@ Logic.registerPanel(P_CONTAINER_EDIT, { } async updateProxyDependentUi(proxyInfo) { - const mozillaVpnConnected = await browser.runtime.sendMessage({ method: "MozillaVPN_getConnectionStatus" }); - const containerHasProxy = typeof(proxyInfo) !== "undefined"; const mozillaVpnProxyLocationAvailable = (proxy) => { @@ -1604,6 +1602,7 @@ Logic.registerPanel(P_CONTAINER_EDIT, { this.updateProxyInputs(proxyInfo); this.enableDisableProxyButtons(); + const mozillaVpnConnected = await browser.runtime.sendMessage({ method: "MozillaVPN_getConnectionStatus" }); if ( !containerHasProxy || !mozillaVpnProxyLocationAvailable(proxyInfo) ||