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
+108
@@ -0,0 +1,108 @@
|
||||
// Package uivet checks native UI build lifetimes using Go type information.
|
||||
package uivet
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"go/ast"
|
||||
"go/token"
|
||||
"go/types"
|
||||
"sort"
|
||||
)
|
||||
|
||||
const uiPath = "github.com/egoist/mygo/ui"
|
||||
|
||||
type Diagnostic struct {
|
||||
Position token.Position
|
||||
Message string
|
||||
}
|
||||
|
||||
func (d Diagnostic) String() string { return fmt.Sprintf("%s: %s", d.Position, d.Message) }
|
||||
|
||||
// Analyze flags per-pass values in storage and values passed to or captured by
|
||||
// goroutines. Callback signatures and persistent Handle/Services are allowed.
|
||||
func Analyze(fs *token.FileSet, files []*ast.File, pkg *types.Package, info *types.Info) []Diagnostic {
|
||||
if pkg.Path() == uiPath {
|
||||
return nil
|
||||
}
|
||||
var out []Diagnostic
|
||||
report := func(pos token.Pos, message string) { out = append(out, Diagnostic{fs.Position(pos), message}) }
|
||||
for _, f := range files {
|
||||
ast.Inspect(f, func(n ast.Node) bool {
|
||||
switch n := n.(type) {
|
||||
case *ast.StructType:
|
||||
for _, field := range n.Fields.List {
|
||||
if transient(info.TypeOf(field.Type)) {
|
||||
report(field.Pos(), "native UI build value stored in a struct; keep ui.Handle or ui.Services instead")
|
||||
}
|
||||
}
|
||||
case *ast.ValueSpec:
|
||||
for _, name := range n.Names {
|
||||
if object, ok := info.Defs[name].(*types.Var); ok && object.Parent() == pkg.Scope() && transient(object.Type()) {
|
||||
report(name.Pos(), "native UI build value stored in a package variable; keep ui.Handle or ui.Services instead")
|
||||
}
|
||||
}
|
||||
case *ast.GoStmt:
|
||||
seen := map[types.Object]bool{}
|
||||
for _, arg := range n.Call.Args {
|
||||
if transient(info.TypeOf(arg)) {
|
||||
report(arg.Pos(), "native UI build value passed to a goroutine; publish results with Window.Update")
|
||||
}
|
||||
}
|
||||
ast.Inspect(n.Call.Fun, func(child ast.Node) bool {
|
||||
id, ok := child.(*ast.Ident)
|
||||
if !ok {
|
||||
return true
|
||||
}
|
||||
object := info.Uses[id]
|
||||
if _, ok := object.(*types.Var); !ok {
|
||||
return true
|
||||
}
|
||||
if object == nil || seen[object] || object.Pos() >= n.Pos() || !transient(object.Type()) {
|
||||
return true
|
||||
}
|
||||
seen[object] = true
|
||||
report(id.Pos(), "native UI build value captured by a goroutine; publish results with Window.Update")
|
||||
return true
|
||||
})
|
||||
}
|
||||
return true
|
||||
})
|
||||
}
|
||||
sort.Slice(out, func(i, j int) bool {
|
||||
a, b := out[i].Position, out[j].Position
|
||||
if a.Filename != b.Filename {
|
||||
return a.Filename < b.Filename
|
||||
}
|
||||
return a.Offset < b.Offset
|
||||
})
|
||||
return out
|
||||
}
|
||||
|
||||
func transient(t types.Type) bool {
|
||||
if t == nil {
|
||||
return false
|
||||
}
|
||||
t = types.Unalias(t)
|
||||
switch t := t.(type) {
|
||||
case *types.Pointer:
|
||||
return transient(t.Elem())
|
||||
case *types.Slice:
|
||||
return transient(t.Elem())
|
||||
case *types.Array:
|
||||
return transient(t.Elem())
|
||||
case *types.Map:
|
||||
return transient(t.Key()) || transient(t.Elem())
|
||||
case *types.Chan:
|
||||
return transient(t.Elem())
|
||||
case *types.Named:
|
||||
object := t.Obj()
|
||||
if object.Pkg() == nil || object.Pkg().Path() != uiPath {
|
||||
return false
|
||||
}
|
||||
switch object.Name() {
|
||||
case "Element", "Context", "TabsParts", "SelectParts", "ComboboxParts", "CollapsibleParts", "SegmentedParts", "ToastParts", "AccordionParts", "MenuParts", "TreeParts", "TreeItemParts", "OutlineRow", "ListRow":
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
+55
@@ -0,0 +1,55 @@
|
||||
package uivet
|
||||
|
||||
import (
|
||||
"go/ast"
|
||||
"go/parser"
|
||||
"go/token"
|
||||
"go/types"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
type testImporter struct{ ui *types.Package }
|
||||
|
||||
func (i testImporter) Import(path string) (*types.Package, error) { return i.ui, nil }
|
||||
func TestStoredValuesAndGoroutineCaptures(t *testing.T) {
|
||||
ui := types.NewPackage(uiPath, "ui")
|
||||
for _, name := range []string{"Element", "Context", "Handle", "Services"} {
|
||||
obj := types.NewTypeName(token.NoPos, ui, name, nil)
|
||||
types.NewNamed(obj, types.NewStruct(nil, nil), nil)
|
||||
ui.Scope().Insert(obj)
|
||||
}
|
||||
ui.Scope().Insert(types.NewFunc(token.NoPos, ui, "Box", types.NewSignatureType(nil, nil, nil, types.NewTuple(types.NewVar(token.NoPos, ui, "c", types.NewPointer(ui.Scope().Lookup("Context").Type()))), types.NewTuple(types.NewVar(token.NoPos, ui, "", ui.Scope().Lookup("Element").Type())), false)))
|
||||
ui.MarkComplete()
|
||||
fs := token.NewFileSet()
|
||||
f, err := parser.ParseFile(fs, "app.go", `package app
|
||||
import native "github.com/egoist/mygo/ui"
|
||||
type E = native.Element
|
||||
type app struct { bad E; context *native.Context; safe native.Handle; services native.Services; view func(*native.Context) }
|
||||
var saved native.Element
|
||||
func view(c *native.Context){
|
||||
e:=native.Box(c)
|
||||
go func(){ _=e; _=c }()
|
||||
go func(e native.Element){}(e)
|
||||
var h native.Handle
|
||||
go func(){_=h}()
|
||||
}
|
||||
`, 0)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
info := &types.Info{Defs: map[*ast.Ident]types.Object{}, Uses: map[*ast.Ident]types.Object{}, Types: map[ast.Expr]types.TypeAndValue{}}
|
||||
pkg, err := (&types.Config{Importer: testImporter{ui}}).Check("example/app", fs, []*ast.File{f}, info)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
diagnostics := Analyze(fs, []*ast.File{f}, pkg, info)
|
||||
if len(diagnostics) != 6 {
|
||||
t.Fatalf("got %d: %#v", len(diagnostics), diagnostics)
|
||||
}
|
||||
for _, d := range diagnostics {
|
||||
if strings.Contains(d.Message, "safe") || strings.Contains(d.Message, "services") {
|
||||
t.Fatal(d)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user