Ensure icon & context menu are up to date on window focus change

Related issue:
- https://github.com/uBlockOrigin/uBlock-issues/issues/151

Related feedback:
- https://github.com/uBlockOrigin/uBlock-issues/issues/680#issuecomment-515215220
This commit is contained in:
Raymond Hill 2019-07-26 08:53:20 -04:00
parent 869c63f821
commit aaee898d95
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2
1 changed files with 19 additions and 2 deletions

View File

@ -327,10 +327,27 @@ vAPI.Tabs = class {
this.onUpdated(tabId, changeInfo, tab);
});
browser.tabs.onActivated.addListener((tabId, details) => {
this.onActivated(tabId, details);
browser.tabs.onActivated.addListener(details => {
this.onActivated(details);
});
// https://github.com/uBlockOrigin/uBlock-issues/issues/151
// https://github.com/uBlockOrigin/uBlock-issues/issues/680#issuecomment-515215220
if ( browser.windows instanceof Object ) {
browser.windows.onFocusChanged.addListener(windowId => {
if ( windowId === browser.windows.WINDOW_ID_NONE ) { return; }
browser.tabs.query({ active: true, windowId }, tabs => {
if ( Array.isArray(tabs) === false ) { return; }
if ( tabs.length === 0 ) { return; }
const tab = tabs[0];
this.onActivated({
tabId: tab.id,
windowId: tab.windowId,
});
});
});
}
browser.tabs.onRemoved.addListener((tabId, details) => {
this.onClosed(tabId, details);
});