mirror of
https://github.com/rwinkhart/MUTN.git
synced 2026-09-03 07:37:23 -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":
|
case "note", "-n":
|
||||||
field = 3
|
field = 3
|
||||||
case "totp", "-t":
|
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)
|
field = 5 // TODO Update field after removed from notes (breaking sshyp entry compatibility)
|
||||||
default:
|
default:
|
||||||
cli.HelpCopy()
|
cli.HelpCopy()
|
||||||
|
|||||||
+12
-12
@@ -28,19 +28,19 @@ func CopyArgument(targetLocation string, field int, executableName string) {
|
|||||||
copySubject = decryptedEntry[field]
|
copySubject = decryptedEntry[field]
|
||||||
} else { // TOTP mode
|
} else { // TOTP mode
|
||||||
var err error
|
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
|
||||||
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
|
||||||
for { // keep field copied to clipboard, refresh on 30-second intervals
|
copySubject, err = totp.GenerateCode(decryptedEntry[5], time.Now())
|
||||||
currentSecond = time.Now().Second()
|
if err != nil {
|
||||||
if currentSecond == 0 || currentSecond == 30 || !copied {
|
fmt.Println(AnsiError + "Error generating TOTP code" + AnsiReset)
|
||||||
copySubject, err = totp.GenerateCode(decryptedEntry[5], time.Now())
|
os.Exit(1)
|
||||||
if err != nil {
|
|
||||||
fmt.Println(AnsiError + "Error generating TOTP code" + AnsiReset)
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
copyField(copySubject, "")
|
|
||||||
}
|
}
|
||||||
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 {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user