this fixes #19

This commit is contained in:
gorhill 2014-08-04 08:42:57 -04:00
parent 08c01e11fd
commit e2c79b3919
2 changed files with 15 additions and 20 deletions

View File

@ -145,5 +145,5 @@ return asyncJobManager;
chrome.browserAction.setIcon({ tabId: tabId, path: 'img/browsericons/icon19-off.png' }); chrome.browserAction.setIcon({ tabId: tabId, path: 'img/browsericons/icon19-off.png' });
} }
}; };
this.asyncJobs.add('updateBadge-' + tabId, tabId, updateBadgeCallback, 200); this.asyncJobs.add('updateBadge-' + tabId, tabId, updateBadgeCallback, 250);
}; };

View File

@ -207,38 +207,33 @@ PageStore.prototype.recordRequest = function(type, url, reason) {
/******************************************************************************/ /******************************************************************************/
// Update badge, incrementally PageStore.prototype.updateBadgeFromTab = function(tab) {
if ( !tab ) {
// rhill 2013-11-09: well this sucks, I can't update icon/badge return;
// incrementally, as chromium overwrites the icon at some point without }
// notifying me, and this causes internal cached state to be out of sync.
PageStore.prototype.updateBadge = function() {
// https://github.com/gorhill/uBlock/issues/19
// TODO: need to check with µb object to see whether tab still exists.
var netFiltering = this.getNetFilteringSwitch(); var netFiltering = this.getNetFilteringSwitch();
var iconPath = netFiltering ? 'img/browsericons/icon19.png' : 'img/browsericons/icon19-off.png'; var iconPath = netFiltering ? 'img/browsericons/icon19.png' : 'img/browsericons/icon19-off.png';
chrome.browserAction.setIcon({ tabId: this.tabId, path: iconPath }); chrome.browserAction.setIcon({ tabId: tab.id, path: iconPath });
var iconStr = ''; var iconStr = '';
if ( µb.userSettings.showIconBadge && netFiltering && this.perLoadBlockedRequestCount ) { if ( µb.userSettings.showIconBadge && netFiltering && this.perLoadBlockedRequestCount ) {
iconStr = this.perLoadBlockedRequestCount.toLocaleString(); iconStr = this.perLoadBlockedRequestCount.toLocaleString();
} }
chrome.browserAction.setBadgeText({ chrome.browserAction.setBadgeText({ tabId: tab.id, text: iconStr });
tabId: this.tabId,
text: iconStr
});
if ( iconStr !== '' ) { if ( iconStr !== '' ) {
chrome.browserAction.setBadgeBackgroundColor({ chrome.browserAction.setBadgeBackgroundColor({ tabId: tab.id, color: '#666' });
tabId: this.tabId,
color: '#666'
});
} }
}; };
PageStore.prototype.updateBadge = function() {
// https://github.com/gorhill/uBlock/issues/19
// Since we may be called asynchronously, the tab id may not exist
// anymore, so this ensures it does still exist.
chrome.tabs.get(this.tabId, this.updateBadgeFromTab.bind(this));
};
/******************************************************************************/ /******************************************************************************/
return { return {