mirror of
https://github.com/bitwarden/browser
synced 2025-12-16 00:03:56 +00:00
[PM-5189] Reworking how we handle updating ciphers on unlock and updating reference to auth status to use observable
This commit is contained in:
@@ -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", () => {});
|
||||
});
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user