Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Auto-fill on page load" options #1455

Merged
merged 14 commits into from May 18, 2021
18 changes: 18 additions & 0 deletions src/_locales/en/messages.json
Expand Up @@ -901,6 +901,24 @@
"experimentalFeature": {
"message": "This is currently an experimental feature. Use at your own risk."
},
"defaultAutoFillOnPageLoad": {
"message": "Default autofill setting for login items"
},
"defaultAutoFillOnPageLoadDesc": {
"message": "After enabling Auto-fill On Page Load, you can enable or disable the feature for individual login items. This is the default setting for login items that are not separately configured."
},
"itemAutoFillOnPageLoad": {
"message": "Auto-fill On Page Load (if enabled in Options)"
},
"autoFillOnPageLoadUseDefault": {
"message": "Use default setting"
},
"autoFillOnPageLoadYes": {
"message": "Auto-fill on page load"
},
"autoFillOnPageLoadNo": {
"message": "Do not auto-fill on page load"
},
"commandOpenPopup": {
"message": "Open vault popup"
},
Expand Down
12 changes: 12 additions & 0 deletions src/popup/settings/options.component.html
Expand Up @@ -161,5 +161,17 @@
<b>{{'warning' | i18n}}</b>: {{'experimentalFeature' | i18n}}
</div>
</div>
<div class="box">
<div class="box-content">
<div class="box-content-row" appBoxRow>
<label for="defaultAutofill">{{'defaultAutoFillOnPageLoad' | i18n}}</label>
<select id="defaultAutofill" name="DefaultAutofill" [(ngModel)]="autoFillOnPageLoadDefault"
(change)="updateAutoFillOnPageLoadDefault()" [disabled]="!enableAutoFillOnPageLoad">
<option *ngFor="let o of autoFillOnPageLoadOptions" [ngValue]="o.value">{{o.name}}</option>
</select>
</div>
</div>
<div class="box-footer">{{'defaultAutoFillOnPageLoadDesc' | i18n}}</div>
</div>
</ng-container>
</content>
13 changes: 13 additions & 0 deletions src/popup/settings/options.component.ts
Expand Up @@ -21,6 +21,8 @@ export class OptionsComponent implements OnInit {
disableFavicon = false;
disableBadgeCounter = false;
enableAutoFillOnPageLoad = false;
autoFillOnPageLoadDefault = false;
autoFillOnPageLoadOptions: any[];
disableAutoTotpCopy = false;
disableContextMenuItem = false;
disableAddLoginNotification = false;
Expand Down Expand Up @@ -64,11 +66,18 @@ export class OptionsComponent implements OnInit {
{ name: i18nService.t('twoMinutes'), value: 120 },
{ name: i18nService.t('fiveMinutes'), value: 300 },
];
this.autoFillOnPageLoadOptions = [
{ name: i18nService.t('autoFillOnPageLoadYes'), value: true },
{ name: i18nService.t('autoFillOnPageLoadNo'), value: false },
]
}

async ngOnInit() {
this.enableAutoFillOnPageLoad = await this.storageService.get<boolean>(
ConstantsService.enableAutoFillOnPageLoadKey);

this.autoFillOnPageLoadDefault = await this.storageService.get<boolean>(
ConstantsService.autoFillOnPageLoadDefaultKey) ?? false;

this.disableAddLoginNotification = await this.storageService.get<boolean>(
ConstantsService.disableAddLoginNotificationKey);
Expand Down Expand Up @@ -120,6 +129,10 @@ export class OptionsComponent implements OnInit {
await this.storageService.save(ConstantsService.enableAutoFillOnPageLoadKey, this.enableAutoFillOnPageLoad);
}

async updateAutoFillOnPageLoadDefault() {
await this.storageService.save(ConstantsService.autoFillOnPageLoadDefaultKey, this.autoFillOnPageLoadDefault);
}

async updateDisableFavicon() {
await this.storageService.save(ConstantsService.disableFaviconKey, this.disableFavicon);
await this.stateService.save(ConstantsService.disableFaviconKey, this.disableFavicon);
Expand Down
10 changes: 10 additions & 0 deletions src/popup/vault/add-edit.component.html
Expand Up @@ -268,6 +268,16 @@
</a>
</div>
</div>
<div class="box" *ngIf="showAutoFillOnPageLoadOptions">
<div class="box-content">
<div class="box-content-row" appBoxRow>
<label for="autofillOnPageLoad">{{'itemAutoFillOnPageLoad' | i18n}} </label>
<select id="autofillOnPageLoad" name="AutofillOnPageLoad" [(ngModel)]="cipher.login.autofillOnPageLoad">
<option *ngFor="let o of autofillOnPageLoadOptions" [ngValue]="o.value">{{o.name}}</option>
</select>
</div>
</div>
</div>
<div class="box">
<div class="box-content">
<div class="box-content-row" appBoxRow>
Expand Down
13 changes: 12 additions & 1 deletion src/popup/vault/add-edit.component.ts
Expand Up @@ -18,13 +18,17 @@ import { PlatformUtilsService } from 'jslib/abstractions/platformUtils.service';
import { PolicyService } from 'jslib/abstractions/policy.service';
import { StateService } from 'jslib/abstractions/state.service';
import { UserService } from 'jslib/abstractions/user.service';
import { StorageService } from 'jslib/abstractions/storage.service';

import { PopupUtilsService } from '../services/popup-utils.service';
import { ConstantsService } from 'jslib/services/constants.service';

import { LoginUriView } from 'jslib/models/view/loginUriView';

import { AddEditComponent as BaseAddEditComponent } from 'jslib/angular/components/add-edit.component';

import { CipherType } from 'jslib/enums/cipherType';

@Component({
selector: 'app-vault-add-edit',
templateUrl: 'add-edit.component.html',
Expand All @@ -33,6 +37,7 @@ export class AddEditComponent extends BaseAddEditComponent {
currentUris: string[];
showAttachments = true;
openAttachmentsInPopup: boolean;
showAutoFillOnPageLoadOptions: boolean;

constructor(cipherService: CipherService, folderService: FolderService,
i18nService: I18nService, platformUtilsService: PlatformUtilsService,
Expand All @@ -41,7 +46,7 @@ export class AddEditComponent extends BaseAddEditComponent {
messagingService: MessagingService, private route: ActivatedRoute,
private router: Router, private location: Location,
eventService: EventService, policyService: PolicyService,
private popupUtilsService: PopupUtilsService) {
private popupUtilsService: PopupUtilsService, private storageService: StorageService) {
super(cipherService, folderService, i18nService, platformUtilsService, auditService, stateService,
userService, collectionService, messagingService, eventService, policyService);
}
Expand Down Expand Up @@ -108,6 +113,12 @@ export class AddEditComponent extends BaseAddEditComponent {
}, 200);
}

async load() {
await super.load();
this.showAutoFillOnPageLoadOptions = this.cipher.type === CipherType.Login &&
await this.storageService.get<boolean>(ConstantsService.enableAutoFillOnPageLoadKey);
}

async submit(): Promise<boolean> {
if (await super.submit()) {
if (this.cloneMode) {
Expand Down
8 changes: 6 additions & 2 deletions src/services/autofill.service.ts
Expand Up @@ -246,12 +246,16 @@ export default class AutofillService implements AutofillServiceInterface {
if (fromCommand) {
cipher = await this.cipherService.getNextCipherForUrl(tab.url);
} else {
const lastLaunchedCipher = await this.cipherService.getLastLaunchedForUrl(tab.url);
const lastLaunchedCipher = await this.cipherService.getLastLaunchedForUrl(tab.url, true);
if (lastLaunchedCipher && Date.now().valueOf() - lastLaunchedCipher.localData?.lastLaunched?.valueOf() < 30000) {
cipher = lastLaunchedCipher;
}
else {
cipher = await this.cipherService.getLastUsedForUrl(tab.url);
cipher = await this.cipherService.getLastUsedForUrl(tab.url, true);
}

if (cipher == null) {
return null;
}
}

Expand Down