this fixes #12

pull/2/head
gorhill 10 years ago
parent bd411290dd
commit 77cfb56d94

@ -133,8 +133,12 @@ return asyncJobManager;
// Update visual of extension icon. // Update visual of extension icon.
// A time out is used to coalesce adjacent requests to update badge. // A time out is used to coalesce adjacent requests to update badge.
µMatrix.updateBadge = function(pageUrl) { µMatrix.updateBadgeAsync = (function(){
var updateBadgeCallback = function(pageUrl) { var µm = µMatrix;
// Cache callback definition, it was a bad idea to define this one inside
// updateBadgeAsync
var updateBadge = function(pageUrl) {
var µm = µMatrix; var µm = µMatrix;
if ( pageUrl === µm.behindTheSceneURL ) { if ( pageUrl === µm.behindTheSceneURL ) {
return; return;
@ -143,17 +147,27 @@ return asyncJobManager;
if ( !tabId ) { if ( !tabId ) {
return; return;
} }
var pageStats = µm.pageStatsFromTabId(tabId); var pageStore = µm.pageStatsFromTabId(tabId);
if ( pageStats ) { if ( pageStore ) {
pageStats.updateBadge(tabId); pageStore.updateBadge(tabId);
} else { return;
chrome.browserAction.setIcon({ tabId: tabId, path: 'img/browsericons/icon19.png' });
chrome.browserAction.setBadgeText({ tabId: tabId, text: '?' });
} }
µm.XAL.setIcon(
tabId,
{ '19': 'img/browsericons/icon19.png' },
'?'
);
}; };
this.asyncJobs.add('updateBadge ' + pageUrl, pageUrl, updateBadgeCallback, 250); var updateBadgeAsync = function(pageUrl) {
}; if ( typeof pageUrl !== 'string' || pageUrl === '' ) {
return;
}
µm.asyncJobs.add('updateBadge-' + pageUrl, pageUrl, updateBadge, 250);
};
return updateBadgeAsync;
})();
/******************************************************************************/ /******************************************************************************/

@ -504,7 +504,7 @@ PageStore.prototype.recordRequest = function(type, url, block) {
// rhill 2013-10-26: This needs to be called even if the request is // rhill 2013-10-26: This needs to be called even if the request is
// already logged, since the request stats are cached for a while after // already logged, since the request stats are cached for a while after
// the page is no longer visible in a browser tab. // the page is no longer visible in a browser tab.
µm.updateBadge(this.pageUrl); µm.updateBadgeAsync(this.pageUrl);
// Count blocked/allowed requests // Count blocked/allowed requests
this.requestStats.record(type, block); this.requestStats.record(type, block);
@ -571,9 +571,11 @@ PageStore.prototype.updateBadge = function(tabId) {
} else { } else {
iconPath = 'img/browsericons/icon19.png'; iconPath = 'img/browsericons/icon19.png';
} }
chrome.browserAction.setIcon({ tabId: tabId, path: iconPath }); µm.XAL.setIcon(
chrome.browserAction.setBadgeText({ tabId: tabId, text: µm.formatCount(this.distinctRequestCount) }); tabId,
chrome.browserAction.setBadgeBackgroundColor({ tabId: tabId, color: '#000' }); iconPath,
µm.formatCount(this.distinctRequestCount)
);
}; };
/******************************************************************************/ /******************************************************************************/

Loading…
Cancel
Save