Drop support for non-continuous TOTP copy

This commit is contained in:
2025-11-13 22:18:02 -05:00
parent 8d1dd48035
commit c63dff4092
4 changed files with 23 additions and 40 deletions
+51
View File
@@ -0,0 +1,51 @@
//go:build (!android && !ios) || termux
package clip
import (
"errors"
"strings"
"time"
"github.com/rwinkhart/go-boilerplate/back"
)
// ClipClearProcess clears the clipboard after 30 seconds if the clipboard contents have not changed.
// assignedContents can be omitted to clear the clipboard immediately and unconditionally.
func ClipClearProcess(assignedContents string) error {
cmdPaste, cmdClear := getClipCommands()
clearClipboard := func() error {
err := cmdClear.Run()
if err != nil {
return errors.New("unable to clear clipboard")
}
back.Exit(0)
return nil
}
// if assignedContents is empty, clear the clipboard immediately and unconditionally
if assignedContents == "" {
err := clearClipboard()
if err != nil {
return err
}
return nil
}
// wait 30 seconds before checking clipboard contents
time.Sleep(30 * time.Second)
newContents, err := cmdPaste.Output()
if err != nil {
return errors.New("unable to read clipboard contents")
}
if assignedContents == strings.TrimRight(string(newContents), "\r\n") {
err := clearClipboard()
if err != nil {
return err
}
}
return nil
}