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

+67 -78
View File
@@ -1,5 +1,5 @@
// Package storage keeps saved servers in the app's store and their device
// tokens in the platform's secure storage.
// Package storage keeps saved servers in the app's data directory and
// their device tokens in the platform's secure storage.
package storage
import (
@@ -7,12 +7,13 @@ import (
"crypto/sha256"
"encoding/hex"
"encoding/json"
"net/url"
"errors"
"os"
"path/filepath"
"sort"
"sync"
"github.com/egoist/asuka/sdk/secure"
"github.com/egoist/asuka/sdk/store"
"github.com/egoist/asuka/signal"
"github.com/egoist/mygo"
)
// Connection is one saved server.
@@ -38,84 +39,81 @@ type Store interface {
ClearToken(c Connection) error
}
// Persistent is the app's store: servers in store.json, tokens in the
// Android Keystore / Keychain.
// Persistent is the app's store: servers in connections.json, tokens in
// the platform's secure store (the Android Keystore / iOS Keychain).
type Persistent struct {
conns *signal.Signal[[]Connection]
installID *signal.Signal[string]
mu sync.Mutex
path string
conns []Connection
installID string
}
const (
connectionsKey = "openchamber.connections"
installIDKey = "openchamber.installId"
// legacyKey is the single-server record earlier versions wrote.
legacyKey = "openchamber.connection"
)
// New makes the persistent store. Call it on the main thread, while a
// component builds, as any signal.
// New makes the persistent store. It reads the servers file once; call it
// on startup, before any window shows.
func New() *Persistent {
conns := store.Signal(connectionsKey, []Connection{})
list := conns.Get()
if len(list) == 0 {
list = migrateLegacy()
if len(list) > 0 {
conns.Set(list)
}
}
p := &Persistent{
conns: conns,
installID: store.Signal(installIDKey, ""),
p := &Persistent{}
dir, err := mygo.App.Path(mygo.PathUserData)
if err == nil {
p.path = filepath.Join(dir, "connections.json")
}
p.load()
return p
}
// migrateLegacy turns the old single-connection record into a list entry.
func migrateLegacy() []Connection {
var raw string
if !store.Get(legacyKey, &raw) || raw == "" {
return nil
func (p *Persistent) load() {
if p.path == "" {
return
}
var old Connection
if json.Unmarshal([]byte(raw), &old) != nil || old.URL == "" {
return nil
data, err := os.ReadFile(p.path)
if err != nil {
return
}
if old.ID == "" {
old.ID = newID()
var list []Connection
if json.Unmarshal(data, &list) == nil {
p.conns = list
}
if old.Label == "" || 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.
_ = store.Set(legacyKey, "")
return []Connection{old}
}
func (p *Persistent) save() {
if p.path == "" {
return
}
if err := os.MkdirAll(filepath.Dir(p.path), 0o700); err != nil {
return
}
data, _ := json.Marshal(p.conns)
_ = os.WriteFile(p.path, data, 0o600)
}
// migrateLegacy is gone: the earlier Asuka builds kept their data in
// Asuka's own stores, which this app cannot read.
func (p *Persistent) Connections() []Connection {
list := p.conns.Get()
out := make([]Connection, len(list))
copy(out, list)
p.mu.Lock()
defer p.mu.Unlock()
out := make([]Connection, len(p.conns))
copy(out, p.conns)
return out
}
func (p *Persistent) SaveConnections(list []Connection) {
sort.SliceStable(list, func(i, j int) bool { return list[i].LastUsedAt > list[j].LastUsedAt })
p.conns.Set(list)
p.mu.Lock()
p.conns = list
p.mu.Unlock()
p.save()
}
// InstallID is a stable random id for this installation. It names the
// device when logging in, so repeated logins reuse one device record.
func (p *Persistent) InstallID() string {
if id := p.installID.Get(); id != "" {
return id
p.mu.Lock()
defer p.mu.Unlock()
if p.installID != "" {
return p.installID
}
id := newID()
p.installID.Set(id)
return id
p.installID = NewID()
return p.installID
}
func (p *Persistent) tokenKey(id string) string {
@@ -123,38 +121,29 @@ func (p *Persistent) tokenKey(id string) string {
return "openchamber.token." + hex.EncodeToString(sum[:12])
}
// legacyTokenKey is where earlier versions kept a token: by server URL.
func legacyTokenKey(url string) string {
sum := sha256.Sum256([]byte(url))
return "openchamber.token." + hex.EncodeToString(sum[:12])
}
func (p *Persistent) LoadToken(c Connection) (string, bool, error) {
if tok, ok, err := secure.Get(p.tokenKey(c.ID)); err != nil || ok {
return tok, ok, err
tok, err := mygo.Secrets.Get(p.tokenKey(c.ID))
if errors.Is(err, mygo.ErrSecretNotFound) {
return "", false, nil
}
// A connection migrated from the single-server record keeps its token
// under the old URL-based key.
return secure.Get(legacyTokenKey(c.URL))
if err != nil {
return "", false, err
}
return string(tok), true, nil
}
func (p *Persistent) SaveToken(id, token string) error {
return secure.Set(p.tokenKey(id), token)
return mygo.Secrets.Set(p.tokenKey(id), []byte(token))
}
func (p *Persistent) ClearToken(c Connection) error {
err := secure.Delete(p.tokenKey(c.ID))
_ = secure.Delete(legacyTokenKey(c.URL))
return err
return mygo.Secrets.Delete(p.tokenKey(c.ID))
}
func newID() string {
func NewID() string {
var b [8]byte
if _, err := rand.Read(b[:]); err != nil {
return "srv_" + hex.EncodeToString(b[:4])
}
return "srv_" + hex.EncodeToString(b[:])
}
// NewID returns a fresh connection id.
func NewID() string { return newID() }