mirror of
https://github.com/rwinkhart/libmutton.git
synced 2026-09-05 08:37:25 -04:00
Drop support for non-continuous TOTP copy
This commit is contained in:
+7
-14
@@ -1,3 +1,5 @@
|
||||
//go:build (!android && !ios) || termux
|
||||
|
||||
package clip
|
||||
|
||||
import (
|
||||
@@ -29,16 +31,7 @@ func GenTOTP(secret string, time time.Time, forSteam bool) (string, error) {
|
||||
|
||||
// TOTPCopier is meant to be run as a goroutine to keep
|
||||
// the clipboard up-to-date with the latest TOTP token.
|
||||
// Set oneTime to -1 for a one-time (non-continuous) TOTP copy.
|
||||
// For oneTime mode, this function can be used normally (not as a goroutine).
|
||||
func TOTPCopier(secret string, oneTime int, errorChan chan<- error, done <-chan bool) error {
|
||||
var writeErrorChan func(err error)
|
||||
if errorChan != nil {
|
||||
writeErrorChan = func(err error) { errorChan <- err }
|
||||
} else {
|
||||
writeErrorChan = func(err error) {}
|
||||
}
|
||||
|
||||
var forSteam bool
|
||||
if strings.HasPrefix(secret, "steam@") {
|
||||
secret = secret[6:]
|
||||
@@ -49,16 +42,16 @@ func TOTPCopier(secret string, oneTime int, errorChan chan<- error, done <-chan
|
||||
currentTime := time.Now()
|
||||
token, err := GenTOTP(secret, currentTime, forSteam)
|
||||
if err != nil {
|
||||
writeErrorChan(err)
|
||||
errorChan <- err
|
||||
return err // return for when not used as goroutine; should exit on error regardless
|
||||
}
|
||||
err = CopyString(true, token)
|
||||
err = CopyString(false, token)
|
||||
if err != nil {
|
||||
writeErrorChan(err)
|
||||
errorChan <- err
|
||||
return err // return for when not used as goroutine; should exit on error regardless
|
||||
}
|
||||
if oneTime != -1 {
|
||||
writeErrorChan(err)
|
||||
errorChan <- err
|
||||
time.Sleep(time.Duration(30-(currentTime.Second()%30)) * time.Second)
|
||||
} else {
|
||||
return nil
|
||||
@@ -67,7 +60,7 @@ func TOTPCopier(secret string, oneTime int, errorChan chan<- error, done <-chan
|
||||
// exit after sleep if indicated (will not update clipboard again)
|
||||
select {
|
||||
case <-done:
|
||||
writeErrorChan(nil)
|
||||
errorChan <- err
|
||||
return nil
|
||||
default:
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user