From eb5491b43c06f3f956c7b817339dab979d8cb5cf Mon Sep 17 00:00:00 2001 From: Blake Miner Date: Thu, 2 Jan 2025 09:00:01 -0500 Subject: [PATCH 1/3] Added GetPort method (closes #46) --- v2/lib.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/v2/lib.go b/v2/lib.go index b56b7d5..c11a6ae 100644 --- a/v2/lib.go +++ b/v2/lib.go @@ -345,7 +345,13 @@ func (w Window) GetChildProcessID() uint64 { return uint64(C.webui_get_child_process_id(C.size_t(w))) } -// SetPort sets a custom web-server network port to be used by WebUI. +// GetPort returns the network port of the running window. +func (w Window) GetPort() int { + return int(C.webui_get_port(C.size_t(w))) +} + +// SetPort sets a custom web-server network port to be used by WebUI. Returns +// true if the port is free and usable by WebUI. func (w Window) SetPort(port uint) bool { return bool(C.webui_set_port(C.size_t(w), C.size_t(port))) } From eebd64505d1ead484ac343480f1d25d7a13d8821 Mon Sep 17 00:00:00 2001 From: Blake Miner Date: Mon, 6 Jan 2025 15:06:16 -0500 Subject: [PATCH 2/3] Change GetPort to return an error if the window is not running --- v2/lib.go | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/v2/lib.go b/v2/lib.go index c11a6ae..e43349b 100644 --- a/v2/lib.go +++ b/v2/lib.go @@ -345,9 +345,17 @@ func (w Window) GetChildProcessID() uint64 { return uint64(C.webui_get_child_process_id(C.size_t(w))) } -// GetPort returns the network port of the running window. -func (w Window) GetPort() int { - return int(C.webui_get_port(C.size_t(w))) +// GetPort returns the network port of the running window. If the window isn't +// running, an error is returned. +func (w Window) GetPort() (int, error) { + if !w.IsShown() { + return 0, errors.New("error: window is not running") + } + port := int(C.webui_get_port(C.size_t(w))) + if port == 0 { + return 0, errors.New("error: failed to get port") + } + return port, nil } // SetPort sets a custom web-server network port to be used by WebUI. Returns From e4c1916ced867c598e246af3c749de71ee53a292 Mon Sep 17 00:00:00 2001 From: Blake Miner Date: Mon, 6 Jan 2025 15:22:47 -0500 Subject: [PATCH 3/3] GetPort: Remove IsShown check --- v2/lib.go | 3 --- 1 file changed, 3 deletions(-) diff --git a/v2/lib.go b/v2/lib.go index e43349b..c1dca13 100644 --- a/v2/lib.go +++ b/v2/lib.go @@ -348,9 +348,6 @@ func (w Window) GetChildProcessID() uint64 { // GetPort returns the network port of the running window. If the window isn't // running, an error is returned. func (w Window) GetPort() (int, error) { - if !w.IsShown() { - return 0, errors.New("error: window is not running") - } port := int(C.webui_get_port(C.size_t(w))) if port == 0 { return 0, errors.New("error: failed to get port")