Skip to content

Commit eebd645

Browse files
committed
Change GetPort to return an error if the window is not running
1 parent eb5491b commit eebd645

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

v2/lib.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -345,9 +345,17 @@ func (w Window) GetChildProcessID() uint64 {
345345
return uint64(C.webui_get_child_process_id(C.size_t(w)))
346346
}
347347

348-
// GetPort returns the network port of the running window.
349-
func (w Window) GetPort() int {
350-
return int(C.webui_get_port(C.size_t(w)))
348+
// GetPort returns the network port of the running window. If the window isn't
349+
// running, an error is returned.
350+
func (w Window) GetPort() (int, error) {
351+
if !w.IsShown() {
352+
return 0, errors.New("error: window is not running")
353+
}
354+
port := int(C.webui_get_port(C.size_t(w)))
355+
if port == 0 {
356+
return 0, errors.New("error: failed to get port")
357+
}
358+
return port, nil
351359
}
352360

353361
// SetPort sets a custom web-server network port to be used by WebUI. Returns

0 commit comments

Comments
 (0)