No-control checks prev state, change timeouted

This commit is contained in:
Ilya Ig. Petrov 2017-02-07 06:50:35 +00:00
parent a6b5b7ab57
commit 893fd94c17
3 changed files with 14 additions and 22 deletions

View File

@ -39,32 +39,29 @@
// Chrome API calls your cb in a context different from the point of API // Chrome API calls your cb in a context different from the point of API
// method invokation. // method invokation.
let err = chrome.runtime.lastError || chrome.extension.lastError; const err = chrome.runtime.lastError || chrome.extension.lastError;
if (err) { if (!err) {
err = new Error(err.message); // Add stack. return;
console.warn('API returned error:', err);
} }
return err; console.warn('API returned error:', err);
return new Error(err.message); // Add stack.
}, },
timeouted(cb = self.mandatory) { timeouted(cb = self.mandatory) {
return (...args) => setTimeout(cb.bind(null, ...args), 0) // setTimeout fixes error context, see bug #357568.
return (...args) => setTimeout(() => cb(...args), 0);
}, },
chromified(cb = self.mandatory(), ...replaceArgs) { chromified(cb = self.mandatory()) {
// Take error first callback and convert it to chrome API callback. // Take error first callback and convert it to chrome API callback.
return function(...args) { return function(...args) {
if (replaceArgs.length) {
args = replaceArgs;
}
const err = self.checkChromeError(); const err = self.checkChromeError();
// setTimeout fixes error context. self.timeouted(cb)(err, ...args);
setTimeout( cb.bind(null, err, ...args), 0 );
}; };

View File

@ -67,13 +67,9 @@
viewError(type = window.utils.mandatory(), err) { viewError(type = window.utils.mandatory(), err) {
let errors = {}; const errors = err ? { [type]: err } : this.idToError;
if (err) {
errors[type] = err;
} else {
errors = this.idToError;
}
const json = JSON.stringify(errors, errorJsonReplacer, 0); const json = JSON.stringify(errors, errorJsonReplacer, 0);
openAndFocus( openAndFocus(
'http://rebrand.ly/ac-error/?json=' + encodeURIComponent(json) + 'http://rebrand.ly/ac-error/?json=' + encodeURIComponent(json) +
(type ? '&type=' + encodeURIComponent(type) : '') + (type ? '&type=' + encodeURIComponent(type) : '') +
@ -144,7 +140,7 @@
icon = 'default-128.png', icon = 'default-128.png',
context = extName, context = extName,
ifSticky = true, ifSticky = true,
} } = {}
) { ) {
if ( !this.isOn(id) ) { if ( !this.isOn(id) ) {
@ -245,7 +241,8 @@
console.log('Proxy settings changed.', details); console.log('Proxy settings changed.', details);
const noCon = 'no-control'; const noCon = 'no-control';
if ( !handlers.isControllable(details) ) { const ifWasControllable = handler.ifControllable;
if ( !handlers.isControllable(details) && ifWasControllable ) {
handlers.mayNotify( handlers.mayNotify(
noCon, noCon,
chrome.i18n.getMessage('noControl'), chrome.i18n.getMessage('noControl'),

View File

@ -116,10 +116,8 @@
'https://dns.google.com/resolve?type=' + type + '&name=' + host, 'https://dns.google.com/resolve?type=' + type + '&name=' + host,
(err, res) => { (err, res) => {
console.log('After GET...');
if (res) { if (res) {
try { try {
console.log('Parsing JSON...');
res = JSON.parse(res); res = JSON.parse(res);
console.log('JSON parsed.'); console.log('JSON parsed.');
if (err || res.Status) { if (err || res.Status) {