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

+93
View File
@@ -0,0 +1,93 @@
//go:build linux && !android && (amd64 || arm64)
package linux
import (
"sync"
"github.com/ebitengine/purego"
"github.com/egoist/mygo/internal/platform"
)
// Input methods ask for the text around the caret, and delete some of it
// before they commit what replaces it, as Hangul and other input methods
// that edit what was typed do.
var (
systemOnce sync.Once
gtkIMContextSetSurrounding func(im ptr, text *byte, length, cursor int32)
gtkIMContextGetSurrounding func(im ptr, text *ptr, cursor *int32) bool
gtkIMContextDeleteSurrounding func(im ptr, offset, n int32) bool
cbIMRetrieveSurrounding, cbIMDeleteSurrounding, cbSurfaceAreaDestroy ptr
// surfaceAreas finds surfaces by their widget.
surfaceAreas = map[ptr]*surface{}
)
// connectSystem connects the surface to the system's input methods, drag
// and drop, and assistive technology.
func (s *surface) connectSystem(data ptr) {
systemOnce.Do(initSystemSurface)
surfaceAreas[s.area] = s
connect(s.area, "destroy", cbSurfaceAreaDestroy, data)
connect(s.im, "retrieve-surrounding", cbIMRetrieveSurrounding, data)
connect(s.im, "delete-surrounding", cbIMDeleteSurrounding, data)
s.acceptFileDrops(data)
}
func initSystemSurface() {
t := libGTK
mustBind(t, &gtkIMContextSetSurrounding, "gtk_im_context_set_surrounding")
mustBind(t, &gtkIMContextGetSurrounding, "gtk_im_context_get_surrounding")
mustBind(t, &gtkIMContextDeleteSurrounding, "gtk_im_context_delete_surrounding")
loadDrops()
b := func() *Backend { return theBackend }
cbIMRetrieveSurrounding = purego.NewCallback(func(im, data ptr) bool {
s := b().surfaceOf(data)
if s == nil || !s.input.Active {
return false
}
text, cursor := s.surrounding()
gtkIMContextSetSurrounding(im, cs(text), int32(len(text)), int32(cursor))
return true
})
cbIMDeleteSurrounding = purego.NewCallback(func(im ptr, offset, n int32, data ptr) bool {
s := b().surfaceOf(data)
if s == nil || !s.input.Active || n < 0 {
return false
}
if client := s.input.Client; client != nil {
r := platform.ClientDeleteRange(client, int(offset), int(n))
client.ReplaceText(&r, "")
return true
}
from := s.input.End + int(offset)
s.send(platform.SurfaceEvent{Kind: platform.TextInput, Replace: true, From: from, To: from + int(n)})
return true
})
cbSurfaceAreaDestroy = purego.NewCallback(func(widget, data ptr) {
if s := surfaceAreas[widget]; s != nil {
delete(surfaceAreas, widget)
s.destroyAccess()
}
})
}
// surrounding returns the text around the caret that input methods see,
// and the caret's byte offset in it: the end of the selection.
func (s *surface) surrounding() (string, int) {
if c := s.input.Client; c != nil {
context := platform.ClientTextContext(c)
return context.Text, platform.UTF16ByteOffset(context.Text, context.Caret)
}
text, cursor := s.input.Text, 0
for i := range text {
if cursor == s.input.End {
return text, i
}
cursor++
}
return text, len(text)
}