fix: show a server's host instead of repeating its address

A connection saved without a name (including the one migrated from the
single-server record) showed its URL as both title and subtitle. Fall
back to the host, and migrate old records that stored the URL as the
name.
This commit is contained in:
blumia committed 2026-11-16 12:05:50 +08:00
1 parent 13aca21d99
commit 265145af41
4 files changed
+28 -7

No files matched your search

+7 -3
View File
@@ -331,10 +331,14 @@ func (c *controller) saveConnection(conn storage.Connection) {
}
func (c *controller) labelOf(conn storage.Connection) string {
if strings.TrimSpace(conn.Label) != "" {
return conn.Label
label := strings.TrimSpace(conn.Label)
if label != "" && label != conn.URL {
return label
}
return hostOf(conn.URL)
if host := hostOf(conn.URL); host != "" {
return host
}
return label
}
func (c *controller) refresh() {
+12
View File
@@ -304,3 +304,15 @@ func TestDeleteConnection(t *testing.T) {
a.Until("the connection list to empty", func() bool { return len(st.connections()) == 0 })
a.Expect("手动输入地址")
}
func TestLabelFallsBackToHost(t *testing.T) {
c := &controller{}
conn := storage.Connection{URL: "http://192.168.1.5:3000", Label: "http://192.168.1.5:3000"}
if got := c.labelOf(conn); got != "192.168.1.5:3000" {
t.Fatalf("label = %q", got)
}
conn.Label = "Home"
if got := c.labelOf(conn); got != "Home" {
t.Fatalf("label = %q", got)
}
}