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:
1 parent
13aca21d99
commit
265145af41
4 files changed
+28
-7
No files matched your search
+2
-2
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "OpenChamber",
|
"name": "OpenChamber",
|
||||||
"id": "com.openchamber.native",
|
"id": "com.openchamber.native",
|
||||||
"version": "0.1.2",
|
"version": "0.1.3",
|
||||||
"build": 3,
|
"build": 4,
|
||||||
"orientations": ["portrait", "landscape"]
|
"orientations": ["portrait", "landscape"]
|
||||||
}
|
}
|
||||||
@@ -331,10 +331,14 @@ func (c *controller) saveConnection(conn storage.Connection) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *controller) labelOf(conn storage.Connection) string {
|
func (c *controller) labelOf(conn storage.Connection) string {
|
||||||
if strings.TrimSpace(conn.Label) != "" {
|
label := strings.TrimSpace(conn.Label)
|
||||||
return 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() {
|
func (c *controller) refresh() {
|
||||||
|
|||||||
@@ -304,3 +304,15 @@ func TestDeleteConnection(t *testing.T) {
|
|||||||
a.Until("the connection list to empty", func() bool { return len(st.connections()) == 0 })
|
a.Until("the connection list to empty", func() bool { return len(st.connections()) == 0 })
|
||||||
a.Expect("手动输入地址")
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -7,6 +7,7 @@ import (
|
|||||||
"crypto/sha256"
|
"crypto/sha256"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"net/url"
|
||||||
"sort"
|
"sort"
|
||||||
|
|
||||||
"github.com/egoist/asuka/sdk/secure"
|
"github.com/egoist/asuka/sdk/secure"
|
||||||
@@ -82,8 +83,12 @@ func migrateLegacy() []Connection {
|
|||||||
if old.ID == "" {
|
if old.ID == "" {
|
||||||
old.ID = newID()
|
old.ID = newID()
|
||||||
}
|
}
|
||||||
if old.Label == "" {
|
if old.Label == "" || old.Label == old.URL {
|
||||||
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.
|
// Clear it so the next launch does not migrate again.
|
||||||
_ = store.Set(legacyKey, "")
|
_ = store.Set(legacyKey, "")
|
||||||
|
|||||||
Reference in new issue
Block a user