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

+132
View File
@@ -0,0 +1,132 @@
// Package menuicon turns the PNG images of menu items into the pixels a
// backend that draws them itself needs: premultiplied BGRA, as Windows'
// 32-bit DIB sections (PARGB) take them, scaled to the menu's size.
package menuicon
import (
"bytes"
"image"
"image/png"
)
// Image is a decoded image, its pixels premultiplied 0xAARRGGBB, row after
// row from the top.
type Image struct {
W, H int
Px []uint32
}
// Decode decodes a PNG image.
func Decode(data []byte) (*Image, error) {
src, err := png.Decode(bytes.NewReader(data))
if err != nil {
return nil, err
}
return FromImage(src), nil
}
// FromImage copies an image's pixels.
func FromImage(src image.Image) *Image {
r := src.Bounds()
img := &Image{W: r.Dx(), H: r.Dy(), Px: make([]uint32, r.Dx()*r.Dy())}
i := 0
for y := r.Min.Y; y < r.Max.Y; y++ {
for x := r.Min.X; x < r.Max.X; x++ {
// RGBA is premultiplied, 16 bits a channel.
cr, cg, cb, ca := src.At(x, y).RGBA()
img.Px[i] = ca>>8<<24 | cr>>8<<16 | cg>>8<<8 | cb>>8
i++
}
}
return img
}
// Scale returns the image at w by h pixels, each pixel the average of the
// part of the image it covers, which keeps fine lines of a large image
// as a box filter does when it shrinks, and draws it in blocks when it
// grows.
func (img *Image) Scale(w, h int) *Image {
if w <= 0 || h <= 0 || img.W == 0 || img.H == 0 {
return &Image{}
}
if w == img.W && h == img.H {
return img
}
xs, ys := spans(img.W, w), spans(img.H, h)
out := &Image{W: w, H: h, Px: make([]uint32, w*h)}
for dy, ry := range ys {
for dx, rx := range xs {
var a, r, g, b, total float64
for _, sy := range ry {
row := img.Px[sy.i*img.W:]
for _, sx := range rx {
k := sx.w * sy.w
p := row[sx.i]
a += k * float64(p>>24)
r += k * float64(p>>16&0xFF)
g += k * float64(p>>8&0xFF)
b += k * float64(p&0xFF)
total += k
}
}
out.Px[dy*w+dx] = channel(a/total)<<24 | channel(r/total)<<16 | channel(g/total)<<8 | channel(b/total)
}
}
return out
}
// Tint returns the image in one color, 0xRRGGBB, keeping its alpha: a
// template image in the color of the menu's text.
func (img *Image) Tint(rgb uint32) *Image {
out := &Image{W: img.W, H: img.H, Px: make([]uint32, len(img.Px))}
cr, cg, cb := rgb>>16&0xFF, rgb>>8&0xFF, rgb&0xFF
for i, p := range img.Px {
a := p >> 24
out.Px[i] = a<<24 | (cr*a+127)/255<<16 | (cg*a+127)/255<<8 | (cb*a+127)/255
}
return out
}
// Over returns a premultiplied pixel drawn over an opaque one, 0x00RRGGBB,
// at an opacity from 0 to 1.
func Over(src, dst uint32, opacity float64) uint32 {
a := float64(src>>24) / 255 * opacity
mix := func(shift uint) uint32 {
s, d := float64(src>>shift&0xFF)*opacity, float64(dst>>shift&0xFF)
return channel(s+d*(1-a)) << shift
}
return mix(16) | mix(8) | mix(0)
}
func channel(v float64) uint32 {
switch {
case v <= 0:
return 0
case v >= 255:
return 255
}
return uint32(v + 0.5)
}
// span is a source pixel and how much of it a destination pixel covers.
type span struct {
i int
w float64
}
// spans returns, for each of n destination pixels, the source pixels of a
// row (or column) of size pixels it covers, and by how much.
func spans(size, n int) [][]span {
out := make([][]span, n)
scale := float64(size) / float64(n)
for d := range out {
lo, hi := float64(d)*scale, float64(d+1)*scale
for s := int(lo); s < size && float64(s) < hi; s++ {
w := min(hi, float64(s+1)) - max(lo, float64(s))
if w > 1e-9 {
out[d] = append(out[d], span{s, w})
}
}
}
return out
}
+110
View File
@@ -0,0 +1,110 @@
package menuicon
import (
"bytes"
"image"
"image/color"
"image/png"
"testing"
)
func encode(t *testing.T, img image.Image) []byte {
t.Helper()
var b bytes.Buffer
if err := png.Encode(&b, img); err != nil {
t.Fatal(err)
}
return b.Bytes()
}
// A PNG's straight alpha comes out premultiplied, in BGRA's order.
func TestDecodePremultiplies(t *testing.T) {
src := image.NewNRGBA(image.Rect(0, 0, 2, 1))
src.SetNRGBA(0, 0, color.NRGBA{R: 255, G: 128, B: 0, A: 255})
src.SetNRGBA(1, 0, color.NRGBA{R: 255, G: 255, B: 255, A: 128})
img, err := Decode(encode(t, src))
if err != nil {
t.Fatal(err)
}
if img.W != 2 || img.H != 1 {
t.Fatalf("size = %dx%d, want 2x1", img.W, img.H)
}
if got := img.Px[0]; got != 0xFFFF8000 {
t.Errorf("opaque orange = %#08x, want 0xffff8000", got)
}
if got := img.Px[1]; got != 0x80808080 {
t.Errorf("half white = %#08x, want 0x80808080", got)
}
}
func TestDecodeRejectsOtherData(t *testing.T) {
if _, err := Decode([]byte("not a png")); err == nil {
t.Error("Decode of text succeeded")
}
}
// Shrinking averages the pixels each covers, in premultiplied space: a
// transparent pixel does not darken an opaque one.
func TestScaleAverages(t *testing.T) {
img := &Image{W: 4, H: 2, Px: []uint32{
0xFFFF0000, 0x00000000, 0xFF0000FF, 0xFF0000FF,
0xFFFF0000, 0x00000000, 0xFF0000FF, 0xFF0000FF,
}}
got := img.Scale(2, 1)
if got.W != 2 || got.H != 1 {
t.Fatalf("size = %dx%d", got.W, got.H)
}
if got.Px[0] != 0x80800000 {
t.Errorf("red over transparent = %#08x, want half red, half covered (0x80800000)", got.Px[0])
}
if got.Px[1] != 0xFF0000FF {
t.Errorf("blue = %#08x, want 0xff0000ff", got.Px[1])
}
}
// A size that does not divide the image's weighs the pixels split between
// two by how much of each is covered.
func TestScaleFractional(t *testing.T) {
img := &Image{W: 3, H: 1, Px: []uint32{0xFF000000, 0xFFFFFFFF, 0xFF000000}}
got := img.Scale(2, 1)
for i, p := range got.Px {
if p>>24 != 0xFF || p&0xFF < 0x50 || p&0xFF > 0x56 {
t.Errorf("pixel %d = %#08x, want opaque, a third white", i, p)
}
}
if same := img.Scale(3, 1); same != img {
t.Error("Scale to the image's own size copied it")
}
if up := img.Scale(6, 2); up.Px[0] != 0xFF000000 || up.Px[2] != 0xFFFFFFFF || up.Px[6+5] != 0xFF000000 {
t.Errorf("growing = %#08x", up.Px)
}
}
func TestTintKeepsAlpha(t *testing.T) {
img := &Image{W: 2, H: 1, Px: []uint32{0xFF000000, 0x80000000}}
got := img.Tint(0xFFFFFF)
if got.Px[0] != 0xFFFFFFFF || got.Px[1] != 0x80808080 {
t.Errorf("white template = %#08x, want 0xffffffff and 0x80808080", got.Px)
}
if img.Px[0] != 0xFF000000 {
t.Error("Tint changed the image")
}
}
func TestOver(t *testing.T) {
for _, c := range []struct {
src, dst uint32
opacity float64
want uint32
}{
{0xFFFF0000, 0x00FFFFFF, 1, 0xFF0000}, // opaque covers
{0x00000000, 0x00123456, 1, 0x123456}, // transparent leaves
{0x80800000, 0x00000000, 1, 0x800000}, // half red over black
{0x80800000, 0x00FFFFFF, 1, 0xFF7F7F}, // half red over white
{0xFF0000FF, 0x00FF0000, 0.5, 0x800080}, // half opacity
} {
if got := Over(c.src, c.dst, c.opacity); got != c.want {
t.Errorf("Over(%#08x, %#06x, %v) = %#06x, want %#06x", c.src, c.dst, c.opacity, got, c.want)
}
}
}