diff --git a/extensions/chromium/runet-censorship-bypass/extension/11-error-handlers-api.js b/extensions/chromium/runet-censorship-bypass/extension/11-error-handlers-api.js index ef90b64..3ef1631 100644 --- a/extensions/chromium/runet-censorship-bypass/extension/11-error-handlers-api.js +++ b/extensions/chromium/runet-censorship-bypass/extension/11-error-handlers-api.js @@ -4,7 +4,7 @@ const timeouted = window.utils.timeouted; - function errorJsonReplacer(key, value) { + const errorJsonReplacer = function errorJsonReplacer(key, value) { // fooWindow.ErrorEvent !== barWindow.ErrorEvent if (!( value && value.constructor @@ -47,7 +47,7 @@ return alt; - } + }; const openAndFocus = function openAndFocus(url) { @@ -60,6 +60,7 @@ const ifPrefix = 'if-on-'; const extName = chrome.runtime.getManifest().name; + const extVersion = chrome.runtime.getManifest().version.replace(/\d+\.\d+\./g, ''); window.apis.errorHandlers = { @@ -112,6 +113,7 @@ isControllable(details) { + console.log('IS',details); this.ifControllable = window.utils.areSettingsControllableFor(details); if (this.ifControllable) { @@ -132,13 +134,36 @@ }, + isControlled(details) { + + this.isControllable(details); + return this.ifControlled; + + }, + + updateControlState(cb = throwIfError) { + + chrome.proxy.settings.get( + {}, + timeouted( + (details) => { + + this.isControllable(details); + cb(); + + } + ) + ); + + }, + idToError: {}, mayNotify( id, title, errOrMessage, { icon = 'default-128.png', - context = extName, + context = extName + ' ' + extVersion, ifSticky = true, } = {} ) { @@ -241,7 +266,7 @@ console.log('Proxy settings changed.', details); const noCon = 'no-control'; - const ifWasControllable = handler.ifControllable; + const ifWasControllable = handlers.ifControllable; if ( !handlers.isControllable(details) && ifWasControllable ) { handlers.mayNotify( noCon, diff --git a/extensions/chromium/runet-censorship-bypass/extension/17-sync-pac-script-with-pac-provider-api.js b/extensions/chromium/runet-censorship-bypass/extension/17-sync-pac-script-with-pac-provider-api.js index 3c7b2a2..4bd68ba 100644 --- a/extensions/chromium/runet-censorship-bypass/extension/17-sync-pac-script-with-pac-provider-api.js +++ b/extensions/chromium/runet-censorship-bypass/extension/17-sync-pac-script-with-pac-provider-api.js @@ -30,6 +30,7 @@ const Warning = window.apis.errorsLib.Warning; const httpLib = window.apis.httpLib; + const handlers = window.apis.errorHandlers; const asyncLogGroup = function asyncLogGroup(...args) { @@ -65,9 +66,9 @@ if (err) { return cb(err); } - chrome.proxy.settings.get({}, timeouted( (details) => { + handlers.updateControlState( () => { - if ( !window.utils.areSettingsControlledFor( details ) ) { + if ( !handlers.ifControlled ) { console.warn('Failed, other extension is in control.'); return cb( @@ -77,7 +78,8 @@ } console.log('Successfuly set PAC in proxy settings..'); cb(); - })); + + }); })); @@ -403,7 +405,9 @@ return cb(err); } this.setCurrentPacProviderKey(null); - this.pushToStorageAsync(cb); + this.pushToStorageAsync( + () => handlers.updateControlState(cb) + ); }) )