[PM-8833] Reworking how we handle adding a password to history

This commit is contained in:
Cesar Gonzalez 2024-09-27 14:43:39 -05:00
parent 59e119bea0
commit ab681e79eb
No known key found for this signature in database
GPG Key ID: 3381A5457F8CCECF
3 changed files with 13 additions and 5 deletions

View File

@ -191,6 +191,7 @@ describe("OverlayBackground", () => {
inlineMenuFieldQualificationService,
themeStateService,
() => Promise.resolve(generatedPassword),
() => Promise.resolve(),
);
portKeyForTabSpy = overlayBackground["portKeyForTab"];
pageDetailsForTabSpy = overlayBackground["pageDetailsForTab"];

View File

@ -208,6 +208,7 @@ export class OverlayBackground implements OverlayBackgroundInterface {
private inlineMenuFieldQualificationService: InlineMenuFieldQualificationService,
private themeStateService: ThemeStateService,
private generatePasswordCallback: () => Promise<string>,
private addPasswordCallback: (password: string) => Promise<void>,
) {
this.initOverlayEventObservables();
}
@ -1536,6 +1537,8 @@ export class OverlayBackground implements OverlayBackgroundInterface {
return;
}
await this.addPasswordCallback(this.generatedPassword);
const pageDetails = this.pageDetailsForTab[port.sender.tab.id];
if (!pageDetails) {
return;

View File

@ -1621,6 +1621,7 @@ export default class MainBackground {
inlineMenuFieldQualificationService,
this.themeStateService,
() => this.generatePassword(),
(password) => this.addPasswordToHistory(password),
);
}
@ -1636,13 +1637,16 @@ export default class MainBackground {
generatePassword = async (): Promise<string> => {
const options = (await this.passwordGenerationService.getOptions())?.[0] ?? {};
const password = await this.passwordGenerationService.generatePassword(options);
await this.passwordGenerationService.addHistory(password);
return password;
return await this.passwordGenerationService.generatePassword(options);
};
generatePasswordToClipboard = async () => {
this.platformUtilsService.copyToClipboard(await this.generatePassword());
const password = await this.generatePassword();
this.platformUtilsService.copyToClipboard(password);
await this.addPasswordToHistory(password);
};
addPasswordToHistory = async (password: string) => {
await this.passwordGenerationService.addHistory(password);
};
}