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

+74
View File
@@ -0,0 +1,74 @@
// Package mp3 decodes MP3 files for package audio, with
// github.com/hajimehoshi/go-mp3. Import it for its side effect:
//
// import _ "github.com/egoist/mygo/audio/mp3"
package mp3
import (
"encoding/binary"
"io"
"github.com/egoist/mygo/audio"
gomp3 "github.com/hajimehoshi/go-mp3"
)
func init() {
open := func(r io.ReadSeeker) (audio.Decoder, error) { return NewDecoder(r) }
// An ID3 tag, or the sync word of a frame of MPEG-1 or 2 layer III.
audio.RegisterFormat("mp3", "ID3", open)
for _, b := range []string{"\xff\xfb", "\xff\xfa", "\xff\xf3", "\xff\xf2", "\xff\xe3", "\xff\xe2"} {
audio.RegisterFormat("mp3", b, open)
}
}
// NewDecoder returns a decoder of the MP3 file r, which decodes to stereo.
func NewDecoder(r io.ReadSeeker) (audio.Decoder, error) {
d, err := gomp3.NewDecoder(r)
if err != nil {
return nil, err
}
return &decoder{d: d}, nil
}
// go-mp3 decodes to 16-bit stereo: 4 bytes a frame.
const frameBytes = 4
type decoder struct {
d *gomp3.Decoder
buf []byte
}
func (d *decoder) SampleRate() int { return d.d.SampleRate() }
func (d *decoder) Channels() int { return 2 }
func (d *decoder) Len() int64 {
if n := d.d.Length(); n > 0 {
return n / frameBytes
}
return -1
}
func (d *decoder) Read(dst []float32) (int, error) {
n := len(dst) / 2 * frameBytes
if cap(d.buf) < n {
d.buf = make([]byte, n)
}
b := d.buf[:n]
got, err := io.ReadFull(d.d, b)
got -= got % frameBytes
for i := 0; i < got/2; i++ {
dst[i] = float32(int16(binary.LittleEndian.Uint16(b[2*i:]))) / (1 << 15)
}
if got > 0 {
return got / 2, nil
}
if err == io.ErrUnexpectedEOF {
err = io.EOF
}
return 0, err
}
func (d *decoder) SetPosition(frame int64) error {
_, err := d.d.Seek(frame*frameBytes, io.SeekStart)
return err
}
+59
View File
@@ -0,0 +1,59 @@
package mp3
import (
"bytes"
"math"
"os"
"testing"
"time"
"github.com/egoist/mygo/audio"
)
// tone.mp3 is 0.5 s of a 440 Hz sine at 44.1 kHz, in mono, which decodes
// to stereo with the encoder's padding.
func TestDecode(t *testing.T) {
data, err := os.ReadFile("testdata/tone.mp3")
if err != nil {
t.Fatal(err)
}
d, name, err := audio.NewDecoder(bytes.NewReader(data))
if err != nil || name != "mp3" {
t.Fatal(name, err)
}
if d.SampleRate() != 44100 || d.Channels() != 2 {
t.Fatalf("%d Hz, %d channels", d.SampleRate(), d.Channels())
}
// go-mp3 keeps the encoder's delay and padding, a few frames of 1152.
if n := d.Len(); n < 22050 || n > 22050+4*1152 {
t.Errorf("Len = %d", n)
}
s, err := audio.DecodeSound(data)
if err != nil {
t.Fatal(err)
}
if got := s.Duration(); got < 500*time.Millisecond || got > 610*time.Millisecond {
t.Errorf("Duration = %v", got)
}
if err := d.SetPosition(10000); err != nil {
t.Fatal(err)
}
buf := make([]float32, 2*8820)
n := 0
for n < len(buf) {
m, err := d.Read(buf[n:])
n += m
if err != nil {
break
}
}
zc := 0
for i := 2; i < n; i += 2 {
if (buf[i-2] < 0) != (buf[i] < 0) {
zc++
}
}
if f := float64(zc) / 2 / (float64(n/2) / 44100); math.Abs(f-440) > 5 {
t.Errorf("decoded %v Hz from frame 10000", f)
}
}
Binary file not shown.