From 27066c4a0898ba92ac06415ce56dab6da5946172 Mon Sep 17 00:00:00 2001 From: Cesar Gonzalez Date: Tue, 4 Jun 2024 17:58:38 -0500 Subject: [PATCH] [PM-5189] Reworking how we handle updating ciphers on unlock and updating reference to auth status to use observable --- .../background/overlay.background.spec.ts | 4 ++- .../autofill/background/overlay.background.ts | 30 +++++++------------ 2 files changed, 13 insertions(+), 21 deletions(-) diff --git a/apps/browser/src/autofill/background/overlay.background.spec.ts b/apps/browser/src/autofill/background/overlay.background.spec.ts index dbece263aaa..4f2a8c67b9b 100644 --- a/apps/browser/src/autofill/background/overlay.background.spec.ts +++ b/apps/browser/src/autofill/background/overlay.background.spec.ts @@ -395,7 +395,7 @@ describe("OverlayBackground", () => { }); it("skips updating the inline menu list if the focused field has a value and the user status is not unlocked", async () => { - overlayBackground["userAuthStatus"] = AuthenticationStatus.Locked; + activeAccountStatusMock$.next(AuthenticationStatus.Locked); tabsSendMessageSpy.mockImplementation((_tab, message, _options) => { if (message.command === "checkMostRecentlyFocusedFieldHasValue") { return Promise.resolve(true); @@ -425,4 +425,6 @@ describe("OverlayBackground", () => { }); }); }); + + describe("updateOverlayCiphers", () => {}); }); diff --git a/apps/browser/src/autofill/background/overlay.background.ts b/apps/browser/src/autofill/background/overlay.background.ts index 3b9ea490fd7..6190861851e 100644 --- a/apps/browser/src/autofill/background/overlay.background.ts +++ b/apps/browser/src/autofill/background/overlay.background.ts @@ -54,7 +54,6 @@ export class OverlayBackground implements OverlayBackgroundInterface { private subFrameOffsetsForTab: SubFrameOffsetsForTab = {}; private updateInlineMenuPositionTimeout: number | NodeJS.Timeout; private inlineMenuFadeInTimeout: number | NodeJS.Timeout; - private userAuthStatus: AuthenticationStatus = AuthenticationStatus.LoggedOut; private inlineMenuButtonPort: chrome.runtime.Port; private inlineMenuListPort: chrome.runtime.Port; private expiredPorts: chrome.runtime.Port[] = []; @@ -393,7 +392,7 @@ export class OverlayBackground implements OverlayBackgroundInterface { if ( mostRecentlyFocusedFieldHasValue && (this.checkIsOverlayLoginCiphersPopulated(sender) || - this.userAuthStatus !== AuthenticationStatus.Unlocked) + (await this.getAuthStatus()) !== AuthenticationStatus.Unlocked) ) { return; } @@ -742,27 +741,16 @@ export class OverlayBackground implements OverlayBackgroundInterface { * and the inline menu list's ciphers will be updated. */ private async getAuthStatus() { - const formerAuthStatus = this.userAuthStatus; - this.userAuthStatus = await firstValueFrom(this.authService.activeAccountStatus$); - - if ( - this.userAuthStatus !== formerAuthStatus && - this.userAuthStatus === AuthenticationStatus.Unlocked - ) { - this.updateInlineMenuButtonAuthStatus(); - await this.updateOverlayCiphers(); - } - - return this.userAuthStatus; + return await firstValueFrom(this.authService.activeAccountStatus$); } /** * Sends a message to the inline menu button to update its authentication status. */ - private updateInlineMenuButtonAuthStatus() { + private async updateInlineMenuButtonAuthStatus() { this.inlineMenuButtonPort?.postMessage({ command: "updateInlineMenuButtonAuthStatus", - authStatus: this.userAuthStatus, + authStatus: await this.getAuthStatus(), }); } @@ -773,13 +761,13 @@ export class OverlayBackground implements OverlayBackgroundInterface { * * @param port - The port of the inline menu button */ - private handleInlineMenuButtonClicked(port: chrome.runtime.Port) { - if (this.userAuthStatus !== AuthenticationStatus.Unlocked) { - void this.unlockVault(port); + private async handleInlineMenuButtonClicked(port: chrome.runtime.Port) { + if ((await this.getAuthStatus()) !== AuthenticationStatus.Unlocked) { + await this.unlockVault(port); return; } - void this.openInlineMenu(false, true); + await this.openInlineMenu(false, true); } /** @@ -839,6 +827,8 @@ export class OverlayBackground implements OverlayBackgroundInterface { */ private async unlockCompleted(message: OverlayBackgroundExtensionMessage) { await this.getAuthStatus(); + await this.updateInlineMenuButtonAuthStatus(); + await this.updateOverlayCiphers(); if (message.data?.commandToRetry?.message?.command === "openAutofillInlineMenu") { await this.openInlineMenu(true);