1
0
mirror of https://github.com/bitwarden/browser synced 2026-02-14 15:33:55 +00:00

Change argument to full GenerateRequest for clarity, generatePasswordToClipboard uses observables, cleanup processCommand arguments to use ExtensionCommand types.

# Conflicts:
#	apps/browser/src/background/commands.background.ts
This commit is contained in:
Miles Blackwood
2026-01-23 11:37:12 -05:00
parent 1b43defc6f
commit 1c73e77251
4 changed files with 20 additions and 16 deletions

View File

@@ -3604,9 +3604,10 @@ describe("OverlayBackground", () => {
});
it("sends a message to the list port indicating that the generated password should be updated", async () => {
sendPortMessage(listMessageConnectorSpy, { command: "refreshGeneratedPassword", portKey });
overlayBackground["credential$"].next("refresh");
sendPortMessage(listMessageConnectorSpy, { command: "refreshGeneratedPassword", portKey });
await flushPromises();
expect(listPortSpy.postMessage).toHaveBeenCalledWith({

View File

@@ -1822,8 +1822,8 @@ export class OverlayBackground implements OverlayBackgroundInterface {
/**
* Generates a password based on the user defined password generation options.
*/
private requestGeneratedPassword(source: GenerateRequest["source"]) {
this.requestGeneratedPassword$.next({ source, type: Type.password });
private requestGeneratedPassword(request: GenerateRequest) {
this.requestGeneratedPassword$.next(request);
}
/**
@@ -1840,7 +1840,7 @@ export class OverlayBackground implements OverlayBackgroundInterface {
*/
private async updateGeneratedPassword(refreshPassword: boolean = false) {
if (!this.credential$.value || refreshPassword) {
this.requestGeneratedPassword("inline-menu");
this.requestGeneratedPassword({ source: "inline-menu", type: Type.password });
}
this.postMessageToPort(this.inlineMenuListPort, {
@@ -3105,7 +3105,7 @@ export class OverlayBackground implements OverlayBackgroundInterface {
}
if (!this.credential$.value) {
this.requestGeneratedPassword("inline-menu.init");
this.requestGeneratedPassword({ source: "inline-menu.init", type: Type.password });
}
return true;

View File

@@ -1,6 +1,6 @@
// FIXME: Update this file to be type safe and remove this and next line
// @ts-strict-ignore
import { firstValueFrom } from "rxjs";
import { firstValueFrom, Observable } from "rxjs";
import { LockService } from "@bitwarden/auth/common";
import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
@@ -26,7 +26,7 @@ export default class CommandsBackground {
private main: MainBackground,
private platformUtilsService: PlatformUtilsService,
private authService: AuthService,
private generatePasswordToClipboard: () => Promise<void>,
private generatePasswordToClipboard: () => Observable<string>,
private accountService: AccountService,
private lockService: LockService,
) {
@@ -53,8 +53,8 @@ export default class CommandsBackground {
private async processCommand(command: string, sender?: chrome.runtime.MessageSender) {
switch (command) {
case "generate_password":
await this.generatePasswordToClipboard();
case ExtensionCommand.GeneratePassword:
this.generatePasswordToClipboard();
break;
case ExtensionCommand.AutofillLogin:
await this.triggerAutofillCommand(
@@ -74,10 +74,10 @@ export default class CommandsBackground {
ExtensionCommand.AutofillIdentity,
);
break;
case "open_popup":
case ExtensionCommand.OpenPopup:
await this.openPopup();
break;
case "lock_vault": {
case ExtensionCommand.LockVault: {
const activeUserId = await firstValueFrom(getUserId(this.accountService.activeAccount$));
await this.lockService.lock(activeUserId);
break;

View File

@@ -2060,12 +2060,15 @@ export default class MainBackground {
);
};
generatePasswordToClipboard = async () => {
const { credential: password } = await firstValueFrom(
this.yieldGeneratedPassword(of({ source: "clipboard", type: Type.password })),
generatePasswordToClipboard = () => {
return this.yieldGeneratedPassword(of({ source: "clipboard", type: Type.password })).pipe(
concatMap(async (generated) => {
this.platformUtilsService.copyToClipboard(generated.credential);
await this.addPasswordToHistory(generated.credential);
return generated.credential;
}),
);
this.platformUtilsService.copyToClipboard(password);
await this.addPasswordToHistory(password);
};
addPasswordToHistory = async (password: string) => {