diff --git a/src/_locales/en/messages.json b/src/_locales/en/messages.json index 790c635f4be..3c04cfad93b 100644 --- a/src/_locales/en/messages.json +++ b/src/_locales/en/messages.json @@ -885,6 +885,12 @@ "enableAutoFillOnPageLoadDesc": { "message": "If a login form is detected, automatically perform an auto-fill when the web page loads." }, + "enableAutoTotpCopyOnAutoFill": { + "message": "Enable Copy to Clipboard of TOTP On Page Auto-fill" + }, + "enableAutoTotpCopyOnAutoFillDesc": { + "message": "If login auto-fills on page load and TOTP exists for this login, copy to clipboard without prompt" + }, "experimentalFeature": { "message": "This is currently an experimental feature. Use at your own risk." }, diff --git a/src/popup/settings/options.component.html b/src/popup/settings/options.component.html index 938bcd756ed..dc39c2453c9 100644 --- a/src/popup/settings/options.component.html +++ b/src/popup/settings/options.component.html @@ -24,6 +24,19 @@ {{'warning' | i18n}}: {{'experimentalFeature' | i18n}} +
+
+
+ + +
+
+ +
diff --git a/src/popup/settings/options.component.ts b/src/popup/settings/options.component.ts index e5cf6322bbb..80a145e318d 100644 --- a/src/popup/settings/options.component.ts +++ b/src/popup/settings/options.component.ts @@ -23,6 +23,7 @@ import { ConstantsService } from 'jslib/services/constants.service'; export class OptionsComponent implements OnInit { disableFavicon = false; enableAutoFillOnPageLoad = false; + enableAutoTotpCopyOnAutoFill = false; disableAutoTotpCopy = false; disableContextMenuItem = false; disableAddLoginNotification = false; @@ -70,6 +71,8 @@ export class OptionsComponent implements OnInit { this.enableAutoFillOnPageLoad = await this.storageService.get( ConstantsService.enableAutoFillOnPageLoadKey); + this.enableAutoTotpCopyOnAutoFill = await this.totpService.isAutoCopyOnAutoFillEnabled(); + this.disableAddLoginNotification = await this.storageService.get( ConstantsService.disableAddLoginNotificationKey); @@ -120,9 +123,20 @@ export class OptionsComponent implements OnInit { async updateAutoFillOnPageLoad() { await this.storageService.save(ConstantsService.enableAutoFillOnPageLoadKey, this.enableAutoFillOnPageLoad); + if (!this.enableAutoFillOnPageLoad) { + // If we disable Auto Fill on Page Load, also disable Copying of TOTP + await this.storageService.save(ConstantsService.enableAutoTotpCopyOnAutoFill, false); + // TODO the below reloads the entire extension, I just want to reload the current view, or at least the enable auto totp copy checkbox + window.setTimeout(() => window.location.reload(), 200); + } this.callAnalytics('Auto-fill Page Load', this.enableAutoFillOnPageLoad); } + async updateAutoTotpCopyOnAutoFill() { + await this.storageService.save(ConstantsService.enableAutoTotpCopyOnAutoFill, this.enableAutoTotpCopyOnAutoFill); + this.callAnalytics('Auto Copy TOTP on Page Load', this.enableAutoTotpCopyOnAutoFill); + } + async updateDisableFavicon() { await this.storageService.save(ConstantsService.disableFaviconKey, this.disableFavicon); await this.stateService.save(ConstantsService.disableFaviconKey, this.disableFavicon); diff --git a/src/services/autofill.service.ts b/src/services/autofill.service.ts index 841e27098d4..9cb3822219d 100644 --- a/src/services/autofill.service.ts +++ b/src/services/autofill.service.ts @@ -254,10 +254,12 @@ export default class AutofillService implements AutofillServiceInterface { } } + const shouldCopyTotpOnAutoFill = await this.totpService.isAutoCopyOnAutoFillEnabled(); + const totpCode = await this.doAutoFill({ cipher: cipher, pageDetails: pageDetails, - skipTotp: !fromCommand, + skipTotp: !fromCommand && !shouldCopyTotpOnAutoFill, skipLastUsed: !fromCommand, skipUsernameOnlyFill: !fromCommand, onlyEmptyFields: !fromCommand,