mirror of
https://github.com/rwinkhart/MUTN.git
synced 2026-08-27 20:36:29 -04:00
Do not check time/refresh TOTP every second - calculate time till next 30-second interval, instead
This commit is contained in:
@@ -77,7 +77,7 @@ func main() {
|
||||
case "note", "-n":
|
||||
field = 3
|
||||
case "totp", "-t":
|
||||
fmt.Println("TOTP code copied to clipboard - until this process is closed, your clipboard will be kept up to date with the current TOTP code")
|
||||
fmt.Println("TOTP code will be copied to clipboard - your clipboard will be kept up to date with the current TOTP code until this process is closed")
|
||||
field = 5 // TODO Update field after removed from notes (breaking sshyp entry compatibility)
|
||||
default:
|
||||
cli.HelpCopy()
|
||||
|
||||
+12
-12
@@ -28,19 +28,19 @@ func CopyArgument(targetLocation string, field int, executableName string) {
|
||||
copySubject = decryptedEntry[field]
|
||||
} else { // TOTP mode
|
||||
var err error
|
||||
var currentSecond int // track current second for TOTP code refresh
|
||||
var copied bool // track whether the TOTP code has been copied to the clipboard for the first time
|
||||
for { // keep field copied to clipboard, refresh on 30-second intervals
|
||||
currentSecond = time.Now().Second()
|
||||
if currentSecond == 0 || currentSecond == 30 || !copied {
|
||||
copySubject, err = totp.GenerateCode(decryptedEntry[5], time.Now())
|
||||
if err != nil {
|
||||
fmt.Println(AnsiError + "Error generating TOTP code" + AnsiReset)
|
||||
os.Exit(1)
|
||||
}
|
||||
copyField(copySubject, "")
|
||||
var copied bool // track whether the TOTP code has been copied to the clipboard for the first time
|
||||
for { // keep field copied to clipboard, refresh on 30-second intervals
|
||||
copySubject, err = totp.GenerateCode(decryptedEntry[5], time.Now())
|
||||
if err != nil {
|
||||
fmt.Println(AnsiError + "Error generating TOTP code" + AnsiReset)
|
||||
os.Exit(1)
|
||||
}
|
||||
time.Sleep(1 * time.Second)
|
||||
copyField(copySubject, "")
|
||||
if !copied {
|
||||
copied = true
|
||||
}
|
||||
// sleep until next 30-second interval
|
||||
time.Sleep(time.Duration(30-(time.Now().Second()%30)) * time.Second)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user