diff --git a/extensions/chromium/minimalistic-pac-setter/extension/1-sync-pac-script-with-pac-provider.js b/extensions/chromium/minimalistic-pac-setter/extension/1-sync-pac-script-with-pac-provider.js index e2d5001..4910b6a 100755 --- a/extensions/chromium/minimalistic-pac-setter/extension/1-sync-pac-script-with-pac-provider.js +++ b/extensions/chromium/minimalistic-pac-setter/extension/1-sync-pac-script-with-pac-provider.js @@ -155,7 +155,8 @@ (pushErr) => cb(pacErr || ipsErr || pushErr, pacRes) ); - } + }, + cb ); }, @@ -346,6 +347,37 @@ } + function setPac(pacData, cb) { + + const config = { + mode: 'pac_script', + pacScript: { + mandatory: false, + data: pacData + } + }; + console.log('Setting chrome proxy settings...'); + chrome.proxy.settings.set( {value: config}, () => { + + const err = checkChromeError(); + if (err) { + return cb(err); + } + chrome.proxy.settings.get({}, (details) => { + + const ifThis = details.levelOfControl.startsWith('controlled_by_this'); + if (!ifThis) { + console.warn('Failed, other extension is in control.'); + return cb({clarification: {message:'Настройки прокси контролирует другое расширение. Какое?'}}); + } + console.log('Successfuly set PAC in proxy settings..'); + return cb(); + }); + + }); + + } + function httpGet(url, cb) { const start = Date.now(); @@ -518,16 +550,7 @@ }; return cb(err); } - - const config = { - mode: 'pac_script', - pacScript: { - mandatory: false, - data: pacData - } - }; - console.log('Setting chrome proxy settings...'); - chrome.proxy.settings.set( {value: config}, chromified(cb) ); + setPac(pacData, cb); } ); @@ -548,3 +571,9 @@ window.addEventListener('unhandledrejection', (event) => { throw event.reason; }); + +chrome.proxy.settings.onChange.addListener((details) => { + + console.log('Settings changed:', details); + +}); diff --git a/extensions/chromium/minimalistic-pac-setter/extension/pages/choose-pac-provider/index.html b/extensions/chromium/minimalistic-pac-setter/extension/pages/choose-pac-provider/index.html index 7e0fa9e..30118fa 100755 --- a/extensions/chromium/minimalistic-pac-setter/extension/pages/choose-pac-provider/index.html +++ b/extensions/chromium/minimalistic-pac-setter/extension/pages/choose-pac-provider/index.html @@ -50,8 +50,9 @@