Handle error for failing to read clipboard contents on all platforms

This commit is contained in:
2024-06-05 17:45:49 -04:00
parent f7cc27f88d
commit a804cf7cff
3 changed files with 18 additions and 6 deletions
+6 -2
View File
@@ -40,12 +40,16 @@ func clipClear(oldContents string) {
time.Sleep(30 * time.Second)
cmd := exec.Command("pbpaste")
newContents, _ := cmd.Output()
newContents, err := cmd.Output()
if err != nil {
fmt.Println(AnsiError + "Failed to read clipboard contents: " + err.Error() + AnsiReset)
os.Exit(1)
}
if oldContents == strings.TrimRight(string(newContents), "\r\n") {
cmd = exec.Command("pbcopy")
writeToStdin(cmd, "")
err := cmd.Run()
err = cmd.Run()
if err != nil {
fmt.Println(AnsiError + "Failed to clear clipboard: " + err.Error() + AnsiReset)
os.Exit(1)
+6 -2
View File
@@ -38,12 +38,16 @@ func clipClear(oldContents string) {
time.Sleep(30 * time.Second)
cmd := exec.Command("termux-clipboard-get")
newContents, _ := cmd.Output()
newContents, err := cmd.Output()
if err != nil {
fmt.Println(AnsiError + "Failed to read clipboard contents: " + err.Error() + AnsiReset)
os.Exit(1)
}
if oldContents == strings.TrimRight(string(newContents), "\r\n") {
cmd = exec.Command("termux-clipboard-set")
writeToStdin(cmd, "")
err := cmd.Run()
err = cmd.Run()
if err != nil {
fmt.Println(AnsiError + "Failed to clear clipboard: " + err.Error() + AnsiReset)
os.Exit(1)
+6 -2
View File
@@ -37,11 +37,15 @@ func clipClear(oldContents string) {
time.Sleep(30 * time.Second)
cmd := exec.Command("powershell.exe", "-c", "Get-Clipboard")
newContents, _ := cmd.Output()
newContents, err := cmd.Output()
if err != nil {
fmt.Println(AnsiError + "Failed to read clipboard contents: " + err.Error() + AnsiReset)
os.Exit(1)
}
if oldContents == strings.TrimRight(string(newContents), "\r\n") {
cmd = exec.Command("powershell.exe", "-c", "Set-Clipboard")
err := cmd.Run()
err = cmd.Run()
if err != nil {
fmt.Println(AnsiError + "Failed to clear clipboard: " + err.Error() + AnsiReset)
os.Exit(1)