1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-11-07 03:12:33 +01:00

this fixes #225, and comply with chromium dev's advice on how to use setIcon()

This commit is contained in:
gorhill 2014-09-11 10:53:36 -04:00
parent c9040b15dd
commit 7089c4d85d
2 changed files with 14 additions and 28 deletions

View File

@ -19,7 +19,7 @@
Home: https://github.com/gorhill/uBlock
*/
/* global chrome, µBlock */
/* global µBlock */
/******************************************************************************/
@ -137,26 +137,18 @@ return asyncJobManager;
if ( tabId < 0 ) {
return;
}
var safeUpdateBagde = function(tab) {
if ( chrome.runtime.lastError ) {
return;
}
var pageStore = µBlock.pageStoreFromTabId(tab.id);
var µb = this;
var updateBadge = function() {
var pageStore = µb.pageStoreFromTabId(tabId);
if ( pageStore ) {
pageStore.updateBadge();
} else {
chrome.browserAction.setIcon({
tabId: tab.id,
path: { '19': 'img/browsericons/icon19-off.png', '38': 'img/browsericons/icon38-off.png' }
});
return;
}
µb.XAL.setIcon(
tabId,
{ '19': 'img/browsericons/icon19-off.png', '38': 'img/browsericons/icon38-off.png' },
''
);
};
// https://github.com/gorhill/uBlock/issues/19
// https://github.com/gorhill/uBlock/issues/207
// Since we may be called asynchronously, the tab id may not exist
// anymore, so this ensures it does still exist.
var unsafeUpdateBadge = function(tabId) {
chrome.tabs.get(tabId, safeUpdateBagde);
};
this.asyncJobs.add('updateBadge-' + tabId, tabId, unsafeUpdateBadge, 250);
this.asyncJobs.add('updateBadge-' + tabId, tabId, updateBadge, 250);
};

View File

@ -19,7 +19,7 @@
Home: https://github.com/gorhill/uBlock
*/
/* global chrome, µBlock */
/* global µBlock */
/*******************************************************************************
@ -213,21 +213,15 @@ PageStore.prototype.recordRequest = function(type, url, reason) {
PageStore.prototype.updateBadge = function() {
var netFiltering = this.getNetFilteringSwitch();
var iconPath = netFiltering ?
var iconPaths = netFiltering ?
{ '19': 'img/browsericons/icon19.png', '38': 'img/browsericons/icon38.png' } :
{ '19': 'img/browsericons/icon19-off.png', '38': 'img/browsericons/icon38-off.png' };
chrome.browserAction.setIcon({ tabId: this.tabId, path: iconPath });
var iconStr = '';
if ( µb.userSettings.showIconBadge && netFiltering && this.perLoadBlockedRequestCount ) {
iconStr = µb.utils.formatCount(this.perLoadBlockedRequestCount);
}
chrome.browserAction.setBadgeText({ tabId: this.tabId, text: iconStr });
if ( iconStr !== '' ) {
chrome.browserAction.setBadgeBackgroundColor({ tabId: this.tabId, color: '#666' });
}
µb.XAL.setIcon(this.tabId, iconPaths, iconStr);
};
// https://www.youtube.com/watch?v=drW8p_dTLD4