From 1d28743f31b9f5086f137e2c634cbd448849acee Mon Sep 17 00:00:00 2001 From: Ophestra Umiker Date: Sun, 30 Jun 2024 03:00:02 +0900 Subject: [PATCH] library: io: implement Windows platform support Discord on Windows makes use of Windows named pipes for the socket instead of UNIX domain sockets. Signed-off-by: Ophestra Umiker --- go.mod | 3 ++- io_windows.go | 27 +++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 io_windows.go diff --git a/go.mod b/go.mod index 7b5ce64..c0f95d4 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,9 @@ go 1.22 require ( fyne.io/fyne/v2 v2.4.5 + github.com/Microsoft/go-winio v0.6.2 github.com/google/uuid v1.6.0 + golang.org/x/image v0.17.0 ) require ( @@ -28,7 +30,6 @@ require ( github.com/stretchr/testify v1.8.4 // indirect github.com/tevino/abool v1.2.0 // indirect github.com/yuin/goldmark v1.5.5 // indirect - golang.org/x/image v0.17.0 // indirect golang.org/x/mobile v0.0.0-20231127183840-76ac6878050a // indirect golang.org/x/net v0.17.0 // indirect golang.org/x/sys v0.21.0 // indirect diff --git a/io_windows.go b/io_windows.go new file mode 100644 index 0000000..d5e313e --- /dev/null +++ b/io_windows.go @@ -0,0 +1,27 @@ +package rpcfetch + +import ( + "errors" + "github.com/Microsoft/go-winio" + "io/fs" + "syscall" +) + +var errPipe = syscall.Errno(232) + +func (d *Client) dial() error { + if d.dialed { + panic("attempted to dial on open client") + } + + if conn, err := winio.DialPipe(`\\.\pipe\discord-ipc-0`, nil); err != nil { + if errors.Is(err, winio.ErrTimeout) || errors.Is(err, fs.ErrNotExist) { + return ErrAgain + } + return err + } else { + d.conn = conn + d.dialed = true + } + return nil +}