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
@@ -0,0 +1,132 @@
|
||||
//go:build darwin && !ios
|
||||
|
||||
package darwin
|
||||
|
||||
import (
|
||||
"runtime"
|
||||
"sync"
|
||||
"testing"
|
||||
|
||||
"github.com/ebitengine/purego"
|
||||
"github.com/egoist/mygo/internal/platform"
|
||||
)
|
||||
|
||||
var (
|
||||
accessClassTestOnce sync.Once
|
||||
accessNoteTestOnce sync.Once
|
||||
accessNoteTestCall uintptr
|
||||
accessNoteTestHook func(id)
|
||||
)
|
||||
|
||||
// A native accessibility notification can synchronously call back into MyGo.
|
||||
// Keep one callback for its ABI, rather than leaking one per test or element.
|
||||
func observeAccessNotes(t *testing.T, hook func(id)) {
|
||||
t.Helper()
|
||||
loadAccess()
|
||||
accessNoteTestOnce.Do(func() {
|
||||
accessNoteTestCall = purego.NewCallback(func(obj, _ uintptr) {
|
||||
if accessNoteTestHook != nil {
|
||||
accessNoteTestHook(id(obj))
|
||||
}
|
||||
})
|
||||
})
|
||||
previous := postAccessNote
|
||||
postAccessNote, accessNoteTestHook = accessNoteTestCall, hook
|
||||
t.Cleanup(func() { postAccessNote, accessNoteTestHook = previous, nil })
|
||||
}
|
||||
|
||||
func accessFixture(t *testing.T) *surface {
|
||||
t.Helper()
|
||||
runtime.LockOSThread()
|
||||
t.Cleanup(runtime.UnlockOSThread)
|
||||
load()
|
||||
accessClassTestOnce.Do(registerAccessClass)
|
||||
b := &Backend{byAccess: map[id]*accessElement{}}
|
||||
s := &surface{w: &window{b: b}}
|
||||
withPool(func() { s.view = send(send(class("NSView"), "alloc"), "init") })
|
||||
previous := theBackend
|
||||
theBackend = b
|
||||
t.Cleanup(func() {
|
||||
withPool(func() {
|
||||
s.w.closed = true
|
||||
s.destroyAccess()
|
||||
release(s.view)
|
||||
})
|
||||
theBackend = previous
|
||||
})
|
||||
return s
|
||||
}
|
||||
|
||||
func accessPair(child uint64) *platform.AccessTree {
|
||||
return &platform.AccessTree{Nodes: []platform.AccessNode{
|
||||
{ID: 1, Parent: -1, Role: platform.RoleGroup},
|
||||
{ID: child, Parent: 0, Role: platform.RoleButton, Label: "Button"},
|
||||
}}
|
||||
}
|
||||
|
||||
func TestAccessibilityNotificationQueuesLatestTree(t *testing.T) {
|
||||
s := accessFixture(t)
|
||||
s.UpdateAccessibility(accessPair(2))
|
||||
removed, root := s.elements[2].obj, s.elements[1].obj
|
||||
called := false
|
||||
latest := accessPair(5)
|
||||
latest.Nodes[0].Controls = []uint64{5}
|
||||
observeAccessNotes(t, func(obj id) {
|
||||
if obj == removed && !called {
|
||||
called = true
|
||||
s.UpdateAccessibility(accessPair(4))
|
||||
s.UpdateAccessibility(latest)
|
||||
}
|
||||
})
|
||||
// Removing node 2 posts AXUIElementDestroyed. A nested update used to
|
||||
// remove node 3 from the outer transaction and panic at el.linked.
|
||||
s.UpdateAccessibility(accessPair(3))
|
||||
if !called || len(s.elements) != 2 || s.elements[5] == nil || s.elements[3] != nil || s.elements[4] != nil {
|
||||
t.Fatal("nested updates did not settle on the latest complete tree")
|
||||
}
|
||||
if len(s.access.Nodes) != 2 || s.access.Nodes[1].ID != 5 || s.updating {
|
||||
t.Fatal("the published accessibility tree does not match its native elements")
|
||||
}
|
||||
if links := s.elements[1].linked; s.elements[1].obj != root || len(links) != 1 || links[0] != s.elements[5].obj || len(s.w.b.byAccess) != 2 {
|
||||
t.Fatal("the latest tree lost its control links or leaked retired native elements")
|
||||
}
|
||||
}
|
||||
|
||||
func TestAccessibilityNotificationCanDestroySurface(t *testing.T) {
|
||||
s := accessFixture(t)
|
||||
s.UpdateAccessibility(accessPair(2))
|
||||
removed := s.elements[2].obj
|
||||
called := false
|
||||
observeAccessNotes(t, func(obj id) {
|
||||
if obj == removed && !called {
|
||||
called = true
|
||||
s.UpdateAccessibility(accessPair(4))
|
||||
s.w.closed = true
|
||||
s.destroyAccess()
|
||||
}
|
||||
})
|
||||
s.UpdateAccessibility(accessPair(3))
|
||||
if !called || len(s.elements) != 0 || len(s.w.b.byAccess) != 0 || s.topLevel != 0 || len(s.access.Nodes) != 0 || s.updating {
|
||||
t.Fatal("surface destruction left accessibility objects or resumed a stale update")
|
||||
}
|
||||
// A late frame cannot resurrect a destroyed surface's native elements.
|
||||
s.UpdateAccessibility(accessPair(4))
|
||||
if len(s.elements) != 0 {
|
||||
t.Fatal("late update resurrected destroyed accessibility elements")
|
||||
}
|
||||
}
|
||||
|
||||
func TestAccessibilityDestroyNotificationIsReentrant(t *testing.T) {
|
||||
s := accessFixture(t)
|
||||
s.UpdateAccessibility(accessPair(2))
|
||||
calls := 0
|
||||
observeAccessNotes(t, func(obj id) {
|
||||
calls++
|
||||
s.destroyAccess()
|
||||
s.UpdateAccessibility(accessPair(3))
|
||||
})
|
||||
s.destroyAccess()
|
||||
if calls != 2 || len(s.elements) != 0 || len(s.w.b.byAccess) != 0 || s.topLevel != 0 || len(s.access.Nodes) != 0 {
|
||||
t.Fatal("recursive destruction released an element twice or allowed it to be recreated")
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user