Remove mobile clipboard management (this should be the responsibility of the GUI toolkit)

This commit is contained in:
2025-11-13 21:58:37 -05:00
parent 80cf65775a
commit 8d1dd48035
11 changed files with 13 additions and 76 deletions
-36
View File
@@ -1,36 +0,0 @@
//go:build (android && !termux) || ios
package clip
import (
"strings"
"time"
"github.com/rwinkhart/go-boilerplate/back"
"golang.design/x/clipboard"
)
// 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 {
clearClipboard := func() {
clipboard.Write(clipboard.FmtText, []byte(""))
back.Exit(0)
}
// if assignedContents is empty, clear the clipboard immediately and unconditionally
if assignedContents == "" {
clearClipboard()
return nil
}
// wait 30 seconds before checking clipboard contents
time.Sleep(30 * time.Second)
newContents := clipboard.Read(clipboard.FmtText)
if assignedContents == strings.TrimRight(string(newContents), "\r\n") {
clearClipboard()
}
return nil
}
+2 -2
View File
@@ -10,14 +10,14 @@ import (
) )
// CopyString copies a string to the clipboard. // CopyString copies a string to the clipboard.
func CopyString(continuous bool, copySubject string) error { func CopyString(clearClipboardAutomatically bool, copySubject string) error {
cmd := exec.Command("pbcopy") cmd := exec.Command("pbcopy")
_ = back.WriteToStdin(cmd, copySubject) _ = back.WriteToStdin(cmd, copySubject)
err := cmd.Run() err := cmd.Run()
if err != nil { if err != nil {
return errors.New("unable to copy to clipboard: " + err.Error()) return errors.New("unable to copy to clipboard: " + err.Error())
} }
if !continuous { if clearClipboardAutomatically {
LaunchClipClearProcess(copySubject) LaunchClipClearProcess(copySubject)
} }
return nil return nil
-16
View File
@@ -1,16 +0,0 @@
//go:build (android && !termux) || ios
package clip
import (
"golang.design/x/clipboard"
)
// CopyString copies a string to the clipboard.
func CopyString(continuous bool, copySubject string) error {
clipboard.Write(clipboard.FmtText, []byte(copySubject))
if !continuous {
LaunchClipClearProcess(copySubject)
}
return nil
}
+2 -2
View File
@@ -10,14 +10,14 @@ import (
) )
// CopyString copies a string to the clipboard. // CopyString copies a string to the clipboard.
func CopyString(continuous bool, copySubject string) error { func CopyString(clearClipboardAutomatically bool, copySubject string) error {
cmd := exec.Command("termux-clipboard-set") cmd := exec.Command("termux-clipboard-set")
_ = back.WriteToStdin(cmd, copySubject) _ = back.WriteToStdin(cmd, copySubject)
err := cmd.Run() err := cmd.Run()
if err != nil { if err != nil {
return errors.New("unable to copy to clipboard: " + err.Error()) return errors.New("unable to copy to clipboard: " + err.Error())
} }
if !continuous { if clearClipboardAutomatically {
LaunchClipClearProcess(copySubject) LaunchClipClearProcess(copySubject)
} }
return nil return nil
+2 -2
View File
@@ -11,7 +11,7 @@ import (
) )
// CopyString copies a string to the clipboard. // CopyString copies a string to the clipboard.
func CopyString(continuous bool, copySubject string) error { func CopyString(clearClipboardAutomatically bool, copySubject string) error {
// determine whether to use wl-copy (Wayland) or xclip (X11) // determine whether to use wl-copy (Wayland) or xclip (X11)
var envSet, isWayland bool // track whether environment variables are set var envSet, isWayland bool // track whether environment variables are set
var cmdCopy *exec.Cmd var cmdCopy *exec.Cmd
@@ -29,7 +29,7 @@ func CopyString(continuous bool, copySubject string) error {
if err != nil { if err != nil {
return errors.New("unable to copy to clipboard: " + err.Error()) return errors.New("unable to copy to clipboard: " + err.Error())
} }
if !continuous { if clearClipboardAutomatically {
LaunchClipClearProcess(copySubject, isWayland) LaunchClipClearProcess(copySubject, isWayland)
} }
return nil return nil
+2 -2
View File
@@ -10,13 +10,13 @@ import (
) )
// CopyString copies a string to the clipboard. // CopyString copies a string to the clipboard.
func CopyString(continuous bool, copySubject string) error { func CopyString(clearClipboardAutomatically bool, copySubject string) error {
cmd := exec.Command("powershell.exe", "-c", fmt.Sprintf("echo '%s' | Set-Clipboard", strings.ReplaceAll(copySubject, "'", "''"))) cmd := exec.Command("powershell.exe", "-c", fmt.Sprintf("echo '%s' | Set-Clipboard", strings.ReplaceAll(copySubject, "'", "''")))
err := cmd.Run() err := cmd.Run()
if err != nil { if err != nil {
return errors.New("unable to copy to clipboard: " + err.Error()) return errors.New("unable to copy to clipboard: " + err.Error())
} }
if !continuous { if clearClipboardAutomatically {
LaunchClipClearProcess(copySubject) LaunchClipClearProcess(copySubject)
} }
return nil return nil
+1 -1
View File
@@ -1,4 +1,4 @@
//go:build (windows || darwin || android || ios || termux || wsl) && !interactive //go:build (windows || wsl || (darwin && !ios) || (android && termux)) && !interactive
package clip package clip
+1 -1
View File
@@ -1,4 +1,4 @@
//go:build (windows || darwin || android || ios || termux || wsl) && interactive //go:build (windows || wsl || (darwin && !ios) || (android && termux)) && interactive
package clip package clip
-4
View File
@@ -7,7 +7,6 @@ require (
github.com/pquerna/otp v1.5.0 github.com/pquerna/otp v1.5.0
github.com/rwinkhart/go-boilerplate v0.1.1-0.20251110055016-10ee4f91fcb6 github.com/rwinkhart/go-boilerplate v0.1.1-0.20251110055016-10ee4f91fcb6
github.com/rwinkhart/rcw v0.2.3 github.com/rwinkhart/rcw v0.2.3
golang.design/x/clipboard v0.7.1 // only for mobile builds
golang.org/x/crypto v0.43.0 golang.org/x/crypto v0.43.0
gopkg.in/ini.v1 v1.67.0 gopkg.in/ini.v1 v1.67.0
) )
@@ -17,9 +16,6 @@ require (
github.com/boombuler/barcode v1.1.0 // indirect github.com/boombuler/barcode v1.1.0 // indirect
github.com/kr/fs v0.1.0 // indirect github.com/kr/fs v0.1.0 // indirect
github.com/rwinkhart/peercred-mini v0.1.2 // indirect github.com/rwinkhart/peercred-mini v0.1.2 // indirect
golang.org/x/exp/shiny v0.0.0-20251017212417-90e834f514db // indirect; only for mobile builds
golang.org/x/image v0.32.0 // indirect; only for mobile builds
golang.org/x/mobile v0.0.0-20251021151156-188f512ec823 // indirect; only for mobile builds
golang.org/x/sys v0.38.0 // indirect golang.org/x/sys v0.38.0 // indirect
) )
-10
View File
@@ -12,8 +12,6 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/pquerna/otp v1.5.0 h1:NMMR+WrmaqXU4EzdGJEE1aUUI0AMRzsp96fFFWNPwxs= github.com/pquerna/otp v1.5.0 h1:NMMR+WrmaqXU4EzdGJEE1aUUI0AMRzsp96fFFWNPwxs=
github.com/pquerna/otp v1.5.0/go.mod h1:dkJfzwRKNiegxyNb54X/3fLwhCynbMspSyWKnvi1AEg= github.com/pquerna/otp v1.5.0/go.mod h1:dkJfzwRKNiegxyNb54X/3fLwhCynbMspSyWKnvi1AEg=
github.com/rwinkhart/go-boilerplate v0.1.0 h1:EzlVj6R7Bxtl79Nl7R5zRcg6s+Cf2FAqGIzR4giWTQg=
github.com/rwinkhart/go-boilerplate v0.1.0/go.mod h1:cnzIF45I0FCOvE4YIB+26pLCUx2kWyY2llKYZruNaRY=
github.com/rwinkhart/go-boilerplate v0.1.1-0.20251110055016-10ee4f91fcb6 h1:tGGtw5Wr4laDrU7Ooe95g4E+O6c+oY18atamcMPaMY8= github.com/rwinkhart/go-boilerplate v0.1.1-0.20251110055016-10ee4f91fcb6 h1:tGGtw5Wr4laDrU7Ooe95g4E+O6c+oY18atamcMPaMY8=
github.com/rwinkhart/go-boilerplate v0.1.1-0.20251110055016-10ee4f91fcb6/go.mod h1:cnzIF45I0FCOvE4YIB+26pLCUx2kWyY2llKYZruNaRY= github.com/rwinkhart/go-boilerplate v0.1.1-0.20251110055016-10ee4f91fcb6/go.mod h1:cnzIF45I0FCOvE4YIB+26pLCUx2kWyY2llKYZruNaRY=
github.com/rwinkhart/go-winio v0.1.0 h1:b72agLW+dETGmhR3VbcbwnStfgKfc5AfgJOXBJDkaHg= github.com/rwinkhart/go-winio v0.1.0 h1:b72agLW+dETGmhR3VbcbwnStfgKfc5AfgJOXBJDkaHg=
@@ -28,16 +26,8 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
golang.design/x/clipboard v0.7.1 h1:OEG3CmcYRBNnRwpDp7+uWLiZi3hrMRJpE9JkkkYtz2c=
golang.design/x/clipboard v0.7.1/go.mod h1:i5SiIqj0wLFw9P/1D7vfILFK0KHMk7ydE72HRrUIgkg=
golang.org/x/crypto v0.43.0 h1:dduJYIi3A3KOfdGOHX8AVZ/jGiyPa3IbBozJ5kNuE04= golang.org/x/crypto v0.43.0 h1:dduJYIi3A3KOfdGOHX8AVZ/jGiyPa3IbBozJ5kNuE04=
golang.org/x/crypto v0.43.0/go.mod h1:BFbav4mRNlXJL4wNeejLpWxB7wMbc79PdRGhWKncxR0= golang.org/x/crypto v0.43.0/go.mod h1:BFbav4mRNlXJL4wNeejLpWxB7wMbc79PdRGhWKncxR0=
golang.org/x/exp/shiny v0.0.0-20251017212417-90e834f514db h1:NmsmaSkEAq6A8r0Q78WxD0IygJNCs6J3uYDgNuPkXYM=
golang.org/x/exp/shiny v0.0.0-20251017212417-90e834f514db/go.mod h1:QMAAUorQ8fzCK0C6mr4X4XV9BEp7Al6+jlejJvfYKw4=
golang.org/x/image v0.32.0 h1:6lZQWq75h7L5IWNk0r+SCpUJ6tUVd3v4ZHnbRKLkUDQ=
golang.org/x/image v0.32.0/go.mod h1:/R37rrQmKXtO6tYXAjtDLwQgFLHmhW+V6ayXlxzP2Pc=
golang.org/x/mobile v0.0.0-20251021151156-188f512ec823 h1:M0DtBf/UvJoTH+tk6tgHT2NVxNEJCYhVu1g/xeD+GEk=
golang.org/x/mobile v0.0.0-20251021151156-188f512ec823/go.mod h1:3QSlP0AtP6HPTLbsxfgfefGN76jpIB9yBsMqB8UY37I=
golang.org/x/term v0.36.0 h1:zMPR+aF8gfksFprF/Nc/rd1wRS1EI6nDBGyWAvDzx2Q= golang.org/x/term v0.36.0 h1:zMPR+aF8gfksFprF/Nc/rd1wRS1EI6nDBGyWAvDzx2Q=
golang.org/x/term v0.36.0/go.mod h1:Qu394IJq6V6dCBRgwqshf3mPF85AqzYEzofzRdZkWss= golang.org/x/term v0.36.0/go.mod h1:Qu394IJq6V6dCBRgwqshf3mPF85AqzYEzofzRdZkWss=
gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA= gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA=
+3
View File
@@ -20,6 +20,9 @@ These are as follows:
- `clipclear`: Should be accepted by all non-interactive CLI libmutton implementations (not required for interactive GUI/TUI implementations). In order to clear the clipboard on a timer, non-interactive libmutton-based password managers call another instance of their executable with the `clipclear` argument (e.g. `mutn clipclear`) with the intended clipboard contents provided via STDIN. If after 30 seconds the clipboard contents have not changed, they are cleared. Please accept a `clipclear` argument that calls `clip.ClipClearArgument()`. - `clipclear`: Should be accepted by all non-interactive CLI libmutton implementations (not required for interactive GUI/TUI implementations). In order to clear the clipboard on a timer, non-interactive libmutton-based password managers call another instance of their executable with the `clipclear` argument (e.g. `mutn clipclear`) with the intended clipboard contents provided via STDIN. If after 30 seconds the clipboard contents have not changed, they are cleared. Please accept a `clipclear` argument that calls `clip.ClipClearArgument()`.
- `startrcwd`: Should be accepted by all libmutton implementations making use of the RCW daemon to cache passwords. Please accept a `startrcwd` argument that calls `crypt.RCWDArgument()`. - `startrcwd`: Should be accepted by all libmutton implementations making use of the RCW daemon to cache passwords. Please accept a `startrcwd` argument that calls `crypt.RCWDArgument()`.
## Mobile Clipboard Management
In an effort to reduce dependencies not needed in most environments, libmutton no longer provides clipboard management for mobile platforms. This should be handled by your GUI toolkit/framework.
## Configuration ## Configuration
libmutton-based password manager clients should all share the same INI configuration file. libmutton-based password manager clients should all share the same INI configuration file.