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

+90
View File
@@ -0,0 +1,90 @@
package platform
// MenuIconSize is the box, in points (DIPs), that a menu item's icon is
// drawn to fit, keeping its aspect: the size of the icons of the
// system's own menus on macOS, Windows and Linux.
const MenuIconSize = 16
// MenuIcon is the image a menu item shows beside its label. Package mygo
// shares one between the snapshots of the items showing the same image,
// and makes a new one when an item's image changes, so a backend tells a
// change by the pointer and decodes each image once (Native).
type MenuIcon struct {
// PNG is the image, its bytes never changed once made.
PNG []byte
// Template is a black and transparent image, which takes the color of
// the menu's text where the backend can tint it.
Template bool
native any
made bool
}
// Native returns what make made of the icon the first time it was asked:
// a backend's decoding of it, kept for as long as the icon is, which
// make may free with runtime.AddCleanup. A nil result is kept too, as an
// image that cannot be decoded. Backends call it on the main thread.
func (ic *MenuIcon) Native(make func() any) any {
if !ic.made {
ic.native, ic.made = make(), true
}
return ic.native
}
// FitIcon returns the size of an image of w by h pixels drawn to fit a box
// of box by box pixels, keeping its aspect, at least a pixel each way.
func FitIcon(w, h, box int) (int, int) {
if w <= 0 || h <= 0 || box <= 0 {
return 0, 0
}
if w >= h {
return box, max(1, (h*box+w/2)/w)
}
return max(1, (w*box+h/2)/h), box
}
// LabelWithSubtitle is the label of a backend that can't show the subtitle
// on a line of its own.
func (it *MenuItem) LabelWithSubtitle() string {
if it.Subtitle == "" {
return it.Label
}
return it.Label + " — " + it.Subtitle
}
// LabelWithBadge is the label of a backend that shows the subtitle on a
// line of its own, followed by the badge.
func (it *MenuItem) LabelWithBadge() string {
if it.Badge == "" {
return it.Label
}
return it.Label + " " + it.Badge
}
// LabelWithSubtitleAndBadge is the label of a backend that can show neither
// the subtitle nor the badge on its own: both follow the label.
func (it *MenuItem) LabelWithSubtitleAndBadge() string {
label := it.LabelWithSubtitle()
if it.Badge == "" {
return label
}
return label + " " + it.Badge
}
// Apply gives the items of the menu that it is a snapshot of, by ID, its
// state: a backend that keeps a snapshot to build menus from later (a
// tray's, the application menu for new windows) keeps it current with the
// updates it is given.
func (m *Menu) Apply(it *MenuItem) {
if m == nil {
return
}
for i, x := range m.Items {
if x.ID == it.ID {
c := *it
m.Items[i] = &c
continue
}
x.Submenu.Apply(it)
}
}