Skip to content

Commit

Permalink
windows clipboard fix #15
Browse files Browse the repository at this point in the history
  • Loading branch information
meliksah-simsek-20230331 committed Feb 24, 2023
1 parent f3dbb3e commit c9c9eec
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions uniclip.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,8 @@ func MonitorSentClips(r *bufio.Reader) {
handleError(err)
continue
}
} else {
foreignClipboardBytes = []byte(foreignClipboard)
}
foreignClipboard = string(foreignClipboardBytes)
// hacky way to prevent empty clipboard TODO: find out why empty cb happens
Expand Down Expand Up @@ -205,6 +207,8 @@ func sendClipboard(w *bufio.Writer, clipboard string) error {
if err != nil {
return err
}
} else {
clipboardBytes = []byte(clipboard)
}
err = gob.NewEncoder(w).Encode(clipboardBytes)
if err != nil {
Expand Down Expand Up @@ -345,7 +349,7 @@ func setLocalClip(s string) {
case "darwin":
copyCmd = exec.Command("pbcopy")
case "windows":
copyCmd = exec.Command("powershell.exe", "-command", "Set-Clipboard") //-Value "+"\""+s+"\"")
copyCmd = exec.Command("clip")
default:
if _, err := exec.LookPath("xclip"); err == nil {
copyCmd = exec.Command("xclip", "-in", "-selection", "clipboard")
Expand All @@ -369,15 +373,13 @@ func setLocalClip(s string) {
handleError(err)
return
}
if runtime.GOOS != "windows" {
if _, err = in.Write([]byte(s)); err != nil {
handleError(err)
return
}
if err = in.Close(); err != nil {
handleError(err)
return
}
if _, err = in.Write([]byte(s)); err != nil {
handleError(err)
return
}
if err = in.Close(); err != nil {
handleError(err)
return
}
if err = copyCmd.Wait(); err != nil {
handleError(err)
Expand Down

0 comments on commit c9c9eec

Please sign in to comment.