Fix apis error context with timeout, change default locale, colorize icons

This commit is contained in:
Ilya Ig. Petrov 2016-12-23 13:38:35 +00:00
parent 34c94eb3d3
commit 85859b3f4b
15 changed files with 52 additions and 25 deletions

View File

@ -11,7 +11,7 @@ window.utils = {
messages: { messages: {
searchSettingsUrlFor(niddle) { searchSettingsForUrl(niddle) {
return 'chrome://settings/search#' + (chrome.i18n.getMessage(niddle) || niddle); return 'chrome://settings/search#' + (chrome.i18n.getMessage(niddle) || niddle);
@ -20,7 +20,7 @@ window.utils = {
whichExtensionHtml() { whichExtensionHtml() {
return chrome.i18n.getMessage('noControl') + return chrome.i18n.getMessage('noControl') +
` <a href="${ this.searchSettingsUrlFor('proxy') }"> ` <a href="${ this.searchSettingsForUrl('proxy') }">
${ chrome.i18n.getMessage('which') } ${ chrome.i18n.getMessage('which') }
</a>`; </a>`;

View File

@ -22,7 +22,7 @@
for(const prop in value) { for(const prop in value) {
if (/^[A-Z]/.test(prop)) { if (/^[A-Z]/.test(prop)) {
console.log(prop); // MOUSEMOVE, CLICK, KEYUP, NONE, etc.
continue; continue;
} }
alt[prop] = value[prop]; alt[prop] = value[prop];
@ -78,10 +78,11 @@
window.apis.errorHandlers = { window.apis.errorHandlers = {
viewError(err) { viewErrorVoid(err) {
const json = JSON.stringify(err, errorJsonReplacer, 0);
openAndFocus( openAndFocus(
'https://rebrand.ly/ac-error/?' + btoa(JSON.stringify(err, errorJsonReplacer, 0)) 'https://rebrand.ly/ac-error/?' + btoa(json)
); );
}, },
@ -96,7 +97,7 @@
}, },
switch(onOffStr, eventName) { switchVoid(onOffStr, eventName) {
if (!['on', 'off'].includes(onOffStr)) { if (!['on', 'off'].includes(onOffStr)) {
throw new TypeError('First argument bust be "on" or "off".'); throw new TypeError('First argument bust be "on" or "off".');
@ -131,7 +132,7 @@
idToError: {}, idToError: {},
mayNotify( mayNotifyVoid(
id, title, errOrMessage, id, title, errOrMessage,
icon = 'default-128.png', icon = 'default-128.png',
context = extName context = extName
@ -158,12 +159,12 @@
}, },
installListenersOn(win, name, cb) { installListenersOnAsync(win, name, cb) {
win.addEventListener('error', (errEvent) => { win.addEventListener('error', (errEvent) => {
console.warn(name + ':GLOBAL ERROR', errEvent); console.warn(name + ':GLOBAL ERROR', errEvent);
this.mayNotify('ext-error', 'Ошибка расширения', errEvent, this.mayNotifyVoid('ext-error', 'Ошибка расширения', errEvent,
'ext-error-128.png'); 'ext-error-128.png');
}); });
@ -200,14 +201,14 @@
chrome.notifications.clear(notId); chrome.notifications.clear(notId);
if(notId === 'no-control') { if(notId === 'no-control') {
return openAndFocus( window.utils.messages.searchSettingsUrlFor('proxy') ); return openAndFocus( window.utils.messages.searchSettingsForUrl('proxy') );
} }
const errors = handlers.idToError; const errors = handlers.idToError;
handlers.viewError(errors); handlers.viewErrorVoid(errors);
}); });
handlers.installListenersOn(window, 'BG'); handlers.installListenersOnAsync(window, 'BG');
chrome.proxy.onProxyError.addListener((details) => { chrome.proxy.onProxyError.addListener((details) => {
@ -222,7 +223,7 @@
*/ */
console.warn('PAC ERROR', details); console.warn('PAC ERROR', details);
// TOOD: add "view pac script at this line" button. // TOOD: add "view pac script at this line" button.
handlers.mayNotify('pac-error', 'Ошибка PAC!', handlers.mayNotifyVoid('pac-error', 'Ошибка PAC!',
details.error + '\n' + details.details, details.error + '\n' + details.details,
'pac-error-128.png' 'pac-error-128.png'
); );
@ -234,7 +235,7 @@
console.log('Proxy settings changed.', details); console.log('Proxy settings changed.', details);
const noCon = 'no-control'; const noCon = 'no-control';
if ( handlers.isNotControlled(details) ) { if ( handlers.isNotControlled(details) ) {
handlers.mayNotify( handlers.mayNotifyVoid(
noCon, noCon,
chrome.i18n.getMessage('noControl'), chrome.i18n.getMessage('noControl'),
chrome.i18n.getMessage('which'), chrome.i18n.getMessage('which'),

View File

@ -18,6 +18,7 @@
See errorHandlers api for more. See errorHandlers api for more.
*/ */
{ // Private namespace starts. { // Private namespace starts.
function mandatory() { function mandatory() {

View File

@ -0,0 +1,26 @@
'use strict';
/* `setTimeout` changes context of execution from other window
(e.g. popup) to background window, so we may catch errors
in bg error handlers.
More: https://bugs.chromium.org/p/chromium/issues/detail?id=357568
setTimeout is applied to Async methods only (name ends with Async)
*/
// Fix error context of methods of all APIs.
for(const apiName of Object.keys(window.apis)) {
const api = window.apis[apiName];
for(const prop of Object.keys(api)) {
const method = api[prop];
if ( !(
typeof(api[prop]) === 'function'
&& ['Async', 'Void'].some( (suff) => method.name.endsWith(suff) )
)
) {
continue;
}
api[prop] = function(...args) {
setTimeout(method.bind(this, ...args), 0);
};
}
}

View File

@ -3,7 +3,7 @@
"message": "Runet Censorship Bypass" "message": "Runet Censorship Bypass"
}, },
"extDesc": { "extDesc": {
"message": "Circumvent Russian internet censorship:" "message": "Circumvent Russian Internet Censorship: https://rebrand.ly/ac-wiki"
}, },
"proxy": { "proxy": {
"message": "proxy" "message": "proxy"

View File

@ -3,7 +3,7 @@
"message": "Обход блокировок Рунета" "message": "Обход блокировок Рунета"
}, },
"extDesc": { "extDesc": {
"message": "Обход интернет-цензуры в России:" "message": "Обход интернет-цензуры в России: https://rebrand.ly/ac-wiki"
}, },
"proxy": { "proxy": {
"message": "прокси" "message": "прокси"

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.6 KiB

After

Width:  |  Height:  |  Size: 9.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.9 KiB

After

Width:  |  Height:  |  Size: 8.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.4 KiB

After

Width:  |  Height:  |  Size: 9.6 KiB

View File

@ -2,8 +2,8 @@
"manifest_version": 2, "manifest_version": 2,
"name": "__MSG_extName__", "name": "__MSG_extName__",
"default_locale": "en", "default_locale": "ru",
"description": "__MSG_extDesc__ https://rebrand.ly/ac-wiki", "description": "__MSG_extDesc__",
"version": "0.0.0.16", "version": "0.0.0.16",
"icons": { "icons": {
"128": "/icons/default-128.png" "128": "/icons/default-128.png"
@ -27,6 +27,7 @@
"00-init-apis.js", "00-init-apis.js",
"11-api-error-handlers.js", "11-api-error-handlers.js",
"12-api-sync-pac-script-with-pac-provider.js", "12-api-sync-pac-script-with-pac-provider.js",
"20-api-fixes.js",
"30-block-informer.js", "30-block-informer.js",
"40-context-menus.js" "40-context-menus.js"
] ]

View File

@ -1,7 +1,7 @@
'use strict'; 'use strict';
chrome.runtime.getBackgroundPage( (backgroundPage) => chrome.runtime.getBackgroundPage( (backgroundPage) =>
backgroundPage.apis.errorHandlers.installListenersOn(window, 'POPUP', () => { backgroundPage.apis.errorHandlers.installListenersOnAsync(window, 'POPUP', () => {
const getStatus = () => document.querySelector('#status'); const getStatus = () => document.querySelector('#status');
@ -41,7 +41,7 @@ chrome.runtime.getBackgroundPage( (backgroundPage) =>
} }
const dateElement = document.querySelector('.update-date'); const dateElement = document.querySelector('.update-date');
dateElement.innerText = dateForUser + ' / T=' + (antiCensorRu.pacUpdatePeriodInMinutes/60) + 'ч'; dateElement.innerText = dateForUser + ' / ' + (antiCensorRu.pacUpdatePeriodInMinutes/60) + 'ч';
dateElement.title = new Date(antiCensorRu.lastPacUpdateStamp) dateElement.title = new Date(antiCensorRu.lastPacUpdateStamp)
.toLocaleString('ru-RU'); .toLocaleString('ru-RU');
@ -89,7 +89,7 @@ chrome.runtime.getBackgroundPage( (backgroundPage) =>
); );
getStatus().querySelector('.link-button').onclick = function() { getStatus().querySelector('.link-button').onclick = function() {
errorHandlers.viewError(err); errorHandlers.viewErrorVoid(err);
return false; return false;
}; };
@ -185,7 +185,7 @@ chrome.runtime.getBackgroundPage( (backgroundPage) =>
box.onclick = function() { box.onclick = function() {
const id = this.id.replace('if-on-', ''); const id = this.id.replace('if-on-', '');
backgroundPage.apis.errorHandlers.switch( return backgroundPage.apis.errorHandlers.switchVoid(
this.checked ? 'on' : 'off', this.checked ? 'on' : 'off',
id id
); );
@ -196,7 +196,6 @@ chrome.runtime.getBackgroundPage( (backgroundPage) =>
}); });
if( errorHandlers.ifNotControlled ) { if( errorHandlers.ifNotControlled ) {
console.log('ADDING');
document.getElementById('which-extension').innerHTML = backgroundPage.utils.messages.whichExtensionHtml(); document.getElementById('which-extension').innerHTML = backgroundPage.utils.messages.whichExtensionHtml();
document.querySelectorAll('.if-not-controlled').forEach( (node) => { document.querySelectorAll('.if-not-controlled').forEach( (node) => {

View File

@ -10,7 +10,6 @@ Use only if really required because of performance penalty.
const updateLinks = () => { const updateLinks = () => {
console.log('UPDATE');
const links = document.querySelectorAll('a:not([href=""])'); const links = document.querySelectorAll('a:not([href=""])');
for (let i = 0; i < links.length; i++) { for (let i = 0; i < links.length; i++) {
const ln = links[i]; const ln = links[i];