From a7cce1a3ad89bfa1f12b08aa69358ae10a4e7b6b Mon Sep 17 00:00:00 2001 From: Cesar Gonzalez Date: Tue, 8 Aug 2023 15:56:42 -0500 Subject: [PATCH] [PM-669] Right Click Autofill List Contains Incorrect Entries (#5711) --- apps/browser/src/autofill/background/tabs.background.ts | 2 ++ .../src/autofill/browser/cipher-context-menu-handler.ts | 6 ++++++ apps/browser/src/platform/background.ts | 2 ++ apps/browser/src/platform/listeners/index.ts | 6 ++++++ apps/browser/src/platform/listeners/update-badge.ts | 7 +++++++ 5 files changed, 23 insertions(+) diff --git a/apps/browser/src/autofill/background/tabs.background.ts b/apps/browser/src/autofill/background/tabs.background.ts index 0f724c84dd..0655fd23b6 100644 --- a/apps/browser/src/autofill/background/tabs.background.ts +++ b/apps/browser/src/autofill/background/tabs.background.ts @@ -21,6 +21,8 @@ export default class TabsBackground { } this.focusedWindowId = windowId; + await this.main.refreshBadge(); + await this.main.refreshMenu(); this.main.messagingService.send("windowChanged"); }); diff --git a/apps/browser/src/autofill/browser/cipher-context-menu-handler.ts b/apps/browser/src/autofill/browser/cipher-context-menu-handler.ts index 2eccc03c12..d4f72e5663 100644 --- a/apps/browser/src/autofill/browser/cipher-context-menu-handler.ts +++ b/apps/browser/src/autofill/browser/cipher-context-menu-handler.ts @@ -81,6 +81,12 @@ export class CipherContextMenuHandler { ); } + static async windowsOnFocusChangedListener(windowId: number, serviceCache: CachedServices) { + const cipherContextMenuHandler = await CipherContextMenuHandler.create(serviceCache); + const tab = await BrowserApi.getTabFromCurrentWindow(); + await cipherContextMenuHandler.update(tab?.url); + } + static async tabsOnActivatedListener( activeInfo: chrome.tabs.TabActiveInfo, serviceCache: CachedServices diff --git a/apps/browser/src/platform/background.ts b/apps/browser/src/platform/background.ts index 949991df9f..f7913dade9 100644 --- a/apps/browser/src/platform/background.ts +++ b/apps/browser/src/platform/background.ts @@ -8,6 +8,7 @@ import { onCommandListener, onInstallListener, runtimeMessageListener, + windowsOnFocusChangedListener, tabsOnActivatedListener, tabsOnReplacedListener, tabsOnUpdatedListener, @@ -18,6 +19,7 @@ if (BrowserApi.manifestVersion === 3) { chrome.runtime.onInstalled.addListener(onInstallListener); chrome.alarms.onAlarm.addListener(onAlarmListener); registerAlarms(); + chrome.windows.onFocusChanged.addListener(windowsOnFocusChangedListener); chrome.tabs.onActivated.addListener(tabsOnActivatedListener); chrome.tabs.onReplaced.addListener(tabsOnReplacedListener); chrome.tabs.onUpdated.addListener(tabsOnUpdatedListener); diff --git a/apps/browser/src/platform/listeners/index.ts b/apps/browser/src/platform/listeners/index.ts index cf4950023f..60e304402a 100644 --- a/apps/browser/src/platform/listeners/index.ts +++ b/apps/browser/src/platform/listeners/index.ts @@ -6,6 +6,11 @@ import { onCommandListener } from "./on-command-listener"; import { onInstallListener } from "./on-install-listener"; import { UpdateBadge } from "./update-badge"; +const windowsOnFocusChangedListener = combine([ + UpdateBadge.windowsOnFocusChangedListener, + CipherContextMenuHandler.windowsOnFocusChangedListener, +]); + const tabsOnActivatedListener = combine([ UpdateBadge.tabsOnActivatedListener, CipherContextMenuHandler.tabsOnActivatedListener, @@ -33,6 +38,7 @@ const runtimeMessageListener = combine< ]); export { + windowsOnFocusChangedListener, tabsOnActivatedListener, tabsOnReplacedListener, tabsOnUpdatedListener, diff --git a/apps/browser/src/platform/listeners/update-badge.ts b/apps/browser/src/platform/listeners/update-badge.ts index 4623ff30f0..89b620ad6f 100644 --- a/apps/browser/src/platform/listeners/update-badge.ts +++ b/apps/browser/src/platform/listeners/update-badge.ts @@ -42,6 +42,13 @@ export class UpdateBadge { "deletedCipher", ]; + static async windowsOnFocusChangedListener( + windowId: number, + serviceCache: Record + ) { + await new UpdateBadge(self).run({ windowId, existingServices: serviceCache }); + } + static async tabsOnActivatedListener( activeInfo: chrome.tabs.TabActiveInfo, serviceCache: Record