Cycle through every login when using the auto-fill shortcut (#956)

* Cycle through every login when using the auto-fill shortcut

* Leave imports ordering as it was

* Undo formatting

* Move logic to jslib

* Remove unused method
This commit is contained in:
Josep Marí 2020-08-12 22:05:12 +02:00 committed by GitHub
parent 289177259a
commit fe2557e21c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 9 deletions

View File

@ -140,7 +140,7 @@ export default class RuntimeBackground {
break; break;
case 'autofiller': case 'autofiller':
case 'autofill_cmd': case 'autofill_cmd':
const totpCode = await this.autofillService.doAutoFillForLastUsedLogin([{ const totpCode = await this.autofillService.doAutoFillActiveTab([{
frameId: sender.frameId, frameId: sender.frameId,
tab: msg.tab, tab: msg.tab,
details: msg.details, details: msg.details,

View File

@ -3,5 +3,5 @@ import AutofillPageDetails from '../../models/autofillPageDetails';
export abstract class AutofillService { export abstract class AutofillService {
getFormsWithPasswordFields: (pageDetails: AutofillPageDetails) => any[]; getFormsWithPasswordFields: (pageDetails: AutofillPageDetails) => any[];
doAutoFill: (options: any) => Promise<string>; doAutoFill: (options: any) => Promise<string>;
doAutoFillForLastUsedLogin: (pageDetails: any, fromCommand: boolean) => Promise<string>; doAutoFillActiveTab: (pageDetails: any, fromCommand: boolean) => Promise<string>;
} }

View File

@ -3,6 +3,8 @@ import {
FieldType, FieldType,
} from 'jslib/enums'; } from 'jslib/enums';
import { CipherView } from 'jslib/models/view';
import AutofillField from '../models/autofillField'; import AutofillField from '../models/autofillField';
import AutofillPageDetails from '../models/autofillPageDetails'; import AutofillPageDetails from '../models/autofillPageDetails';
import AutofillScript from '../models/autofillScript'; import AutofillScript from '../models/autofillScript';
@ -117,6 +119,7 @@ var IsoProvinces: { [id: string]: string; } = {
/* tslint:enable */ /* tslint:enable */
export default class AutofillService implements AutofillServiceInterface { export default class AutofillService implements AutofillServiceInterface {
constructor(private cipherService: CipherService, private userService: UserService, constructor(private cipherService: CipherService, private userService: UserService,
private totpService: TotpService, private eventService: EventService) { } private totpService: TotpService, private eventService: EventService) { }
@ -217,23 +220,24 @@ export default class AutofillService implements AutofillServiceInterface {
} }
} }
async doAutoFillForLastUsedLogin(pageDetails: any, fromCommand: boolean) { async doAutoFillActiveTab(pageDetails: any, fromCommand: boolean) {
const tab = await this.getActiveTab(); const tab = await this.getActiveTab();
if (!tab || !tab.url) { if (!tab || !tab.url) {
return; return;
} }
const lastUsedCipher = await this.cipherService.getLastUsedForUrl(tab.url); let cipher: CipherView;
if (!lastUsedCipher) { if (fromCommand) {
return; cipher = await this.cipherService.getNextCipherForUrl(tab.url);
} else {
cipher = await this.cipherService.getLastUsedForUrl(tab.url);
} }
return await this.doAutoFill({ return await this.doAutoFill({
cipher: lastUsedCipher, cipher: cipher,
// tslint:disable-next-line
pageDetails: pageDetails, pageDetails: pageDetails,
skipTotp: !fromCommand, skipTotp: !fromCommand,
skipLastUsed: true, skipLastUsed: !fromCommand,
skipUsernameOnlyFill: !fromCommand, skipUsernameOnlyFill: !fromCommand,
onlyEmptyFields: !fromCommand, onlyEmptyFields: !fromCommand,
onlyVisibleFields: !fromCommand, onlyVisibleFields: !fromCommand,