Better modularize clipboard code (add "clip" package; break up TOTP code

This commit is contained in:
2025-11-09 23:23:47 -05:00
parent d49632d221
commit bf1399ce8d
14 changed files with 162 additions and 140 deletions
+31
View File
@@ -0,0 +1,31 @@
//go:build android && termux
package clip
import (
"errors"
"os/exec"
"github.com/rwinkhart/go-boilerplate/back"
)
// CopyString copies a string to the clipboard.
func CopyString(continuous bool, copySubject string) error {
cmd := exec.Command("termux-clipboard-set")
_ = back.WriteToStdin(cmd, copySubject)
err := cmd.Run()
if err != nil {
return errors.New("unable to copy to clipboard: " + err.Error())
}
if !continuous {
LaunchClipClearProcess(copySubject)
}
return nil
}
// getClipCommands returns the commands for pasting and clearing the clipboard contents.
func getClipCommands() (*exec.Cmd, *exec.Cmd) {
cmdClear := exec.Command("termux-clipboard-set")
_ = back.WriteToStdin(cmdClear, "")
return exec.Command("termux-clipboard-get"), cmdClear
}