From a44f594e6d5d2f4a923d2f1c7dbc3fe0a65f1b1d Mon Sep 17 00:00:00 2001 From: Cesar Gonzalez Date: Tue, 25 Jun 2024 12:23:53 -0500 Subject: [PATCH] [PM-5189] Fixing an issue found when switching between open windows --- .../autofill/background/overlay.background.ts | 16 ++++++++++++++-- .../src/autofill/background/tabs.background.ts | 9 +++------ 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/apps/browser/src/autofill/background/overlay.background.ts b/apps/browser/src/autofill/background/overlay.background.ts index 18fe6bc5243..bb33fe5c55b 100644 --- a/apps/browser/src/autofill/background/overlay.background.ts +++ b/apps/browser/src/autofill/background/overlay.background.ts @@ -163,7 +163,7 @@ export class OverlayBackground implements OverlayBackgroundInterface { private initOverlayEventObservables() { this.repositionInlineMenuSubject .pipe( - debounceTime(950), + debounceTime(1000), switchMap((sender) => this.repositionInlineMenu(sender)), ) .subscribe(); @@ -176,7 +176,7 @@ export class OverlayBackground implements OverlayBackgroundInterface { // Debounce used to update inline menu position merge( - this.startUpdateInlineMenuPositionSubject.pipe(debounceTime(250)), + this.startUpdateInlineMenuPositionSubject.pipe(debounceTime(150)), this.cancelUpdateInlineMenuPositionSubject, ) .pipe(switchMap((sender) => this.updateInlineMenuPositionAfterRepositionEvent(sender))) @@ -216,6 +216,9 @@ export class OverlayBackground implements OverlayBackgroundInterface { async updateInlineMenuCiphers() { const authStatus = await firstValueFrom(this.authService.activeAccountStatus$); if (authStatus !== AuthenticationStatus.Unlocked) { + if (this.focusedFieldData) { + void this.closeInlineMenuAfterCiphersUpdate(); + } return; } @@ -224,6 +227,10 @@ export class OverlayBackground implements OverlayBackgroundInterface { return; } + if (this.focusedFieldData && currentTab.id !== this.focusedFieldData.tabId) { + void this.closeInlineMenuAfterCiphersUpdate(); + } + this.inlineMenuCiphers = new Map(); const ciphersViews = (await this.cipherService.getAllDecryptedForUrl(currentTab.url)).sort( (a, b) => this.cipherService.sortCiphersByLastUsedThenName(a, b), @@ -266,6 +273,11 @@ export class OverlayBackground implements OverlayBackgroundInterface { return inlineMenuCipherData; } + private async closeInlineMenuAfterCiphersUpdate() { + const focusedFieldTab = await BrowserApi.getTab(this.focusedFieldData.tabId); + this.closeInlineMenu({ tab: focusedFieldTab }, { forceCloseInlineMenu: true }); + } + /** * Handles aggregation of page details for a tab. Stores the page details * in association with the tabId of the tab that sent the message. diff --git a/apps/browser/src/autofill/background/tabs.background.ts b/apps/browser/src/autofill/background/tabs.background.ts index 1aa2cacd640..a9feb8c61c6 100644 --- a/apps/browser/src/autofill/background/tabs.background.ts +++ b/apps/browser/src/autofill/background/tabs.background.ts @@ -94,7 +94,7 @@ export default class TabsBackground { return; } - await this.overlayBackground.updateInlineMenuCiphers(); + this.overlayBackground.updateInlineMenuCiphers(); if (this.main.onUpdatedRan) { return; @@ -121,10 +121,7 @@ export default class TabsBackground { * for the current tab. Also updates the overlay ciphers. */ private updateCurrentTabData = async () => { - await Promise.all([ - this.main.refreshBadge(), - this.main.refreshMenu(), - this.overlayBackground.updateInlineMenuCiphers(), - ]); + this.overlayBackground.updateInlineMenuCiphers(); + await Promise.all([this.main.refreshBadge(), this.main.refreshMenu()]); }; }