diff --git a/extensions/chromium/runet-censorship-bypass/extension/00-init-apis.js b/extensions/chromium/runet-censorship-bypass/extension/00-init-apis.js index d1679d5..d743f53 100644 --- a/extensions/chromium/runet-censorship-bypass/extension/00-init-apis.js +++ b/extensions/chromium/runet-censorship-bypass/extension/00-init-apis.js @@ -48,6 +48,12 @@ }, + timeouted(cb = self.mandatory) { + + return (...args) => setTimeout(cb.bind(null, ...args), 0) + + }, + chromified(cb = self.mandatory(), ...replaceArgs) { // Take error first callback and convert it to chrome API callback. 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 a0913d2..94e7215 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 @@ -2,7 +2,7 @@ { // Private namespace - const chromified = window.utils.chromified; + const timeouted = window.utils.timeouted; function errorJsonReplacer(key, value) { @@ -204,10 +204,10 @@ chrome.proxy.settings.get( {}, - chromified((err, details) => handlers.isControllable(details)) + timeouted( handlers.isControllable.bind(handlers) ) ); - chrome.notifications.onClicked.addListener( chromified( (_, notId) => { + chrome.notifications.onClicked.addListener( timeouted( (notId) => { chrome.notifications.clear(notId); if(notId === 'no-control') { @@ -221,7 +221,7 @@ handlers.installListenersOn(window, 'BG'); - chrome.proxy.onProxyError.addListener( chromified( (_, details) => { + chrome.proxy.onProxyError.addListener( timeouted( (details) => { if (!handlers.ifControlled) { return; @@ -241,7 +241,7 @@ })); - chrome.proxy.settings.onChange.addListener( chromified((_, details) => { + chrome.proxy.settings.onChange.addListener( timeouted( (details) => { console.log('Proxy settings changed.', details); const noCon = 'no-control'; diff --git a/extensions/chromium/runet-censorship-bypass/extension/15-pac-kitchen-api.js b/extensions/chromium/runet-censorship-bypass/extension/15-pac-kitchen-api.js index 857c924..e9a7ad4 100644 --- a/extensions/chromium/runet-censorship-bypass/extension/15-pac-kitchen-api.js +++ b/extensions/chromium/runet-censorship-bypass/extension/15-pac-kitchen-api.js @@ -5,6 +5,7 @@ const mandatory = window.utils.mandatory; const throwIfError = window.utils.throwIfError; const chromified = window.utils.chromified; + const timeouted = window.utils.timeouted; const kitchenStartsMark = '\n\n//%#@@@@@@ PAC_KITCHEN_STARTS @@@@@@#%'; const kitchenState = window.utils.createStorage('pac-kitchen-'); @@ -256,7 +257,7 @@ details ? resolve(details) - : chrome.proxy.settings.get({}, chromified( (_, res) => resolve(res))) + : chrome.proxy.settings.get({}, timeouted(resolve) ) ).then( (details) => { @@ -365,8 +366,8 @@ pacKitchen.checkIncontinence(); chrome.proxy.settings.onChange.addListener( - chromified( - (_, details) => pacKitchen.checkIncontinence(details) + timeouted( + pacKitchen.checkIncontinence.bind(pacKitchen) ) ); 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 dd7d91f..3c7b2a2 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 @@ -24,6 +24,7 @@ const mandatory = window.utils.mandatory; const throwIfError = window.utils.throwIfError; const chromified = window.utils.chromified; + const timeouted = window.utils.timeouted; const clarifyThen = window.apis.errorsLib.clarifyThen; const Warning = window.apis.errorsLib.Warning; @@ -64,7 +65,7 @@ if (err) { return cb(err); } - chrome.proxy.settings.get({}, chromified((_, details) => { + chrome.proxy.settings.get({}, timeouted( (details) => { if ( !window.utils.areSettingsControlledFor( details ) ) { @@ -118,21 +119,20 @@ } // Employ all urls, the latter are fallbacks for the former. - let pacDataPromise = Promise.reject(); - for(const url of provider.pacUrls) { - - pacDataPromise = pacDataPromise.catch( - (err) => new Promise( + const pacDataPromise = provider.pacUrls.reduce( + (promise, url) => promise.catch( + () => new Promise( (resolve, reject) => httpLib.get( url, (newErr, pacData) => newErr ? reject(newErr) : resolve(pacData) ) ) - ); - - } + ), + Promise.reject() + ); pacDataPromise.then( + (pacData) => { setPacAsync( @@ -144,11 +144,13 @@ ); }, + clarifyThen( 'Не удалось скачать PAC-скрипт с адресов: [ ' + provider.pacUrls.join(' , ') + ' ].', cb ) + ); }); @@ -274,7 +276,7 @@ chrome.storage.local.clear( () => chrome.storage.local.set( onlySettable, - chromified(cb, onlySettable) + chromified(cb) ) ); @@ -427,7 +429,7 @@ const antiCensorRu = window.apis.antiCensorRu; chrome.alarms.onAlarm.addListener( - chromified((_, alarm) => { + timeouted( (alarm) => { if (alarm.name === antiCensorRu._periodicUpdateAlarmReason) { console.log(