mirror of
https://github.com/anticensority/runet-censorship-bypass.git
synced 2024-11-27 20:03:45 +03:00
Add timeouted, s/for/reduce
This commit is contained in:
parent
a460ed85d2
commit
a6b5b7ab57
|
@ -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.
|
||||
|
|
|
@ -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';
|
||||
|
|
|
@ -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)
|
||||
)
|
||||
);
|
||||
|
||||
|
|
|
@ -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(
|
||||
|
|
Loading…
Reference in New Issue
Block a user