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

+158
View File
@@ -0,0 +1,158 @@
package ui
import (
"strings"
"testing"
"time"
"github.com/egoist/mygo/internal/pacing"
"github.com/egoist/mygo/internal/platform"
"github.com/egoist/mygo/internal/surface"
)
// uncapped has frames uncapped (MYGO_UNCAPPED) for the rest of the test.
func uncapped(t *testing.T) {
before := pacing.Uncapped
pacing.Uncapped = true
t.Cleanup(func() { pacing.Uncapped = before })
}
// askingSurface is a paced test surface that counts the frames asked for.
type askingSurface struct {
refreshSurface
asked int
}
func (s *askingSurface) RequestFrame() { s.asked++ }
// TestUncappedFramesInMemoryWaitForNoRefresh checks that, uncapped, a paced
// frame drawn in memory on a surface that shows such frames at once, as
// Windows' does, draws at once, rather than wait for the display's next
// refresh as TestFramesInMemoryWaitForTheRefresh's do: nothing waits for
// the display, off the main thread or on it.
func TestUncappedFramesInMemoryWaitForNoRefresh(t *testing.T) {
uncapped(t)
t.Setenv("MYGO_GPU", "0")
s := &refreshSurface{refresh: make(chan struct{})}
h := &windowHost{conn: &surface.Conn{Surface: s}}
h.rt = newRuntime(func(c *context) { coreText(c, "Hello") }, h)
s.h = h
posted := 0
h.conn.Post = func(func()) { posted++ }
h.event(platform.SurfaceEvent{Kind: platform.SurfaceFrame})
for i := range 3 {
h.event(platform.SurfaceEvent{Kind: platform.SurfaceFrame, Paced: true})
if s.pixels != i+2 || h.waiting || h.refresh != nil || posted != 0 {
t.Fatalf("paced frame %d: %d frames, waiting %v, refresh awaited %v, %d posted", i, s.pixels, h.waiting, h.refresh != nil, posted)
}
}
}
// TestUncappedFramesComeAtOnce checks that, uncapped, every surface's
// frames count as coming as soon as asked for (framesAtOnce), so that a
// drawing asking for fewer frames (Painter.AnimationFrameRate) keeps its
// pace with the repaint timer rather than a frame each time one is asked
// for, as TestAnimationFrameRateAtOnce checks.
func TestUncappedFramesComeAtOnce(t *testing.T) {
h := &windowHost{conn: &surface.Conn{Surface: &testSurface{}}}
if h.framesAtOnce() {
t.Fatal("a surface paced by the display has frames at once")
}
uncapped(t)
if !h.framesAtOnce() {
t.Fatal("uncapped, frames do not come at once")
}
}
// TestUncappedIdleAsksNoFrame checks that uncapped frames never come while
// nothing changes: a frame asks for the next only while something moves,
// once each frame, and none once it stops, so that an idle window draws
// nothing, uncapped or not.
func TestUncappedIdleAsksNoFrame(t *testing.T) {
uncapped(t)
t.Setenv("MYGO_GPU", "0")
moving := true
s := &askingSurface{}
h := &windowHost{conn: &surface.Conn{Surface: s}}
h.rt = newRuntime(func(c *context) {
coreBox(c).Size(100, 20).Draw(func(p *Painter, r Rect) {
if moving {
p.AnimationFrame()
}
p.Fill(Rect{r.X, r.Y, 2, r.H}, RGB(0, 0, 255), 0)
})
}, h)
s.h = h
frame := func() { h.event(platform.SurfaceEvent{Kind: platform.SurfaceFrame, Paced: true}) }
frame()
for i := range 5 {
if s.asked != i+1 {
t.Fatalf("frame %d of an animation asked for %d frames, want %d", i, s.asked, i+1)
}
frame()
}
moving = false
asked := s.asked
frame() // the frame the last asked for, which moves nothing
frame() // as a resize's or a late tick's
if s.asked != asked {
t.Fatalf("frames once nothing moves asked for %d more", s.asked-asked)
}
}
// TestUncappedFrameRate checks the line MYGO_FRAME_STATS logs uncapped:
// how many frames came a second, once they followed each other for a
// second, counted anew after a pause or a frame as long.
func TestUncappedFrameRate(t *testing.T) {
var logged []string
defer func(f func(...any)) { frameLog = f }(frameLog)
frameLog = func(v ...any) { logged = append(logged, v[0].(string)) }
f := newFrameStats(time.Hour)
at := time.Unix(1000, 0)
// 2 ms frames, back to back: 500 a second.
for range 499 {
f.rate(at, at.Add(2*time.Millisecond))
at = at.Add(2 * time.Millisecond)
}
if len(logged) != 0 {
t.Fatalf("logged before a second: %q", logged)
}
f.rate(at, at.Add(2*time.Millisecond))
at = at.Add(2 * time.Millisecond)
if len(logged) != 1 || !strings.Contains(logged[0], "500 frames a second, uncapped: 2.00 ms a frame") {
t.Fatalf("after a second: %q", logged)
}
// An idle second counts for nothing: the count starts anew.
at = at.Add(time.Second)
for range 99 {
f.rate(at, at.Add(10*time.Millisecond))
at = at.Add(10 * time.Millisecond)
}
if len(logged) != 1 {
t.Fatalf("the pause counted: %q", logged)
}
f.rate(at, at.Add(10*time.Millisecond))
at = at.Add(10 * time.Millisecond)
if len(logged) != 2 || !strings.Contains(logged[1], "100 frames a second") {
t.Fatalf("after the pause: %q", logged)
}
// A frame that took 2 s, as a present that waited on the system, is a
// pause too: the second it ends in counts the frames after it only,
// not a few frames a second.
for range 50 {
f.rate(at, at.Add(10*time.Millisecond))
at = at.Add(10 * time.Millisecond)
}
f.rate(at, at.Add(2*time.Second))
at = at.Add(2 * time.Second)
if len(logged) != 2 {
t.Fatalf("the long frame counted: %q", logged)
}
for range 1000 {
f.rate(at, at.Add(time.Millisecond))
at = at.Add(time.Millisecond)
}
if len(logged) != 3 || !strings.Contains(logged[2], "1000 frames a second") {
t.Fatalf("after the long frame: %q", logged)
}
}