Additional review refactoring

This commit is contained in:
Lesley Norton 2021-10-22 15:25:37 -05:00
parent 96bd0f4b4e
commit b552d41772
No known key found for this signature in database
GPG key ID: E98FBAEE3F13956E
3 changed files with 9 additions and 11 deletions

View file

@ -44,11 +44,11 @@ const MozillaVPN_Background = {
this.maybeInitPort(); this.maybeInitPort();
}, },
async getConnectionStatus() { getConnectionStatus() {
return this._connected; return this._connected;
}, },
async getInstallationStatus() { getInstallationStatus() {
return this._installed; return this._installed;
}, },

View file

@ -38,7 +38,6 @@ const MozillaVPN = {
}, },
async setStatusIndicatorIcons(mozillaVpnInstalled) { async setStatusIndicatorIcons(mozillaVpnInstalled) {
const mozillaVpnConnected = await browser.runtime.sendMessage({ method: "MozillaVPN_getConnectionStatus" });
const statusIconEls = document.querySelectorAll(".moz-vpn-connection-status-indicator"); const statusIconEls = document.querySelectorAll(".moz-vpn-connection-status-indicator");
@ -56,6 +55,7 @@ const MozillaVPN = {
const connectedIndicatorSrc = "url(./img/moz-vpn-connected.svg)"; const connectedIndicatorSrc = "url(./img/moz-vpn-connected.svg)";
const disconnectedIndicatorSrc = "url(./img/moz-vpn-disconnected.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 connectionStatusStringId = mozillaVpnConnected ? "moz-vpn-connected" : "moz-vpn-disconnected";
const connectionStatusLocalizedString = browser.i18n.getMessage(connectionStatusStringId); const connectionStatusLocalizedString = browser.i18n.getMessage(connectionStatusStringId);
@ -127,9 +127,9 @@ const MozillaVPN = {
}, },
async getProxies(identities) { async getProxies(identities) {
const proxies = {};
const mozillaVpnInstalled = await browser.runtime.sendMessage({ method: "MozillaVPN_getInstallationStatus" }); const mozillaVpnInstalled = await browser.runtime.sendMessage({ method: "MozillaVPN_getInstallationStatus" });
const proxies = {};
if (mozillaVpnInstalled) { if (mozillaVpnInstalled) {
for (const identity of identities) { for (const identity of identities) {
try { try {
@ -151,9 +151,8 @@ const MozillaVPN = {
}; };
}, },
async getProxyWarnings(proxyObj) {
const mozillaVpnConnected = await browser.runtime.sendMessage({ method: "MozillaVPN_getConnectionStatus" });
async getProxyWarnings(proxyObj) {
if (!proxyObj) { if (!proxyObj) {
return ""; return "";
} }
@ -164,15 +163,13 @@ const MozillaVPN = {
return ""; return "";
} }
const mozillaVpnConnected = await browser.runtime.sendMessage({ method: "MozillaVPN_getConnectionStatus" });
if (typeof(proxy.mozProxyEnabled) !== "undefined" && !mozillaVpnConnected) { if (typeof(proxy.mozProxyEnabled) !== "undefined" && !mozillaVpnConnected) {
return "proxy-unavailable"; return "proxy-unavailable";
} }
}, },
async getFlag(proxyObj) { async getFlag(proxyObj) {
const mozillaVpnConnected = await browser.runtime.sendMessage({ method: "MozillaVPN_getConnectionStatus" });
const mozillaVpnInstalled = await browser.runtime.sendMessage({ method: "MozillaVPN_getInstallationStatus" });
const flag = { const flag = {
imgCode: "default", imgCode: "default",
elemClasses: "display-none", elemClasses: "display-none",
@ -184,10 +181,12 @@ const MozillaVPN = {
} }
const { proxy } = proxyObj; const { proxy } = proxyObj;
const mozillaVpnInstalled = await browser.runtime.sendMessage({ method: "MozillaVPN_getInstallationStatus" });
if (typeof(proxy) === "undefined" || !mozillaVpnInstalled) { if (typeof(proxy) === "undefined" || !mozillaVpnInstalled) {
return flag; return flag;
} }
const mozillaVpnConnected = await browser.runtime.sendMessage({ method: "MozillaVPN_getConnectionStatus" });
if (mozillaVpnInstalled && typeof(proxy.cityName) !== "undefined") { if (mozillaVpnInstalled && typeof(proxy.cityName) !== "undefined") {
flag.imgCode = proxy.countryCode.toUpperCase(); flag.imgCode = proxy.countryCode.toUpperCase();
flag.imgAlt = proxy.cityName; flag.imgAlt = proxy.cityName;

View file

@ -1588,8 +1588,6 @@ Logic.registerPanel(P_CONTAINER_EDIT, {
} }
async updateProxyDependentUi(proxyInfo) { async updateProxyDependentUi(proxyInfo) {
const mozillaVpnConnected = await browser.runtime.sendMessage({ method: "MozillaVPN_getConnectionStatus" });
const containerHasProxy = typeof(proxyInfo) !== "undefined"; const containerHasProxy = typeof(proxyInfo) !== "undefined";
const mozillaVpnProxyLocationAvailable = (proxy) => { const mozillaVpnProxyLocationAvailable = (proxy) => {
@ -1604,6 +1602,7 @@ Logic.registerPanel(P_CONTAINER_EDIT, {
this.updateProxyInputs(proxyInfo); this.updateProxyInputs(proxyInfo);
this.enableDisableProxyButtons(); this.enableDisableProxyButtons();
const mozillaVpnConnected = await browser.runtime.sendMessage({ method: "MozillaVPN_getConnectionStatus" });
if ( if (
!containerHasProxy || !containerHasProxy ||
!mozillaVpnProxyLocationAvailable(proxyInfo) || !mozillaVpnProxyLocationAvailable(proxyInfo) ||