Review + QA updates - Part 1

This commit is contained in:
Lesley Norton 2021-10-21 23:02:27 -05:00
parent 0a772c8f04
commit 2f6e49bec0
No known key found for this signature in database
GPG key ID: E98FBAEE3F13956E
5 changed files with 59 additions and 92 deletions

View file

@ -1490,7 +1490,7 @@ manage things like container crud */
} }
#edit-container-panel-choose-icon .radio-container:hover .usercontext-icon::before { #edit-container-panel-choose-icon .radio-container:hover .usercontext-icon::before {
fill: #fff !important; fill: var(--grey50) !important;
} }
.mac-icon { .mac-icon {
@ -2182,4 +2182,8 @@ tr:hover > td > .trash-button {
.radio-choice > .radio-container > [type="radio"]:checked + label { .radio-choice > .radio-container > [type="radio"]:checked + label {
background: var(--bgDark); background: var(--bgDark);
} }
#edit-container-panel-choose-icon .radio-container:hover .usercontext-icon::before {
fill: #fff !important;
}
} }

View file

@ -55,23 +55,13 @@ const backgroundLogic = {
}, },
async createOrUpdateContainer(options) { async createOrUpdateContainer(options) {
let donePromise;
if (options.userContextId !== "new") { if (options.userContextId !== "new") {
donePromise = browser.contextualIdentities.update( return await browser.contextualIdentities.update(
this.cookieStoreId(options.userContextId), this.cookieStoreId(options.userContextId),
options.params options.params
); );
} else {
donePromise = browser.contextualIdentities.create(options.params);
// We cannot yet access the new cookieStoreId via this.cookieStoreId(...), so we take this from the resolved promise
donePromise.then((identity) => {
(identity.cookieStoreId, options.proxy);
}).catch(() => {
// Empty because this should never happen theoretically.
});
} }
return await browser.contextualIdentities.create(options.params);
await donePromise;
}, },
async openNewTab(options) { async openNewTab(options) {

View file

@ -12,6 +12,10 @@ const MozillaVPN = {
for (const el of document.querySelectorAll("[data-cookie-store-id]")) { for (const el of document.querySelectorAll("[data-cookie-store-id]")) {
const cookieStoreId = el.dataset.cookieStoreId; const cookieStoreId = el.dataset.cookieStoreId;
if (!proxies[cookieStoreId]) {
continue;
}
const { proxy } = proxies[cookieStoreId]; const { proxy } = proxies[cookieStoreId];
if (typeof(proxy) !== "undefined") { if (typeof(proxy) !== "undefined") {
@ -139,7 +143,7 @@ const MozillaVPN = {
return proxies; return proxies;
}, },
getMozillaProxyInfoObj () { getMozillaProxyInfoObj() {
return { return {
countryCode: undefined, countryCode: undefined,
cityName: undefined, cityName: undefined,
@ -211,7 +215,7 @@ const MozillaVPN = {
return `socks://${socksName}.mullvad.net:1080`; return `socks://${socksName}.mullvad.net:1080`;
}, },
async pickRandomServer() { async pickRandomLocation() {
const { mozillaVpnServers } = await browser.storage.local.get("mozillaVpnServers"); const { mozillaVpnServers } = await browser.storage.local.get("mozillaVpnServers");
const randomInteger = this.getRandomInteger(0, mozillaVpnServers.length - 1); const randomInteger = this.getRandomInteger(0, mozillaVpnServers.length - 1);
const randomServerCountry = mozillaVpnServers[randomInteger]; const randomServerCountry = mozillaVpnServers[randomInteger];

View file

@ -1474,7 +1474,7 @@ Logic.registerPanel(P_CONTAINER_EDIT, {
} else { } else {
// No saved Mozilla VPN proxy information. Get something new. // No saved Mozilla VPN proxy information. Get something new.
const { randomServerCountryCode, randomServerCityName } = await MozillaVPN.pickRandomServer(); const { randomServerCountryCode, randomServerCityName } = await MozillaVPN.pickRandomLocation();
proxy = MozillaVPN.getProxy( proxy = MozillaVPN.getProxy(
randomServerCountryCode, randomServerCountryCode,

View file

@ -3,19 +3,12 @@ proxifiedContainers = {
// Slightly modified version of 'retrieve' which returns a direct proxy whenever an error is met. // Slightly modified version of 'retrieve' which returns a direct proxy whenever an error is met.
async retrieveFromBackground(cookieStoreId = null) { async retrieveFromBackground(cookieStoreId = null) {
return new Promise((resolve, reject) => { try {
proxifiedContainers.retrieve(cookieStoreId).then((success) => { const success = await proxifiedContainers.retrieve(cookieStoreId);
// TODO consider better methods of handling containers with MozillaVPN proxy return success.proxy;
// configs when MozillaVPN is not connected. Currently we are only messaging this } catch (e) {
// in the main panel. return Utils.DEFAULT_PROXY;
// if (mozProxyIsEnabled && !mozillaVpnConnected) { something better here ? } }
resolve(success.proxy);
}, function() {
resolve(Utils.DEFAULT_PROXY);
}).catch((error) => {
reject(error);
});
});
}, },
report_proxy_error(error, identifier = null) { report_proxy_error(error, identifier = null) {
@ -66,27 +59,21 @@ proxifiedContainers = {
}); });
}, },
set(cookieStoreId, proxy, initialize = false) { async set(cookieStoreId, proxy, initialize = false) {
return new Promise((resolve, reject) => {
if (initialize === true) { if (initialize === true) {
const proxifiedContainersStore = []; const proxifiedContainersStore = [];
proxifiedContainersStore.push({ proxifiedContainersStore.push({
cookieStoreId: cookieStoreId, cookieStoreId: cookieStoreId,
proxy: proxy proxy: proxy
}); });
await browser.storage.local.set({
browser.storage.local.set({
proxifiedContainersKey: proxifiedContainersStore proxifiedContainersKey: proxifiedContainersStore
}); });
return proxy;
resolve(proxy);
} }
// Assumes proxy is a properly formatted object // Assumes proxy is a properly formatted object
proxifiedContainers.retrieve().then((proxifiedContainersStore) => { const proxifiedContainersStore = await proxifiedContainers.retrieve();
let index = proxifiedContainersStore.findIndex(i => i.cookieStoreId === cookieStoreId); let index = proxifiedContainersStore.findIndex(i => i.cookieStoreId === cookieStoreId);
if (index === -1) { if (index === -1) {
proxifiedContainersStore.push({ proxifiedContainersStore.push({
cookieStoreId: cookieStoreId, cookieStoreId: cookieStoreId,
@ -99,20 +86,13 @@ proxifiedContainers = {
proxy: proxy proxy: proxy
}; };
} }
await browser.storage.local.set({
browser.storage.local.set({
proxifiedContainersKey: proxifiedContainersStore proxifiedContainersKey: proxifiedContainersStore
}); });
return proxifiedContainersStore[index];
resolve(proxifiedContainersStore[index]);
}, (errorObj) => {
reject(errorObj);
}).catch((error) => {
throw error;
});
});
}, },
//Parses a proxy description string of the format type://host[:port] or type://username:password@host[:port] (port is optional) //Parses a proxy description string of the format type://host[:port] or type://username:password@host[:port] (port is optional)
parseProxy(proxy_str, mozillaVpnData = null) { parseProxy(proxy_str, mozillaVpnData = null) {
const proxyRegexp = /(?<type>(https?)|(socks4?)):\/\/(\b(?<username>\w+):(?<password>\w+)@)?(?<host>((?:\d{1,3}\.){3}\d{1,3}\b)|(\b([\w.-]+)(\.([\w.-]+))+))(:(?<port>\d+))?/; const proxyRegexp = /(?<type>(https?)|(socks4?)):\/\/(\b(?<username>\w+):(?<password>\w+)@)?(?<host>((?:\d{1,3}\.){3}\d{1,3}\b)|(\b([\w.-]+)(\.([\w.-]+))+))(:(?<port>\d+))?/;
@ -133,26 +113,15 @@ proxifiedContainers = {
}, },
// Deletes the proxy information object for a specified cookieStoreId [useful for cleaning] // Deletes the proxy information object for a specified cookieStoreId [useful for cleaning]
delete(cookieStoreId) { async delete(cookieStoreId) {
return new Promise((resolve, reject) => {
// Assumes proxy is a properly formatted object // Assumes proxy is a properly formatted object
proxifiedContainers.retrieve().then((proxifiedContainersStore) => { const proxifiedContainersStore = await proxifiedContainers.retrieve();
const index = proxifiedContainersStore.findIndex(i => i.cookieStoreId === cookieStoreId); const index = proxifiedContainersStore.findIndex(i => i.cookieStoreId === cookieStoreId);
if (index !== -1) { if (index !== -1) {
proxifiedContainersStore.splice(index, 1); proxifiedContainersStore.splice(index, 1);
} }
await browser.storage.local.set({
browser.storage.local.set({
proxifiedContainersKey: proxifiedContainersStore proxifiedContainersKey: proxifiedContainersStore
}); });
resolve();
}, (errorObj) => {
reject(errorObj);
}).catch((error) => {
throw error;
});
});
} }
}; };