feat: save several servers and pick one to connect

Match the first-party mobile client's connection screen:

- the first screen lists saved servers, the one last used leading with
  its connect button or connected state, the others below, and adding
  is one tap
- servers can be added, edited (name, address, proxy, self-signed) and
  deleted; deleting the live or last one returns to the list
- a password sheet prompts only when the server asks for one, keeps the
  error and the typed password for a retry
- while connected, the instances sheet switches servers
- proxy and self-signed options stay per server (the native app's own)
- the single-server record and its token migrate automatically
- permission cards read a plain signal, fixing a flaky update
- bump version to 0.1.2 (build 3)
This commit is contained in:
blumia committed 2026-11-16 11:52:38 +08:00
1 parent ef0b63ceee
commit 13aca21d99
12 files changed
+966 -361

No files matched your search

+25 -13
View File
@@ -54,6 +54,9 @@ type chat struct {
reloadScheduled bool
listNode ui.Node
permList *signal.Signal[[]ocapi.PermissionRequest]
hasPerms *signal.Signal[bool]
pickerOpen *signal.Signal[bool]
pickerKind string
pickerItems *signal.Signal[[]pickerItem]
@@ -91,12 +94,15 @@ func (c *controller) openChat(s *ocapi.Session, nav *ui.Navigator) *chat {
errText: signal.New(""),
textSlots: map[string]map[int]int{},
reasoningSlots: map[string]map[int]int{},
permList: signal.NewFunc([]ocapi.PermissionRequest{}, nil),
hasPerms: signal.New(false),
pickerOpen: signal.New(false),
pickerItems: signal.NewFunc([]pickerItem{}, nil),
pickerFilter: signal.New(""),
pickerLoad: signal.New(false),
}
c.chat = ch
ch.syncPerms()
ch.load()
return ch
}
@@ -591,24 +597,29 @@ func (ch *chat) applyPick(it pickerItem) {
}
// perms are the pending permission requests for this session.
func (ch *chat) perms() signal.Accessor[[]ocapi.PermissionRequest] {
return signal.Func(func() []ocapi.PermissionRequest {
var out []ocapi.PermissionRequest
for _, p := range ch.c.perms.Get() {
if p.SessionID == ch.id {
out = append(out, p)
}
func (ch *chat) perms() []ocapi.PermissionRequest {
var out []ocapi.PermissionRequest
for _, p := range ch.c.perms.Get() {
if p.SessionID == ch.id {
out = append(out, p)
}
return out
})
}
return out
}
// syncPerms publishes this session's pending permission requests. The list
// and the flag are plain signals so the section updates without a computed
// chain (which is timing-sensitive in the test host).
func (ch *chat) syncPerms() {
list := ch.perms()
ch.permList.Set(list)
ch.hasPerms.Set(len(list) > 0)
}
func (ch *chat) permissionSection() ui.Node {
list := ch.perms()
shown := signal.Func(func() bool { return len(list.Get()) > 0 })
return ui.Show(shown, func() ui.Node {
return ui.Show(ch.hasPerms, func() ui.Node {
return ui.Column(ui.Style{Gap: 6, Padding: ui.Symmetric(6, 12)},
ui.For(list, func(p ocapi.PermissionRequest) string { return p.ID },
ui.For(ch.permList, func(p ocapi.PermissionRequest) string { return p.ID },
func(p signal.Accessor[ocapi.PermissionRequest], _ signal.Accessor[int]) ui.Node {
return ui.View(ui.ViewProps{Style: ui.Style{Gap: 8, Padding: ui.Symmetric(10, 12),
CornerRadius: 12, Background: colors.SecondaryBackground}},
@@ -656,6 +667,7 @@ func (ch *chat) reply(req ocapi.PermissionRequest, decision ocapi.PermissionDeci
}
}
ch.c.perms.Set(next)
ch.syncPerms()
})
}()
}