From aaee898d951d753f2a8fa8b2689f7d74c5066af7 Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Fri, 26 Jul 2019 08:53:20 -0400 Subject: [PATCH] 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 --- platform/chromium/vapi-background.js | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/platform/chromium/vapi-background.js b/platform/chromium/vapi-background.js index cea64ada2e64b..5b964aa4f9784 100644 --- a/platform/chromium/vapi-background.js +++ b/platform/chromium/vapi-background.js @@ -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); });