Monitor: show the web UI URL when LISTEN_UI is active

The status snapshot carries the UI address; the monitor renders it as a
dim 'UI: http://…' line below the GPU line.
This commit is contained in:
mram
2026-09-22 18:54:52 +02:00
parent 18a7336c02
commit 5506163493
5 changed files with 38 additions and 0 deletions
+3
View File
@@ -1164,6 +1164,8 @@ type statusSnapshot struct {
// false when game detection (and with it nvidia-smi polling) is not // false when game detection (and with it nvidia-smi polling) is not
// configured. // configured.
GPU statusGPU `json:"gpu"` GPU statusGPU `json:"gpu"`
// UI is the web UI's URL when LISTEN_UI is active, empty otherwise.
UI string `json:"ui,omitempty"`
// MonitorNote is set client-side (never over the wire) when the // MonitorNote is set client-side (never over the wire) when the
// monitor's own binary differs from the service's version. // monitor's own binary differs from the service's version.
MonitorNote string `json:"-"` MonitorNote string `json:"-"`
@@ -1232,6 +1234,7 @@ func statusProvider(cfg config.Config, lk *lock.Lock, comfySup *supervise.Proces
snap := statusSnapshot{ snap := statusSnapshot{
Version: version, Version: version,
UptimeS: int64(time.Since(started).Seconds()), UptimeS: int64(time.Since(started).Seconds()),
UI: uiURL(cfg.ListenUI),
} }
st, known, foreign, ageS := gw.get() st, known, foreign, ageS := gw.get()
snap.GPU = statusGPU{ snap.GPU = statusGPU{
+3
View File
@@ -211,6 +211,9 @@ func renderMonitor(snap statusSnapshot, width int) string {
if snap.GPU.Enabled { if snap.GPU.Enabled {
b.WriteString(renderGPU(snap.GPU) + "\x1b[K\n") b.WriteString(renderGPU(snap.GPU) + "\x1b[K\n")
} }
if snap.UI != "" {
b.WriteString(" " + cDim + "UI: " + snap.UI + cReset + "\x1b[K\n")
}
if snap.MonitorNote != "" { if snap.MonitorNote != "" {
b.WriteString(" " + cYellow + snap.MonitorNote + cReset + "\x1b[K\n") b.WriteString(" " + cYellow + snap.MonitorNote + cReset + "\x1b[K\n")
} }
+6
View File
@@ -66,6 +66,12 @@ func TestRenderMonitor(t *testing.T) {
if strings.Contains(frame, "busy") { if strings.Contains(frame, "busy") {
t.Errorf("idle lock still shows busy:\n%s", frame) t.Errorf("idle lock still shows busy:\n%s", frame)
} }
snap.UI = "http://127.0.0.1:7860"
frame = renderMonitor(snap, 80)
if !strings.Contains(frame, "UI: http://127.0.0.1:7860") {
t.Errorf("frame missing UI line:\n%s", frame)
}
} }
func TestFmtDur(t *testing.T) { func TestFmtDur(t *testing.T) {
+13
View File
@@ -79,6 +79,19 @@ func isLoopbackHost(host string) bool {
return ip != nil && ip.IsLoopback() return ip != nil && ip.IsLoopback()
} }
// uiURL renders a LISTEN_UI address as a browsable URL ("" when disabled).
// A wildcard host reads as 127.0.0.1 — that's where the browser is usually
// running.
func uiURL(addr string) string {
if addr == "" {
return ""
}
if strings.HasPrefix(addr, ":") {
addr = "127.0.0.1" + addr
}
return "http://" + addr
}
// uiPage is the whole web UI: a terminal-styled page that polls /api/status // uiPage is the whole web UI: a terminal-styled page that polls /api/status
// once a second and renders the same lines as --monitor. The buttons (and // once a second and renders the same lines as --monitor. The buttons (and
// the u/r keys) hit the action endpoints, like the monitor's hotkeys. // the u/r keys) hit the action endpoints, like the monitor's hotkeys.
+13
View File
@@ -170,3 +170,16 @@ func TestIsLoopbackHost(t *testing.T) {
} }
} }
} }
func TestUIURL(t *testing.T) {
for addr, want := range map[string]string{
"": "",
"127.0.0.1:7860": "http://127.0.0.1:7860",
":7860": "http://127.0.0.1:7860",
"192.168.1.5:9000": "http://192.168.1.5:9000",
} {
if got := uiURL(addr); got != want {
t.Errorf("uiURL(%q) = %q, want %q", addr, got, want)
}
}
}