Skip to content

Commit

Permalink
run proxyConfig.clear before proxyConfig.set
Browse files Browse the repository at this point in the history
  • Loading branch information
Richard Neomy committed Apr 20, 2018
1 parent c78918f commit f6b8fd0
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
14 changes: 13 additions & 1 deletion webextension/common.js
Expand Up @@ -63,7 +63,19 @@ function icon(config) {
if (/Firefox/.test(navigator.userAgent)) {
chrome.storage.onChanged.addListener(ps => {
if (ps['ffcurent']) {
icon(ps['ffcurent'].newValue);
browser.browserSettings.proxyConfig.get({}).then(settings => {
const mode = {
'none': 'direct',
'autoDetect': 'auto_detect',
'system': 'system',
'manual': 'fixed_servers',
'autoConfig': 'pac_script'
}[settings.value.proxyType];
// overwrite the mode to make sure we are displaying the actual proxy mode;
ps['ffcurent'].newValue.value.mode = mode;

icon(ps['ffcurent'].newValue);
});
}
});
chrome.storage.local.get({
Expand Down
Binary file modified webextension/data/.DS_Store
Binary file not shown.
8 changes: 5 additions & 3 deletions webextension/data/panel/firefox-proxy.js
Expand Up @@ -27,7 +27,7 @@ if (/Firefox/.test(navigator.userAgent)) {
addListener: c => chrome.proxy.callbacks.push(c)
};

chrome.proxy.settings.set = (config, callback = function() {}) => {
chrome.proxy.settings.set = async(config, callback = function() {}) => {
const proxySettings = {};

if (config.value.mode === 'direct') {
Expand Down Expand Up @@ -83,17 +83,19 @@ if (/Firefox/.test(navigator.userAgent)) {
proxySettings.autoConfigUrl = config.value.pacScript.url;
}
// console.log(proxySettings);
await browser.browserSettings.proxyConfig.clear({});
browser.browserSettings.proxyConfig.set({value: proxySettings}, () => {
const lastError = chrome.runtime.lastError;
if (chrome.runtime.lastError) {
chrome.proxy.errors.forEach(c => c(lastError));
}
});

chrome.storage.local.set({
await browser.storage.local.set({
'ffcurent': {
value: config.value
}
}, callback);
});
callback();
};
}

0 comments on commit f6b8fd0

Please sign in to comment.