From dd89c7c44ba1b74c6a263c843e5d9ff00e9c2a18 Mon Sep 17 00:00:00 2001 From: Moritz Poldrack Date: Sun, 18 Dec 2022 17:05:41 +0100 Subject: wizard: debounce warning to ensure pasted passwords are entered correctly When entering passwords from a password-manager the wizard shows it's warning right after the first character has been pasted and the rest of the password is lost. Debounce the displaying of the "stored in plaintext"-warning to only show after the password has been entered. Reported-by: qbit (@qbit:tapenet.org) Signed-off-by: Moritz Poldrack Acked-by: Robin Jarry --- widgets/account-wizard.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'widgets') diff --git a/widgets/account-wizard.go b/widgets/account-wizard.go index 0e2bda1e..2ff87241 100644 --- a/widgets/account-wizard.go +++ b/widgets/account-wizard.go @@ -11,6 +11,7 @@ import ( "strconv" "strings" "sync" + "time" "github.com/gdamore/tcell/v2" "github.com/go-ini/ini" @@ -133,11 +134,21 @@ func NewAccountWizard(aerc *Aerc) *AccountWizard { wizard.smtpUri() }) var once sync.Once + var lastChange time.Time wizard.imapPassword.OnChange(func(_ *ui.TextInput) { wizard.smtpPassword.Set(wizard.imapPassword.String()) wizard.imapUri() wizard.smtpUri() - once.Do(func() { showPasswordWarning(aerc) }) + lastChange = time.Now() + once.Do(func() { + // debounce to ensure pasted passwords are pasted completely + go func() { + for !time.Now().After(lastChange.Add(10 * time.Millisecond)) { + <-time.After(10 * time.Millisecond) + } + showPasswordWarning(aerc) + }() + }) }) wizard.smtpServer.OnChange(func(_ *ui.TextInput) { wizard.smtpUri() -- cgit