diff --git a/v2/lib.go b/v2/lib.go index b56b7d5..c1dca13 100644 --- a/v2/lib.go +++ b/v2/lib.go @@ -345,7 +345,18 @@ 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. If the window isn't +// running, an error is returned. +func (w Window) GetPort() (int, error) { + 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 +// 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))) }