mirror of
https://github.com/rwinkhart/libmutton.git
synced 2026-08-27 20:36:29 -04:00
Continue dropping support for non-continuous TOTP copy
This commit is contained in:
+1
-1
@@ -35,7 +35,7 @@ func CopyShortcut(targetLocation string, field int) error {
|
|||||||
if field == 2 { // TOTP mode
|
if field == 2 { // TOTP mode
|
||||||
fmt.Println(back.AnsiWarning + "[Starting]" + back.AnsiReset + " TOTP clipboard refresher")
|
fmt.Println(back.AnsiWarning + "[Starting]" + back.AnsiReset + " TOTP clipboard refresher")
|
||||||
errorChan := make(chan error)
|
errorChan := make(chan error)
|
||||||
go TOTPCopier(decSlice[2], field, errorChan, nil) // "done" is not needed because the process runs until the program is killed
|
go TOTPCopier(decSlice[2], errorChan, nil) // "done" is not needed because the process runs until the program is killed
|
||||||
err = <-errorChan
|
err = <-errorChan
|
||||||
if err != nil { // handle error from first copy
|
if err != nil { // handle error from first copy
|
||||||
return errors.New("error encountered in TOTP refresh process: " + err.Error())
|
return errors.New("error encountered in TOTP refresh process: " + err.Error())
|
||||||
|
|||||||
+7
-11
@@ -31,7 +31,7 @@ func GenTOTP(secret string, time time.Time, forSteam bool) (string, error) {
|
|||||||
|
|
||||||
// TOTPCopier is meant to be run as a goroutine to keep
|
// TOTPCopier is meant to be run as a goroutine to keep
|
||||||
// the clipboard up-to-date with the latest TOTP token.
|
// the clipboard up-to-date with the latest TOTP token.
|
||||||
func TOTPCopier(secret string, oneTime int, errorChan chan<- error, done <-chan bool) error {
|
func TOTPCopier(secret string, errorChan chan<- error, done <-chan bool) {
|
||||||
var forSteam bool
|
var forSteam bool
|
||||||
if strings.HasPrefix(secret, "steam@") {
|
if strings.HasPrefix(secret, "steam@") {
|
||||||
secret = secret[6:]
|
secret = secret[6:]
|
||||||
@@ -43,25 +43,21 @@ func TOTPCopier(secret string, oneTime int, errorChan chan<- error, done <-chan
|
|||||||
token, err := GenTOTP(secret, currentTime, forSteam)
|
token, err := GenTOTP(secret, currentTime, forSteam)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
errorChan <- err
|
errorChan <- err
|
||||||
return err // return for when not used as goroutine; should exit on error regardless
|
|
||||||
}
|
}
|
||||||
err = CopyString(false, token)
|
err = CopyString(false, token)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
errorChan <- err
|
errorChan <- err
|
||||||
return err // return for when not used as goroutine; should exit on error regardless
|
|
||||||
}
|
|
||||||
if oneTime != -1 {
|
|
||||||
errorChan <- err
|
|
||||||
time.Sleep(time.Duration(30-(currentTime.Second()%30)) * time.Second)
|
|
||||||
} else {
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
errorChan <- nil // indicate that first copy was successful
|
||||||
|
|
||||||
|
// sleep till next 30-second interval
|
||||||
|
time.Sleep(time.Duration(30-(currentTime.Second()%30)) * time.Second)
|
||||||
|
|
||||||
// exit after sleep if indicated (will not update clipboard again)
|
// exit after sleep if indicated (will not update clipboard again)
|
||||||
select {
|
select {
|
||||||
case <-done:
|
case <-done:
|
||||||
errorChan <- err
|
return
|
||||||
return nil
|
|
||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user