From 265145af4163f71913c7b789ced4728517f6bcee Mon Sep 17 00:00:00 2001 From: Wang Zichong Date: Mon, 16 Nov 2026 12:05:50 +0800 Subject: [PATCH] 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. --- asuka.json | 4 ++-- internal/appui/root.go | 10 +++++++--- internal/appui/root_test.go | 12 ++++++++++++ internal/storage/storage.go | 9 +++++++-- 4 files changed, 28 insertions(+), 7 deletions(-) diff --git a/asuka.json b/asuka.json index 30da218..5364c0e 100644 --- a/asuka.json +++ b/asuka.json @@ -1,7 +1,7 @@ { "name": "OpenChamber", "id": "com.openchamber.native", - "version": "0.1.2", - "build": 3, + "version": "0.1.3", + "build": 4, "orientations": ["portrait", "landscape"] } diff --git a/internal/appui/root.go b/internal/appui/root.go index 749b23f..5d16728 100644 --- a/internal/appui/root.go +++ b/internal/appui/root.go @@ -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() { diff --git a/internal/appui/root_test.go b/internal/appui/root_test.go index e500884..8be25e9 100644 --- a/internal/appui/root_test.go +++ b/internal/appui/root_test.go @@ -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) + } +} diff --git a/internal/storage/storage.go b/internal/storage/storage.go index 02d9be2..4943597 100644 --- a/internal/storage/storage.go +++ b/internal/storage/storage.go @@ -7,6 +7,7 @@ import ( "crypto/sha256" "encoding/hex" "encoding/json" + "net/url" "sort" "github.com/egoist/asuka/sdk/secure" @@ -82,8 +83,12 @@ func migrateLegacy() []Connection { if old.ID == "" { old.ID = newID() } - if old.Label == "" { - old.Label = old.URL + if old.Label == "" || old.Label == old.URL { + if u, err := url.Parse(old.URL); err == nil && u.Host != "" { + old.Label = u.Host + } else { + old.Label = old.URL + } } // Clear it so the next launch does not migrate again. _ = store.Set(legacyKey, "")