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

+110
View File
@@ -0,0 +1,110 @@
// Package golden compares what a ui.Tester draws with images kept beside the
// tests, as golden files do, on the platform it runs on: text differs from one
// to another. Run the tests with MYGO_UPDATE_GOLDEN=1 to write them.
//
// func TestCard(t *testing.T) {
// tt := ui.NewTester(card, 320, 200)
// golden.Match(t, tt, "testdata/card.png")
// }
package golden
import (
"bytes"
"image"
"image/color"
"image/png"
"os"
"path/filepath"
"testing"
"github.com/egoist/mygo/ui"
)
// Tolerance is how far a channel of a pixel may be from the golden's, of 255,
// and how many pixels may be further, out of a thousand.
type Tolerance struct {
Channel int
PerMille int
}
// Exact asks for the same pixels.
var Exact = Tolerance{}
// Match fails t where the tester's frame differs from the image at path. A
// failure writes the frame beside it, as name.got.png, to compare.
func Match(t testing.TB, tt *ui.Tester, path string, tol ...Tolerance) {
t.Helper()
tt.Frame()
img := tt.Image()
if os.Getenv("MYGO_UPDATE_GOLDEN") != "" {
if err := write(path, img); err != nil {
t.Fatal(err)
}
return
}
f, err := os.ReadFile(path)
if err != nil {
t.Fatalf("%v: run with MYGO_UPDATE_GOLDEN=1 to write it", err)
}
want, err := png.Decode(bytes.NewReader(f))
if err != nil {
t.Fatalf("%s: %v", path, err)
}
limit := Exact
if len(tol) > 0 {
limit = tol[0]
}
if n, total := Diff(want, img, limit.Channel); n*1000 > total*limit.PerMille {
got := path[:len(path)-len(filepath.Ext(path))] + ".got.png"
if err := write(got, img); err != nil {
t.Error(err)
}
t.Errorf("%s: %d of %d pixels differ; what it drew is in %s", path, n, total, got)
}
}
// Diff counts the pixels that differ by more than channel in a channel, and
// the pixels of the larger image: those only one has differ.
func Diff(a, b image.Image, channel int) (n, total int) {
ab, bb := a.Bounds(), b.Bounds()
w, h := max(ab.Dx(), bb.Dx()), max(ab.Dy(), bb.Dy())
total = w * h
for y := range h {
for x := range w {
pa := image.Pt(ab.Min.X+x, ab.Min.Y+y)
pb := image.Pt(bb.Min.X+x, bb.Min.Y+y)
if !pa.In(ab) || !pb.In(bb) {
n++
continue
}
if differs(a.At(pa.X, pa.Y), b.At(pb.X, pb.Y), channel) {
n++
}
}
}
return n, total
}
func differs(a, b color.Color, limit int) bool {
ar, ag, ab, aa := a.RGBA()
br, bg, bb, ba := b.RGBA()
far := func(x, y uint32) bool {
d := int(x>>8) - int(y>>8)
if d < 0 {
d = -d
}
return d > limit
}
return far(ar, br) || far(ag, bg) || far(ab, bb) || far(aa, ba)
}
func write(path string, img image.Image) error {
if err := os.MkdirAll(filepath.Dir(path), 0o755); err != nil {
return err
}
var b bytes.Buffer
if err := png.Encode(&b, img); err != nil {
return err
}
return os.WriteFile(path, b.Bytes(), 0o644)
}
+38
View File
@@ -0,0 +1,38 @@
package golden
import (
"image"
"image/color"
"path/filepath"
"testing"
"github.com/egoist/mygo/ui"
)
func TestDiff(t *testing.T) {
a := image.NewRGBA(image.Rect(0, 0, 2, 2))
b := image.NewRGBA(image.Rect(0, 0, 2, 2))
if n, total := Diff(a, b, 0); n != 0 || total != 4 {
t.Errorf("same: %d of %d", n, total)
}
b.Set(1, 1, color.RGBA{10, 0, 0, 0})
if n, _ := Diff(a, b, 0); n != 1 {
t.Errorf("one pixel: %d", n)
}
if n, _ := Diff(a, b, 10); n != 0 {
t.Errorf("within tolerance: %d", n)
}
c := image.NewRGBA(image.Rect(0, 0, 3, 2))
if n, total := Diff(a, c, 0); n != 2 || total != 6 {
t.Errorf("sizes: %d of %d", n, total)
}
}
func TestMatch(t *testing.T) {
path := filepath.Join(t.TempDir(), "box.png")
view := func(c *ui.Context) { ui.Box(c).Fill().Background(ui.RGB(10, 20, 30)) }
t.Setenv("MYGO_UPDATE_GOLDEN", "1")
Match(t, ui.NewTester(view, 40, 40), path)
t.Setenv("MYGO_UPDATE_GOLDEN", "")
Match(t, ui.NewTester(view, 40, 40), path)
}