feat: return to the add form when a connection fails

A failed connect from the add/edit form reopens it with the typed
values and the error, instead of dropping back to the list.
Far more useful when the address is wrong.

Bump version to 0.1.4 (build 5).
This commit is contained in:
blumia committed 2026-11-16 12:10:11 +08:00
1 parent 265145af41
commit 5db948b36b
3 files changed
+21 -2

No files matched your search

+2 -2
View File
@@ -1,7 +1,7 @@
{ {
"name": "OpenChamber", "name": "OpenChamber",
"id": "com.openchamber.native", "id": "com.openchamber.native",
"version": "0.1.3", "version": "0.1.4",
"build": 4, "build": 5,
"orientations": ["portrait", "landscape"] "orientations": ["portrait", "landscape"]
} }
+9
View File
@@ -58,6 +58,7 @@ type controller struct {
errorMsg *signal.Signal[string] errorMsg *signal.Signal[string]
formOpen *signal.Signal[bool] formOpen *signal.Signal[bool]
formConnecting bool
formEditID string formEditID string
formLabel *signal.Signal[string] formLabel *signal.Signal[string]
formUseProxy *signal.Signal[bool] formUseProxy *signal.Signal[bool]
@@ -173,6 +174,12 @@ func (c *controller) establish(conn storage.Connection, password string, explici
ui.Post(func() { ui.Post(func() {
c.connecting.Set("") c.connecting.Set("")
c.errorMsg.Set(friendlyError(err)) c.errorMsg.Set(friendlyError(err))
if c.formConnecting {
// The connect came from the add/edit form: bring it back
// with what the user typed so it can be fixed.
c.formConnecting = false
c.formOpen.Set(true)
}
}) })
} }
if !strings.Contains(conn.URL, "://") { if !strings.Contains(conn.URL, "://") {
@@ -296,6 +303,7 @@ func (c *controller) establish(conn storage.Connection, password string, explici
c.server.Set(info) c.server.Set(info)
c.connected.Set(true) c.connected.Set(true)
c.busy.Set(false) c.busy.Set(false)
c.formConnecting = false
c.formOpen.Set(false) c.formOpen.Set(false)
c.passwordOpen.Set(false) c.passwordOpen.Set(false)
c.passwordText.Set("") c.passwordText.Set("")
@@ -474,6 +482,7 @@ func (c *controller) submitForm() {
c.formOpen.Set(false) c.formOpen.Set(false)
if !c.connected.Peek() { if !c.connected.Peek() {
c.formConnecting = true
c.connectTo(conn, "", true) c.connectTo(conn, "", true)
return return
} }
+10
View File
@@ -316,3 +316,13 @@ func TestLabelFallsBackToHost(t *testing.T) {
t.Fatalf("label = %q", got) t.Fatalf("label = %q", got)
} }
} }
func TestFailedAddReopensTheForm(t *testing.T) {
a := mount(t, &memStore{})
a.Tap("手动输入地址")
a.Type("http://192.168.1.5:3000", "http://127.0.0.1:1")
a.Tap("连接")
a.WaitFor("连接被拒绝,请确认服务器地址与端口")
a.Expect("添加服务器")
a.Expect("取消")
}