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

+124
View File
@@ -0,0 +1,124 @@
package uimigrate
import (
"bytes"
"flag"
"fmt"
"go/format"
"go/importer"
"go/token"
"go/types"
"io"
"os"
"os/exec"
"sort"
"strings"
"testing"
)
var update = flag.Bool("update", false, "rewrite uiapi.go from package ui")
const uiPath = "github.com/egoist/mygo/ui"
// TestUIAPI derives uiapi.go from the compiled signatures of package ui, so
// the migrator's facts about its functions and methods cannot drift.
func TestUIAPI(t *testing.T) {
pkg, err := uiImporter(t).Import(uiPath)
if err != nil {
t.Fatal(err)
}
scope := pkg.Scope()
element := scope.Lookup("Element").Type()
parts := map[string]bool{}
for _, name := range scope.Names() {
if obj, ok := scope.Lookup(name).(*types.TypeName); ok && obj.Exported() && strings.HasSuffix(name, "Parts") {
if _, ok := obj.Type().Underlying().(*types.Struct); ok {
parts[name] = true
}
}
}
// kind names a result that the migrator converts: Element or parts.
kind := func(results *types.Tuple) string {
if results.Len() != 1 {
return ""
}
named, ok := results.At(0).Type().(*types.Named)
if !ok || named.Obj().Pkg() != pkg {
return ""
}
if name := named.Origin().Obj().Name(); name == "Element" || parts[name] {
return name
}
return ""
}
results := map[string]string{}
for _, name := range scope.Names() {
if fn, ok := scope.Lookup(name).(*types.Func); ok && fn.Exported() {
if k := kind(fn.Signature().Results()); k != "" {
results[name] = k
}
}
}
chains := map[string]bool{}
methods := types.NewMethodSet(types.NewPointer(element))
for i := range methods.Len() {
fn := methods.At(i).Obj().(*types.Func)
if fn.Exported() && kind(fn.Signature().Results()) == "Element" {
chains[fn.Name()] = true
}
}
var src bytes.Buffer
src.WriteString("// Code generated by go test ./internal/uimigrate -update from package ui; DO NOT EDIT.\n\npackage uimigrate\n\n")
src.WriteString("// uiResults maps each function of package ui that returns one Element or\n// custom parts value to that result's type. Other calls make neither.\nvar uiResults = map[string]string{\n")
for _, name := range sorted(results) {
fmt.Fprintf(&src, "%q: %q,\n", name, results[name])
}
src.WriteString("}\n\n// elementChains lists the methods of Element that return an Element.\nvar elementChains = map[string]bool{\n")
for _, name := range sorted(chains) {
fmt.Fprintf(&src, "%q: true,\n", name)
}
src.WriteString("}\n\n// uiParts lists package ui's custom parts types.\nvar uiParts = map[string]bool{\n")
for _, name := range sorted(parts) {
fmt.Fprintf(&src, "%q: true,\n", name)
}
src.WriteString("}\n")
got, err := format.Source(src.Bytes())
if err != nil {
t.Fatal(err)
}
if *update {
if err := os.WriteFile("uiapi.go", got, 0o644); err != nil {
t.Fatal(err)
}
return
}
if want, err := os.ReadFile("uiapi.go"); err != nil || !bytes.Equal(want, got) {
t.Fatalf("uiapi.go differs from package ui's signatures; go test ./internal/uimigrate -run TestUIAPI -update rewrites it:\n%s", got)
}
}
// uiImporter imports package ui from its compiled export data.
func uiImporter(t *testing.T) types.Importer {
t.Helper()
out, err := exec.Command("go", "list", "-export", "-f", "{{.Export}}", uiPath).Output()
if err != nil {
t.Fatal("export data of package ui:", err)
}
export := strings.TrimSpace(string(out))
return importer.ForCompiler(token.NewFileSet(), "gc", func(path string) (io.ReadCloser, error) {
if path != uiPath {
return nil, fmt.Errorf("unexpected import %s", path)
}
return os.Open(export)
})
}
func sorted[V any](m map[string]V) []string {
var names []string
for name := range m {
names = append(names, name)
}
sort.Strings(names)
return names
}