From 4e1434f243f528a2377f0315d29bef9b0e59c7fa Mon Sep 17 00:00:00 2001 From: labile Date: Sat, 11 May 2024 07:54:38 +0300 Subject: [PATCH 1/4] https://github.com/labi-le/hyprland-ipc-client/issues/5 manual socket path specification. add MustClient --- ipc.go | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/ipc.go b/ipc.go index fc9c174..7294c69 100755 --- a/ipc.go +++ b/ipc.go @@ -4,7 +4,9 @@ import ( "encoding/json" "errors" "io" + "log" "net" + "os" "reflect" "strings" ) @@ -25,15 +27,34 @@ type ReceivedData struct { type IPCClient struct { conn net.Conn wconn *net.UnixAddr - sign string } -func NewClient(sign string) *IPCClient { - if sign == "" { +func MustClient(sign string) *IPCClient { + readsock := "/tmp/hypr/" + sign + "/.socket2.sock" + writesock := "/tmp/hypr/" + sign + "/.socket.sock" + + _, exist := os.Stat(readsock) + _, wexist := os.Stat(writesock) + if exist == nil && wexist == nil { + log.Println("version hyprland < 0.40") + return NewClient( + readsock, + writesock, + ) + } + xdg := os.Getenv("XDG_RUNTIME_DIR") + return NewClient( + xdg+"/hypr/"+sign+"/.socket2.sock", + xdg+"/hypr/"+sign+"/.socket.sock", + ) +} + +func NewClient(readSock, writeSock string) *IPCClient { + if readSock == "" || writeSock == "" { panic("sign is empty") } - conn, err := net.Dial("unix", "/tmp/hypr/"+sign+"/.socket2.sock") + conn, err := net.Dial("unix", readSock) if err != nil { panic(err) } @@ -42,9 +63,8 @@ func NewClient(sign string) *IPCClient { conn: conn, wconn: &net.UnixAddr{ Net: "unix", - Name: "/tmp/hypr/" + sign + "/.socket.sock", + Name: writeSock, }, - sign: sign, } } From 36ae6f799b2543c701e9fa628b3cf08b6190e9fe Mon Sep 17 00:00:00 2001 From: labile Date: Sat, 11 May 2024 07:54:57 +0300 Subject: [PATCH 2/4] update version type --- ipc_test.go | 3 ++- ipc_type.go | 13 ++++++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/ipc_test.go b/ipc_test.go index 19273b3..4691a78 100755 --- a/ipc_test.go +++ b/ipc_test.go @@ -1,11 +1,12 @@ package client import ( + "os" "reflect" "testing" ) -var ipctest = NewClient("fe7b748eb668136dd0558b7c8279bfcd7ab4d759_1714258749") +var ipctest = MustClient(os.Getenv("HYPRLAND_INSTANCE_SIGNATURE")) func Test_ipc_Clients(t *testing.T) { got, err := ipctest.Clients() diff --git a/ipc_type.go b/ipc_type.go index e8c6501..616b363 100755 --- a/ipc_type.go +++ b/ipc_type.go @@ -122,11 +122,14 @@ type Devices struct { } type Version struct { - Branch string `json:"branch"` - Commit string `json:"commit"` - Dirty bool `json:"dirty"` - CommitMessage string `json:"commit_message"` - Flags []interface{} `json:"flags"` + Branch string `json:"branch"` + Commit string `json:"commit"` + Dirty bool `json:"dirty"` + CommitMessage string `json:"commit_message"` + CommitDate string `json:"commit_date"` + Tag string `json:"tag"` + Commits string `json:"commits"` + Flags []string `json:"flags"` } type CursorPos struct { From 4024e8e58aaf4c5af312f6b7986ce946706476c2 Mon Sep 17 00:00:00 2001 From: labi-le <65619560+labi-le@users.noreply.github.com> Date: Sat, 11 May 2024 14:23:30 +0300 Subject: [PATCH 3/4] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index db8e87b..c91ad4b 100755 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ type ed struct { } func main() { - c := client.NewClient(os.Getenv("HYPRLAND_INSTANCE_SIGNATURE")) + c := client.MustClient(os.Getenv("HYPRLAND_INSTANCE_SIGNATURE")) e := &ed{} client.Subscribe(c, e, client.EventActiveLayout) } From d8ba6cabab33e0fde848cfbab9302b1c70ea33db Mon Sep 17 00:00:00 2001 From: labi-le <65619560+labi-le@users.noreply.github.com> Date: Sat, 11 May 2024 14:24:31 +0300 Subject: [PATCH 4/4] Update ipc.go --- ipc.go | 1 - 1 file changed, 1 deletion(-) diff --git a/ipc.go b/ipc.go index 7294c69..de351db 100755 --- a/ipc.go +++ b/ipc.go @@ -36,7 +36,6 @@ func MustClient(sign string) *IPCClient { _, exist := os.Stat(readsock) _, wexist := os.Stat(writesock) if exist == nil && wexist == nil { - log.Println("version hyprland < 0.40") return NewClient( readsock, writesock,