Add support for the RCW daemon

This commit is contained in:
2025-05-04 19:48:20 -04:00
parent 826d94bc43
commit 21d60b8d0f
7 changed files with 48 additions and 14 deletions
+3 -7
View File
@@ -1,7 +1,6 @@
package core
import (
"bufio"
"fmt"
"os"
"strings"
@@ -59,14 +58,11 @@ func CopyArgument(targetLocation string, field int, passphrase []byte) {
// ClipClearArgument reads the assigned clipboard contents from stdin and passes them to clipClearProcess.
func ClipClearArgument() {
// read previous clipboard contents from stdin
clipScanner := bufio.NewScanner(os.Stdin)
if clipScanner.Scan() {
assignedContents := clipScanner.Text()
clipClearProcess(assignedContents)
} else {
assignedContents := readFromStdin()
if assignedContents == "" {
os.Exit(0) // use os.Exit instead of core.Exit, as this function runs out of a background subprocess that is invisible to the user (will never appear in GUI/TUI environment)
}
clipClearProcess(assignedContents)
}
// GenTOTP generates a TOTP token from a secret (supports standard and Steam TOTP).
+1 -2
View File
@@ -10,8 +10,7 @@ import (
// LaunchClipClearProcess launches the timed clipboard clearing process.
// For non-interactive CLI implementations, an entirely separate process is created for this purpose.
func LaunchClipClearProcess(copySubject string) {
executableName := os.Args[0]
cmd := exec.Command(executableName, "clipclear")
cmd := exec.Command(os.Args[0], "clipclear")
writeToStdin(cmd, copySubject)
err := cmd.Start()
if err != nil {
+1 -2
View File
@@ -11,8 +11,7 @@ import (
// LaunchClipClearProcess launches the timed clipboard clearing process.
// For non-interactive CLI implementations, an entirely separate process is created for this purpose.
func LaunchClipClearProcess(copySubject string, isWayland bool) {
executableName := os.Args[0]
cmd := exec.Command(executableName, "clipclear", strconv.FormatBool(isWayland))
cmd := exec.Command(os.Args[0], "clipclear", strconv.FormatBool(isWayland))
writeToStdin(cmd, copySubject)
err := cmd.Start()
if err != nil {
+21
View File
@@ -2,8 +2,10 @@ package core
import (
"os"
"os/exec"
"strings"
"github.com/rwinkhart/rcw/daemon"
"github.com/rwinkhart/rcw/wrappers"
)
@@ -25,3 +27,22 @@ func EncryptBytes(decBytes []byte, passphrase []byte) []byte {
encBytes := wrappers.Encrypt(decBytes, passphrase)
return encBytes
}
// LaunchRCWDProcess launches an RCW daemon to serve the given passphrase.
func LaunchRCWDProcess(passphrase string) {
cmd := exec.Command(os.Args[0], "startrcwd")
writeToStdin(cmd, passphrase)
err := cmd.Start()
if err != nil {
PrintError("Failed to launch RCW daemon - Does this libmutton implementation support the \"startrcwd\" argument?", ErrorOther, true)
}
}
// RCWDArgument reads the passphrase from stdin and serves it via an RCW daemon.
func RCWDArgument() {
passphrase := readFromStdin()
if passphrase == "" {
os.Exit(0)
}
daemon.Start(string(passphrase))
}
+10
View File
@@ -1,6 +1,7 @@
package core
import (
"bufio"
"crypto/rand"
"fmt"
"io"
@@ -59,6 +60,15 @@ func writeToStdin(cmd *exec.Cmd, input string) {
}()
}
// readFromStdin is a utility function that reads a string from stdin.
func readFromStdin() string {
scanner := bufio.NewScanner(os.Stdin)
if scanner.Scan() {
return scanner.Text()
}
return ""
}
// CreateTempFile creates a temporary file and returns a pointer to it.
func CreateTempFile() *os.File {
tempFile, err := os.CreateTemp("", "*.markdown")