feat: port the client to MyGo native UI (0.3.0)

Switch from Asuka to MyGo, keeping the API client and the feature set:

- servers: saved servers, passwordless and password login, proxy,
  self-signed certificates, per-server device tokens (Keystore), connect
  form, instance list sheet with switch/disconnect
- sessions: virtualized list, search, new session, rename/archive/delete,
  running indicator, event stream keeps it live
- chat: pushed window with system back bar, streaming Markdown via
  ui/markdown, reasoning and tool rows with image previews, footer menu
  (read aloud via a Kotlin TTS plugin, copy, fork), user message menu
  (copy, revert, fork), context usage ring and detail sheet, attachments
  (photos/files via the document picker), permissions
- release builds allow plain http:// LAN servers (Go's net/http dials
  directly, no cleartext manifest needed)
- a local fork of MyGo (third_party/mygo) lowers the Android host's
  minSdk to 24 (Android 7.0); Go 1.27.4 via mise

Version 0.3.0.
This commit is contained in:
OpenChamber committed 2026-11-18 13:22:59 +08:00
1 parent 2fb4a8ea79
commit 6c0ee61750
2538 files changed
+675779 -4792

No files matched your search

+152
View File
@@ -0,0 +1,152 @@
package appui
import (
"time"
"github.com/egoist/mygo/ui"
"github.com/egoist/mygo/ui/mobile"
"github.com/openchamber/openchamber-native/internal/ocapi"
)
// sessionsView is the connected screen: the sessions list with its header.
func (a *App) sessionsView(c *ui.Context) {
t := c.Theme()
ui.Column(c).Fill().Background(t.Background).Children(func() {
mobile.TopBar(c, mobile.TopBarOptions{
Title: "会话",
Leading: func() {
// The single server entry: opens the instance list.
if a.iconButton(c, "server", "服务器").Clicked() {
a.instancesOpen = true
}
},
Trailing: func() {
if a.iconButton(c, "search", "搜索").Clicked() {
a.searchOpen = !a.searchOpen
if !a.searchOpen {
a.searchText = ""
a.loadSessions()
}
}
if a.iconButton(c, "plus", "新建会话").Clicked() {
a.newSessionForm()
}
},
})
if a.searchOpen {
ui.TextInput(c, &a.searchText).Placeholder("搜索会话").PaddingX(16).AutoFocus()
a.scheduleSearch()
}
if a.errorText != "" {
ui.Text(c, a.errorText).FontSize(13).TextColor(t.Danger).Padding(8, 16, 0, 16)
}
a.sessionList(c)
})
a.instancesSheet(c)
a.serverActionSheet(c)
a.deleteConfirmSheet(c)
a.newSessionSheet(c)
a.sessionActionSheet(c)
a.renameSheet(c)
a.sessionDeleteConfirm(c)
}
// iconButton is a small square button with an icon.
func (a *App) iconButton(c *ui.Context, icon, label string) ui.Element {
btn := ui.Button(c, "").Width(44).Height(44).Padding(0, 0)
btn.Children(func() {
bmp := iconBitmap(icon)
if bmp != nil {
ui.Image(c, bmp).Size(22, 22)
} else {
ui.Text(c, icon).FontSize(18)
}
})
_ = label
return btn
}
func (a *App) sessionList(c *ui.Context) {
if a.sessionsLoad && len(a.sessions) == 0 {
ui.Column(c).Fill().Center().Children(func() {
ui.Spinner(c)
})
return
}
if len(a.sessions) == 0 && !a.sessionsLoad {
ui.Column(c).Fill().Center().Gap(8).Children(func() {
ui.Text(c, "暂无会话")
if ui.PrimaryButton(c, "新建会话").Clicked() {
a.newSessionForm()
}
})
return
}
list := ui.List(c, &a.sessionListState, len(a.sessions))
list.ItemKey(func(i int) any { return a.sessions[i].ID })
list.Rows(func(r ui.ListRow) {
i := r.Index
s := a.sessions[i]
row := ui.Row(c).FillWidth().Gap(10).AlignItems(ui.Center).Padding(12, 16).
Role(ui.RoleButton).Label(s.Title)
row.Children(func() {
col := ui.Column(c).Grow(1).Basis(0).Gap(2)
col.Children(func() {
title := s.Title
if title == "" {
title = "(无标题会话)"
}
ui.Text(c, title).FontSize(16).FontWeight(600).MaxLines(1)
ui.Text(c, a.sessionSubtitle(s)).FontSize(13).TextColor(t(c).TextMuted).MaxLines(1)
})
if a.active[s.ID] {
ui.Text(c, "●").TextColor(t(c).Accent).FontSize(10)
}
if ui.Button(c, "⋯").Label("会话操作").Width(40).Clicked() {
a.openSessionActions(s)
}
})
if row.Clicked() {
a.openChat(s)
}
})
}
func t(c *ui.Context) *ui.Theme { return c.Theme() }
func (a *App) sessionSubtitle(s ocapi.Session) string {
parts := []string{}
if s.Agent != "" {
parts = append(parts, s.Agent)
}
if s.Model != nil {
parts = append(parts, a.modelName(s.Model))
}
if s.Time.Updated > 0 {
parts = append(parts, time.UnixMilli(s.Time.Updated).Format("01-02 15:04"))
}
out := ""
for i, p := range parts {
if i > 0 {
out += " · "
}
out += p
}
return out
}
// scheduleSearch debounces search input.
func (a *App) scheduleSearch() {
if a.searchTimer != nil {
a.searchTimer.Stop()
}
a.searchTimer = time.AfterFunc(350*time.Millisecond, func() {
a.win.Update(func() {
if a.searchText != "" {
a.searchSessions(a.searchText)
} else {
a.loadSessions()
}
})
})
}