Skip to content

Commit

Permalink
fixed: failure to start when clipboard is empty
Browse files Browse the repository at this point in the history
This patch checks the content of sdterr to make sure not to die when the
clipboard is read but empty.
  • Loading branch information
primalmotion committed Aug 13, 2023
1 parent 5ca5b7c commit 247a777
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion cboard/tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"os/exec"
)

const ClipboardEmptyErrorString = "Nothing is copied\n"

type toolsClipboardManager struct {
}

Expand All @@ -33,9 +35,14 @@ func (c *toolsClipboardManager) Read() ([]byte, error) {

stdout := bytes.NewBuffer(nil)
cmd.Stdout = stdout
stderr := bytes.NewBuffer(nil)
cmd.Stderr = stderr

if err := cmd.Run(); err != nil {
return nil, fmt.Errorf("unable to run command: %w", err)
if stderr.String() == ClipboardEmptyErrorString {
return nil, nil
}
return nil, fmt.Errorf("unable to run read command: %w", err)
}

return stdout.Bytes(), nil
Expand Down Expand Up @@ -105,6 +112,10 @@ func (c *toolsClipboardManager) Watch(ctx context.Context) (<-chan []byte, <-cha
return
}

if len(data) <= 0 {
continue
}

select {
case chout <- data:
case <-ctx.Done():
Expand Down

0 comments on commit 247a777

Please sign in to comment.