Skip to content

Commit

Permalink
Minor refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
erosman authored Sep 17, 2023
1 parent 284193c commit dbc9560
Showing 1 changed file with 20 additions and 21 deletions.
41 changes: 20 additions & 21 deletions src/content/proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,6 @@ import {Action} from './action.js';

export class Proxy {

static async #getSettings() {
// https://bugzilla.mozilla.org/show_bug.cgi?id=1725981
// proxy.settings is not supported on Android
if (!browser.proxy.settings) {
return {value: {}};
}

const conf = await browser.proxy.settings.get({});
// https://bugs.chromium.org/p/chromium/issues/detail?id=29683
// https://developer.chrome.com/docs/extensions/mv3/manifest/icons/
// SVG is not supported by Chrome

// check if proxy.settings is controlled_by_this_extension
if (conf.levelOfControl !== 'controlled_by_this_extension') {
const path = App.firefox ? '/image/icon-off.svg' : '/image/icon-off.png;'
browser.browserAction.setIcon({path});
}

return conf;
}

static set(pref) {
// --- check mode
switch (true) {
Expand All @@ -45,6 +24,26 @@ export class Proxy {
Action.set(pref);
}

static async #getSettings() {
// https://bugzilla.mozilla.org/show_bug.cgi?id=1725981
// proxy.settings is not supported on Android
if (!browser.proxy.settings) {
return {value: {}};
}

const conf = await browser.proxy.settings.get({});

// https://bugs.chromium.org/p/chromium/issues/detail?id=29683
// https://developer.chrome.com/docs/extensions/mv3/manifest/icons/
// SVG is not supported by Chrome
// check if proxy.settings is controlled_by_this_extension
if (conf.levelOfControl !== 'controlled_by_this_extension') {
browser.browserAction.setIcon({path: '/image/icon-off.png'});
}

return conf;
}

static async #setFirefox(pref) {
// retain settings as Network setting is partially customisable
const conf = await this.#getSettings();
Expand Down

0 comments on commit dbc9560

Please sign in to comment.