From 5db948b36b2d9813ac10cea71ea3497d88efbc9a Mon Sep 17 00:00:00 2001 From: Wang Zichong Date: Mon, 16 Nov 2026 12:10:11 +0800 Subject: [PATCH] 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). --- asuka.json | 4 ++-- internal/appui/root.go | 21 +++++++++++++++------ internal/appui/root_test.go | 10 ++++++++++ 3 files changed, 27 insertions(+), 8 deletions(-) diff --git a/asuka.json b/asuka.json index 5364c0e..92b125d 100644 --- a/asuka.json +++ b/asuka.json @@ -1,7 +1,7 @@ { "name": "OpenChamber", "id": "com.openchamber.native", - "version": "0.1.3", - "build": 4, + "version": "0.1.4", + "build": 5, "orientations": ["portrait", "landscape"] } diff --git a/internal/appui/root.go b/internal/appui/root.go index 5d16728..b150468 100644 --- a/internal/appui/root.go +++ b/internal/appui/root.go @@ -57,12 +57,13 @@ type controller struct { status *signal.Signal[string] errorMsg *signal.Signal[string] - formOpen *signal.Signal[bool] - formEditID string - formLabel *signal.Signal[string] - formUseProxy *signal.Signal[bool] - formProxy *signal.Signal[string] - formInsecure *signal.Signal[bool] + formOpen *signal.Signal[bool] + formConnecting bool + formEditID string + formLabel *signal.Signal[string] + formUseProxy *signal.Signal[bool] + formProxy *signal.Signal[string] + formInsecure *signal.Signal[bool] passwordOpen *signal.Signal[bool] passwordFor storage.Connection @@ -173,6 +174,12 @@ func (c *controller) establish(conn storage.Connection, password string, explici ui.Post(func() { c.connecting.Set("") 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, "://") { @@ -296,6 +303,7 @@ func (c *controller) establish(conn storage.Connection, password string, explici c.server.Set(info) c.connected.Set(true) c.busy.Set(false) + c.formConnecting = false c.formOpen.Set(false) c.passwordOpen.Set(false) c.passwordText.Set("") @@ -474,6 +482,7 @@ func (c *controller) submitForm() { c.formOpen.Set(false) if !c.connected.Peek() { + c.formConnecting = true c.connectTo(conn, "", true) return } diff --git a/internal/appui/root_test.go b/internal/appui/root_test.go index 8be25e9..bf38a59 100644 --- a/internal/appui/root_test.go +++ b/internal/appui/root_test.go @@ -316,3 +316,13 @@ func TestLabelFallsBackToHost(t *testing.T) { 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("取消") +}