From 695576c5b1740edc78e6ff0ba71dd82dba0b01a9 Mon Sep 17 00:00:00 2001 From: ayn2op Date: Fri, 19 Jun 2026 12:34:59 -0400 Subject: [PATCH] refactor: switch to upstream clipboard --- .github/workflows/ci.yml | 4 -- README.md | 4 -- go.mod | 4 +- go.sum | 8 +++- internal/clipboard/clipboard.go | 10 ---- internal/clipboard/clipboard_default.go | 19 -------- internal/clipboard/clipboard_wayland.go | 62 ------------------------- internal/ui/chat/composer.go | 15 ++---- internal/ui/chat/guilds_tree.go | 2 +- internal/ui/chat/messages_list.go | 2 +- internal/ui/login/msg.go | 2 +- internal/ui/root/msg.go | 2 +- 12 files changed, 16 insertions(+), 118 deletions(-) delete mode 100644 internal/clipboard/clipboard.go delete mode 100644 internal/clipboard/clipboard_default.go delete mode 100644 internal/clipboard/clipboard_wayland.go diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ada61ae..3600ba9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -26,10 +26,6 @@ jobs: with: go-version: stable - - name: Install libx11-dev for clipboard support - if: runner.os == 'Linux' - run: sudo apt install libx11-dev - - name: Test run: go test -v ./... diff --git a/README.md b/README.md index 2d8519f..385082f 100644 --- a/README.md +++ b/README.md @@ -33,10 +33,6 @@ cd discordo go build . ``` -### Wayland clipboard support - -`wl-clipboard` is required for clipboard support. - ## Usage ### Token (UI, recommended) diff --git a/go.mod b/go.mod index e6e60cd..8d4abb2 100644 --- a/go.mod +++ b/go.mod @@ -10,7 +10,6 @@ require ( github.com/BurntSushi/toml v1.6.0 github.com/alecthomas/chroma/v2 v2.26.1 github.com/andybalholm/brotli v1.2.1 - github.com/ayn2op/clipboard v0.0.0-20260308203959-c5ad7df3fc97 github.com/ayn2op/tview v0.0.0-20260613222404-bc6acaaf92ef github.com/deckarep/gosx-notifier v0.0.0-20180201035817-e127226297fb github.com/diamondburned/arikawa/v3 v3.6.1-0.20260518050745-b430932b3ee1 @@ -28,6 +27,7 @@ require ( github.com/skratchdot/open-golang v0.0.0-20200116055534-eef842397966 github.com/yuin/goldmark v1.8.2 github.com/zalando/go-keyring v0.2.8 + golang.design/x/clipboard v0.8.0 ) require ( @@ -38,6 +38,7 @@ require ( github.com/danieljoos/wincred v1.2.3 // indirect github.com/dchest/jsmin v1.0.0 // indirect github.com/dlclark/regexp2/v2 v2.2.1 // indirect + github.com/ebitengine/purego v0.10.1 // indirect github.com/esiqveland/notify v0.13.3 // indirect github.com/gdamore/encoding v1.0.1 // indirect github.com/go-ole/go-ole v1.3.0 // indirect @@ -54,6 +55,7 @@ require ( github.com/tadvi/systray v0.0.0-20190226123456-11a2b8fa57af // indirect github.com/twmb/murmur3 v1.1.8 // indirect go4.org v0.0.0-20260112195520-a5071408f32f // indirect + golang.design/x/x11 v0.2.0 // indirect golang.org/x/exp/shiny v0.0.0-20260611194520-c48552f49976 // indirect golang.org/x/image v0.42.0 // indirect golang.org/x/mobile v0.0.0-20260611195102-4dd8f1dbf5d2 // indirect diff --git a/go.sum b/go.sum index 9dad609..dbf6437 100644 --- a/go.sum +++ b/go.sum @@ -12,8 +12,6 @@ github.com/alecthomas/repr v0.5.2 h1:SU73FTI9D1P5UNtvseffFSGmdNci/O6RsqzeXJtP0Qs github.com/alecthomas/repr v0.5.2/go.mod h1:Fr0507jx4eOXV7AlPV6AVZLYrLIuIeSOWtW57eE/O/4= github.com/andybalholm/brotli v1.2.1 h1:R+f5xP285VArJDRgowrfb9DqL18yVK0gKAW/F+eTWro= github.com/andybalholm/brotli v1.2.1/go.mod h1:rzTDkvFWvIrjDXZHkuS16NPggd91W3kUSvPlQ1pLaKY= -github.com/ayn2op/clipboard v0.0.0-20260308203959-c5ad7df3fc97 h1:WujETUV+v0DEJyZgjeLzQvihWyL80c0Tg4qf0dDo+Io= -github.com/ayn2op/clipboard v0.0.0-20260308203959-c5ad7df3fc97/go.mod h1:3kFnpNCa3dF6WryzOMCDao7PfZ7DTCh+pievlfuwV80= github.com/ayn2op/tview v0.0.0-20260613222404-bc6acaaf92ef h1:25kloMP4wqA8h5MQBRrPQ9/8O8OzNn0y2fr9gIudFS0= github.com/ayn2op/tview v0.0.0-20260613222404-bc6acaaf92ef/go.mod h1:CaEiemJYKtmWqR0khyMI3HzVIia6B61jOPcLeZ7y4xk= github.com/clipperhouse/displaywidth v0.11.0 h1:lBc6kY44VFw+TDx4I8opi/EtL9m20WSEFgwIwO+UVM8= @@ -35,6 +33,8 @@ github.com/diamondburned/ningen/v3 v3.0.1-0.20260306213430-5a08d3a709b4 h1:m1Wyr github.com/diamondburned/ningen/v3 v3.0.1-0.20260306213430-5a08d3a709b4/go.mod h1:JSqSCBN5MAI9yjAO6tZlSayXM9KWx+8q3EhhlkCuscM= github.com/dlclark/regexp2/v2 v2.2.1 h1:mf4KkFUj0gJuarK8P+LgiS+Lit7m9N1yAwEfPbee7R0= github.com/dlclark/regexp2/v2 v2.2.1/go.mod h1:avUrQvPaLz2DrFNHJF0taWAFFX2C1GMSSoeiqFjcBmU= +github.com/ebitengine/purego v0.10.1 h1:dewVBCBT2GaMu1SrNTYxQhgQBethzfhiwvZiLGP/qyY= +github.com/ebitengine/purego v0.10.1/go.mod h1:iIjxzd6CiRiOG0UyXP+V1+jWqUXVjPKLAI0mRfJZTmQ= github.com/esiqveland/notify v0.13.3 h1:QCMw6o1n+6rl+oLUfg8P1IIDSFsDEb2WlXvVvIJbI/o= github.com/esiqveland/notify v0.13.3/go.mod h1:hesw/IRYTO0x99u1JPweAl4+5mwXJibQVUcP0Iu5ORE= github.com/gdamore/encoding v1.0.1 h1:YzKZckdBL6jVt2Gc+5p82qhrGiqMdG/eNs6Wy0u3Uhw= @@ -115,6 +115,10 @@ go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto= go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE= go4.org v0.0.0-20260112195520-a5071408f32f h1:ziUVAjmTPwQMBmYR1tbdRFJPtTcQUI12fH9QQjfb0Sw= go4.org v0.0.0-20260112195520-a5071408f32f/go.mod h1:ZRJnO5ZI4zAwMFp+dS1+V6J6MSyAowhRqAE+DPa1Xp0= +golang.design/x/clipboard v0.8.0 h1:6VEcH28wwcSgKc+vnxHHDWiRjrakTQIAJnPUrt3aOgg= +golang.design/x/clipboard v0.8.0/go.mod h1:s0pwrtA3Q9fgnVtGDmP5ZK/pp55cQKB23esKsjwWhWM= +golang.design/x/x11 v0.2.0 h1:Uiwu2guGihsJX/ZCzpoDPFz5gR/Qntm08mvoBCmRydo= +golang.design/x/x11 v0.2.0/go.mod h1:/5q1mFkdc1rL8mvB7DsQFi6as4tIkBv4FXjcP07mrkE= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/exp/shiny v0.0.0-20260611194520-c48552f49976 h1:xAKfctaZuXDxw/I98uYRl7TXMBy4a1BgPgl7NavbrdY= diff --git a/internal/clipboard/clipboard.go b/internal/clipboard/clipboard.go deleted file mode 100644 index 9cfcb67..0000000 --- a/internal/clipboard/clipboard.go +++ /dev/null @@ -1,10 +0,0 @@ -package clipboard - -import "github.com/ayn2op/clipboard" - -type Format = clipboard.Format - -const ( - FmtText Format = clipboard.FmtText - FmtImage = clipboard.FmtImage -) diff --git a/internal/clipboard/clipboard_default.go b/internal/clipboard/clipboard_default.go deleted file mode 100644 index bcada6f..0000000 --- a/internal/clipboard/clipboard_default.go +++ /dev/null @@ -1,19 +0,0 @@ -//go:build !linux && !freebsd - -package clipboard - -import ( - "github.com/ayn2op/clipboard" -) - -func Init() error { - return clipboard.Init() -} - -func Read(t Format) ([]byte, error) { - return clipboard.Read(clipboard.Format(t)) -} - -func Write(t Format, buf []byte) error { - return clipboard.Write(clipboard.Format(t), buf) -} diff --git a/internal/clipboard/clipboard_wayland.go b/internal/clipboard/clipboard_wayland.go deleted file mode 100644 index 3d11f15..0000000 --- a/internal/clipboard/clipboard_wayland.go +++ /dev/null @@ -1,62 +0,0 @@ -//go:build linux || freebsd - -package clipboard - -import ( - "bytes" - "github.com/ayn2op/clipboard" - "os" - "os/exec" -) - -var wayland bool - -func Init() error { - if _, ok := os.LookupEnv("WAYLAND_DISPLAY"); !ok { - return clipboard.Init() - } - if _, err := exec.LookPath("wl-copy"); err != nil { - return err - } - if _, err := exec.LookPath("wl-paste"); err != nil { - return err - } - wayland = true - return nil -} - -func Read(t Format) ([]byte, error) { - if !wayland { - return clipboard.Read(clipboard.Format(t)) - } - // -n: Don't print a newline at the end - // -t type: MIME type specifier - cmd := exec.Command("wl-paste", "-nt", formatToType(t)) - outBuffer := bytes.Buffer{} - cmd.Stdout = &outBuffer - if err := cmd.Run(); err != nil { - return nil, err - } - return outBuffer.Bytes(), nil -} - -func Write(t Format, buf []byte) error { - if !wayland { - return clipboard.Write(clipboard.Format(t), buf) - } - // -t type: MIME type specifier - cmd := exec.Command("wl-copy", "-t", formatToType(t)) - cmd.Stdin = bytes.NewReader(buf) - return cmd.Run() -} - -func formatToType(t Format) string { - switch t { - case FmtImage: - return "image" - case FmtText: - fallthrough - default: - return "text/plain;charset=utf-8" - } -} diff --git a/internal/ui/chat/composer.go b/internal/ui/chat/composer.go index 3311879..a4979e7 100644 --- a/internal/ui/chat/composer.go +++ b/internal/ui/chat/composer.go @@ -14,7 +14,6 @@ import ( "unicode" "github.com/ayn2op/discordo/internal/cache" - "github.com/ayn2op/discordo/internal/clipboard" "github.com/ayn2op/discordo/internal/config" "github.com/ayn2op/discordo/internal/consts" "github.com/ayn2op/discordo/internal/ui" @@ -32,6 +31,7 @@ import ( "github.com/ncruces/zenity" "github.com/sahilm/fuzzy" "github.com/yuin/goldmark/ast" + "golang.design/x/clipboard" ) const ( @@ -80,12 +80,7 @@ func newComposer(cfg *config.Config, chat *Model) *composer { } }, func() string { - data, err := clipboard.Read(clipboard.FmtText) - if err != nil { - slog.Error("failed to read clipboard text", "err", err) - return "" - } - return string(data) + return string(clipboard.Read(clipboard.FmtText)) }, ). SetDisabled(true) @@ -249,11 +244,7 @@ type imagePastedMsg []byte func (c *composer) pasteImage() tview.Cmd { return func() tview.Msg { - data, err := clipboard.Read(clipboard.FmtImage) - if err != nil { - slog.Error("failed to read clipboard image", "err", err) - return nil - } + data := clipboard.Read(clipboard.FmtImage) return imagePastedMsg(data) } } diff --git a/internal/ui/chat/guilds_tree.go b/internal/ui/chat/guilds_tree.go index dae5d86..8c911a4 100644 --- a/internal/ui/chat/guilds_tree.go +++ b/internal/ui/chat/guilds_tree.go @@ -4,7 +4,6 @@ import ( "fmt" "log/slog" - "github.com/ayn2op/discordo/internal/clipboard" "github.com/ayn2op/discordo/internal/config" "github.com/ayn2op/discordo/internal/ui" "github.com/ayn2op/tview" @@ -15,6 +14,7 @@ import ( "github.com/diamondburned/arikawa/v3/gateway" "github.com/diamondburned/ningen/v3" "github.com/gdamore/tcell/v3" + "golang.design/x/clipboard" ) type dmNode struct{} diff --git a/internal/ui/chat/messages_list.go b/internal/ui/chat/messages_list.go index 83f21c2..1fc4e43 100644 --- a/internal/ui/chat/messages_list.go +++ b/internal/ui/chat/messages_list.go @@ -16,7 +16,6 @@ import ( "github.com/ayn2op/tview/layers" - "github.com/ayn2op/discordo/internal/clipboard" "github.com/ayn2op/discordo/internal/config" "github.com/ayn2op/discordo/internal/consts" "github.com/ayn2op/discordo/internal/markdown" @@ -38,6 +37,7 @@ import ( "github.com/yuin/goldmark/ast" "github.com/yuin/goldmark/parser" "github.com/yuin/goldmark/text" + "golang.design/x/clipboard" ) type messagesList struct { diff --git a/internal/ui/login/msg.go b/internal/ui/login/msg.go index 074d410..397d0aa 100644 --- a/internal/ui/login/msg.go +++ b/internal/ui/login/msg.go @@ -3,8 +3,8 @@ package login import ( "log/slog" - "github.com/ayn2op/discordo/internal/clipboard" "github.com/ayn2op/tview" + "golang.design/x/clipboard" ) type errMsg struct { diff --git a/internal/ui/root/msg.go b/internal/ui/root/msg.go index 8b1a431..b8943e7 100644 --- a/internal/ui/root/msg.go +++ b/internal/ui/root/msg.go @@ -3,9 +3,9 @@ package root import ( "log/slog" - "github.com/ayn2op/discordo/internal/clipboard" "github.com/ayn2op/discordo/internal/keyring" "github.com/ayn2op/tview" + "golang.design/x/clipboard" ) type tokenMsg string