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:
1 parent
2fb4a8ea79
commit
6c0ee61750
2538 files changed
+675779
-4792
No files matched your search
Vendored
+140
@@ -0,0 +1,140 @@
|
||||
package ui
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestSpacingScalesWidgets(t *testing.T) {
|
||||
type sizes struct{ button, check, tab Rect }
|
||||
measure := func(spacing float32) sizes {
|
||||
tt := coreNewTester(func(c *context) {
|
||||
th := *c.Theme()
|
||||
th.Spacing = spacing
|
||||
c.SetTheme(&th)
|
||||
coreColumn(c).AlignItems(Start).Children(func() {
|
||||
coreButton(c, "OK").Label("button")
|
||||
on, tab := false, 0
|
||||
coreCheckbox(c, &on, "").Label("check")
|
||||
coreTabs(c, &tab, "One", "Two")
|
||||
})
|
||||
}, 400, 300)
|
||||
var s sizes
|
||||
s.button, _ = tt.Find("button")
|
||||
s.check, _ = tt.Find("check")
|
||||
s.tab, _ = tt.Find("One")
|
||||
return s
|
||||
}
|
||||
compact, normal, roomy, unset := measure(3), measure(4), measure(5), measure(0)
|
||||
if normal.check.W != 16 || normal.check.H != 16 {
|
||||
t.Errorf("the check box is %vx%v at the default spacing, not 16x16", normal.check.W, normal.check.H)
|
||||
}
|
||||
if unset != normal {
|
||||
t.Errorf("no spacing lays widgets out as %+v, not as the default %+v", unset, normal)
|
||||
}
|
||||
for name, got := range map[string][3]Rect{
|
||||
"button": {compact.button, normal.button, roomy.button},
|
||||
"check box": {compact.check, normal.check, roomy.check},
|
||||
} {
|
||||
if !(got[0].W < got[1].W && got[1].W < got[2].W && got[0].H < got[1].H && got[1].H < got[2].H) {
|
||||
t.Errorf("the %s does not grow with the spacing: %v", name, got)
|
||||
}
|
||||
}
|
||||
// The text of a tab sits in its padding: 3 units to the left.
|
||||
for _, s := range []sizes{compact, normal, roomy} {
|
||||
if s.tab.W <= 0 {
|
||||
t.Fatal("no tab")
|
||||
}
|
||||
}
|
||||
if !(compact.tab.X < normal.tab.X && normal.tab.X < roomy.tab.X) {
|
||||
t.Errorf("the tabs' padding does not follow the spacing: %v, %v, %v", compact.tab.X, normal.tab.X, roomy.tab.X)
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseHex(t *testing.T) {
|
||||
for _, tc := range []struct {
|
||||
in string
|
||||
want Color
|
||||
ok bool
|
||||
}{
|
||||
{"#2563eb", Color{R: 0x25, G: 0x63, B: 0xeb, A: 255}, true},
|
||||
{"2563EB", Color{R: 0x25, G: 0x63, B: 0xeb, A: 255}, true},
|
||||
{" #00ff0080 ", Color{R: 0, G: 255, B: 0, A: 0x80}, true},
|
||||
{"#fA0", Color{R: 255, G: 0xaa, B: 0, A: 255}, true},
|
||||
{"#fa08", Color{R: 255, G: 0xaa, B: 0, A: 0x88}, true},
|
||||
{"#12345", Color{}, false},
|
||||
{"#1234567", Color{}, false},
|
||||
{"#123456789", Color{}, false},
|
||||
{"#12345g", Color{}, false},
|
||||
{"#+12345", Color{}, false},
|
||||
{"#é12", Color{}, false},
|
||||
{"", Color{}, false},
|
||||
} {
|
||||
got, err := parseHex(tc.in)
|
||||
if got != tc.want || (err == nil) != tc.ok {
|
||||
t.Errorf("parseHex(%q) = %v, %v; want %v, ok %v", tc.in, got, err, tc.want, tc.ok)
|
||||
}
|
||||
}
|
||||
if n := testing.AllocsPerRun(10, func() { Hex("#2563eb") }); n != 0 {
|
||||
t.Errorf("Hex allocates %v times", n)
|
||||
}
|
||||
}
|
||||
|
||||
func TestInverseColors(t *testing.T) {
|
||||
th := *DarkTheme()
|
||||
if fill, text := th.inverse(); fill != th.Text || text != th.Background {
|
||||
t.Errorf("a theme without inverse colors gives %v on %v, not its text on its background", text, fill)
|
||||
}
|
||||
th.Inverse = Hex("#3a3a40")
|
||||
if fill, text := th.inverse(); fill != Hex("#3a3a40") || text != th.Background {
|
||||
t.Errorf("Inverse alone gives %v on %v", text, fill)
|
||||
}
|
||||
th.InverseText = Hex("#f2f2f7")
|
||||
if fill, text := th.inverse(); fill != Hex("#3a3a40") || text != Hex("#f2f2f7") {
|
||||
t.Errorf("both inverse colors give %v on %v", text, fill)
|
||||
}
|
||||
}
|
||||
|
||||
// inverseFills shows a tooltip and a toast in a window of theme th, and
|
||||
// returns the colors they are filled with.
|
||||
func inverseFills(t *testing.T, th *Theme) (tooltip, toast Color) {
|
||||
t.Helper()
|
||||
tt := coreNewTester(func(c *context) {
|
||||
c.SetTheme(th)
|
||||
coreColumn(c).Padding(40).Children(func() {
|
||||
if coreButton(c, "Save").Tooltip("Save the note").Clicked() {
|
||||
c.Toast("Saved")
|
||||
}
|
||||
})
|
||||
}, 400, 300)
|
||||
// Left of the text, inside the padding.
|
||||
fill := func(s string) Color {
|
||||
r, ok := tt.Find(s)
|
||||
if !ok {
|
||||
t.Fatalf("no %q; texts %q", s, tt.Texts())
|
||||
}
|
||||
px := tt.Image().RGBAAt(int(r.X)-3, int(r.Y+r.H/2))
|
||||
return Color{R: px.R, G: px.G, B: px.B, A: px.A}
|
||||
}
|
||||
b, _ := tt.Find("Save")
|
||||
tt.Move(b.X+b.W/2, b.Y+b.H/2)
|
||||
tt.rt.tips.hoverSince = tt.now.Add(-time.Second)
|
||||
tt.Frame()
|
||||
tooltip = fill("Save the note")
|
||||
tt.Click("Save")
|
||||
// Past its fading in.
|
||||
tt.rt.toasts[0].at = tt.now.Add(-time.Second)
|
||||
tt.Frame()
|
||||
return tooltip, fill("Saved")
|
||||
}
|
||||
|
||||
func TestInverseFillsTooltipsAndToasts(t *testing.T) {
|
||||
th := *DarkTheme()
|
||||
if tooltip, toast := inverseFills(t, &th); tooltip != th.Text || toast != th.Text {
|
||||
t.Errorf("a dark theme fills a tooltip with %v and a toast with %v, not its text color %v", tooltip, toast, th.Text)
|
||||
}
|
||||
th.Inverse, th.InverseText = Hex("#3a3a40"), Hex("#f2f2f7")
|
||||
if tooltip, toast := inverseFills(t, &th); tooltip != th.Inverse || toast != th.Inverse {
|
||||
t.Errorf("a theme fills a tooltip with %v and a toast with %v, not its Inverse %v", tooltip, toast, th.Inverse)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user