Skip to content
This repository was archived by the owner on Feb 25, 2026. It is now read-only.

Commit 247a777

Browse files
committed
fixed: failure to start when clipboard is empty
This patch checks the content of sdterr to make sure not to die when the clipboard is read but empty.
1 parent 5ca5b7c commit 247a777

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

cboard/tools.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import (
99
"os/exec"
1010
)
1111

12+
const ClipboardEmptyErrorString = "Nothing is copied\n"
13+
1214
type toolsClipboardManager struct {
1315
}
1416

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

3436
stdout := bytes.NewBuffer(nil)
3537
cmd.Stdout = stdout
38+
stderr := bytes.NewBuffer(nil)
39+
cmd.Stderr = stderr
3640

3741
if err := cmd.Run(); err != nil {
38-
return nil, fmt.Errorf("unable to run command: %w", err)
42+
if stderr.String() == ClipboardEmptyErrorString {
43+
return nil, nil
44+
}
45+
return nil, fmt.Errorf("unable to run read command: %w", err)
3946
}
4047

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

115+
if len(data) <= 0 {
116+
continue
117+
}
118+
108119
select {
109120
case chout <- data:
110121
case <-ctx.Done():

0 commit comments

Comments
 (0)