Browse Source

this fixes #12

pull/2/head
gorhill 10 years ago
parent
commit
77cfb56d94
  1. 34
      src/js/async.js
  2. 10
      src/js/pagestats.js

34
src/js/async.js

@ -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) {
var updateBadgeCallback = function(pageUrl) {
µMatrix.updateBadgeAsync = (function(){
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);
if ( pageStats ) {
pageStats.updateBadge(tabId);
} else {
chrome.browserAction.setIcon({ tabId: tabId, path: 'img/browsericons/icon19.png' });
chrome.browserAction.setBadgeText({ tabId: tabId, text: '?' });
var pageStore = µm.pageStatsFromTabId(tabId);
if ( pageStore ) {
pageStore.updateBadge(tabId);
return;
} }
µ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;
})();
/******************************************************************************/ /******************************************************************************/

10
src/js/pagestats.js

@ -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 });
chrome.browserAction.setBadgeText({ tabId: tabId, text: µm.formatCount(this.distinctRequestCount) });
chrome.browserAction.setBadgeBackgroundColor({ tabId: tabId, color: '#000' });
µm.XAL.setIcon(
tabId,
iconPath,
µm.formatCount(this.distinctRequestCount)
);
}; };
/******************************************************************************/ /******************************************************************************/

Loading…
Cancel
Save