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

+468
View File
@@ -0,0 +1,468 @@
// Command gen writes the messages of spec.go for the three sides: Go
// (../msgs.go), Swift (the iOS host's Wire.swift) and Kotlin (the Android
// host's Wire.kt).
package main
import (
"bytes"
"fmt"
"go/format"
"log"
"os"
"path/filepath"
"strings"
"unicode"
)
// Paths from internal/mobile/wire, where go generate runs.
const (
goOut = "msgs.go"
swiftOut = "../ios/Sources/MyGoHost/Wire.swift"
kotlinOut = "../android/mygo/src/main/java/dev/mygo/Wire.kt"
)
func main() {
out := map[string][]byte{goOut: goSource(), swiftOut: swiftSource(), kotlinOut: kotlinSource()}
for path, b := range out {
if err := os.MkdirAll(filepath.Dir(path), 0o755); err != nil {
log.Fatal(err)
}
if err := os.WriteFile(path, b, 0o644); err != nil {
log.Fatal(err)
}
}
}
// lower makes a Go name the Swift and Kotlin one: ID → id, URLs → urls,
// SafeTop → safeTop, HTMLText → htmlText, BaseURL → baseURL.
func lower(s string) string {
r := []rune(s)
i := 0
for i < len(r) && unicode.IsUpper(r[i]) {
i++
}
switch {
case i == len(r) || string(r[i:]) == "s":
return strings.ToLower(s)
case i > 1:
i-- // the last capital starts the next word
}
return strings.ToLower(string(r[:i])) + string(r[i:])
}
const header = "Code generated by internal/mobile/wire/gen from spec.go; DO NOT EDIT."
// ---- Go
var goTypes = map[string]string{"int": "int", "float": "float64", "bool": "bool", "string": "string", "bytes": "[]byte", "strings": "[]string", "floats": "[]float64"}
var goRW = map[string]string{"int": "Int", "float": "Float", "bool": "Bool", "string": "String", "bytes": "Bytes", "strings": "Strings", "floats": "Floats"}
func goSource() []byte {
var b bytes.Buffer
fmt.Fprintf(&b, "// %s\n\npackage wire\n\n", header)
b.WriteString("// Numbers of calls.\nconst (\n")
for i, m := range calls {
fmt.Fprintf(&b, "\tCall%s = %d\n", m.name, i+1)
}
b.WriteString(")\n\n// Numbers of events.\nconst (\n")
for i, m := range events {
fmt.Fprintf(&b, "\tEvent%s = %d\n", m.name, i+1)
}
b.WriteString(")\n\n")
goStruct := func(name, doc string, fs []field) {
if doc != "" {
fmt.Fprintf(&b, "// %s is %s.\n", name, doc)
}
fmt.Fprintf(&b, "type %s struct {\n", name)
for _, f := range fs {
fmt.Fprintf(&b, "\t%s %s\n", f.name, goTypes[f.typ])
}
b.WriteString("}\n\n")
}
enc := func(recv string, op string, fs []field) {
fmt.Fprintf(&b, "func (m *%s) Encode(w *Writer) {\n", recv)
if op != "" {
fmt.Fprintf(&b, "\tw.Uvarint(%s)\n", op)
}
for _, f := range fs {
fmt.Fprintf(&b, "\tw.%s(m.%s)\n", goRW[f.typ], f.name)
}
b.WriteString("}\n\n")
}
dec := func(recv string, fs []field) {
fmt.Fprintf(&b, "func (m *%s) Decode(r *Reader) {\n", recv)
for _, f := range fs {
fmt.Fprintf(&b, "\tm.%s = r.%s()\n", f.name, goRW[f.typ])
}
b.WriteString("}\n\n")
}
for _, m := range calls {
goStruct(m.name, m.doc, m.args)
enc(m.name, "Call"+m.name, m.args)
fmt.Fprintf(&b, "// Wait reports whether the caller waits for the host to run it.\nfunc (*%s) Wait() bool { return %v }\n\n", m.name, m.wait)
if m.wait {
goStruct(m.name+"Reply", "", m.reply)
dec(m.name+"Reply", m.reply)
}
}
for _, m := range events {
goStruct(m.name+"Event", m.doc, m.args)
dec(m.name+"Event", m.args)
if m.wait {
goStruct(m.name+"Reply", "", m.reply)
enc(m.name+"Reply", "", m.reply)
}
}
b.WriteString("// EventWaits reports whether the host waits for the reply of event op.\nfunc EventWaits(op uint64) bool {\n\tswitch op {\n\tcase ")
var waits []string
for _, m := range events {
if m.wait {
waits = append(waits, "Event"+m.name)
}
}
b.WriteString(strings.Join(waits, ", "))
b.WriteString(":\n\t\treturn true\n\t}\n\treturn false\n}\n")
src, err := format.Source(b.Bytes())
if err != nil {
log.Fatalf("%v\n%s", err, b.Bytes())
}
return src
}
// ---- Swift
var swiftTypes = map[string]string{"int": "Int", "float": "Double", "bool": "Bool", "string": "String", "bytes": "[UInt8]", "strings": "[String]", "floats": "[Double]"}
var swiftZero = map[string]string{"int": "0", "float": "0", "bool": "false", "string": `""`, "bytes": "[]", "strings": "[]", "floats": "[]"}
const swiftCodec = `
/// Writes the values of a message, as package wire encodes them.
public struct WireWriter {
public var buf: [UInt8] = []
public init() {}
mutating func uvarint(_ v: UInt64) {
var v = v
while v >= 0x80 { buf.append(UInt8(v & 0x7f) | 0x80); v >>= 7 }
buf.append(UInt8(v))
}
mutating func int(_ v: Int) { uvarint(UInt64(bitPattern: Int64((v << 1) ^ (v >> 63)))) }
mutating func bool(_ v: Bool) { buf.append(v ? 1 : 0) }
mutating func float(_ v: Double) { withUnsafeBytes(of: v.bitPattern.littleEndian) { buf.append(contentsOf: $0) } }
mutating func string(_ v: String) { let u = Array(v.utf8); uvarint(UInt64(u.count)); buf.append(contentsOf: u) }
mutating func bytes(_ v: [UInt8]) { uvarint(UInt64(v.count)); buf.append(contentsOf: v) }
mutating func strings(_ v: [String]) { uvarint(UInt64(v.count)); for s in v { string(s) } }
mutating func floats(_ v: [Double]) { uvarint(UInt64(v.count)); for f in v { float(f) } }
}
/// Reads the values of a message; past its end they read as zero.
public struct WireReader {
let buf: UnsafeRawBufferPointer
var at = 0
public init(_ buf: UnsafeRawBufferPointer) { self.buf = buf }
mutating func uvarint() -> UInt64 {
var v: UInt64 = 0, shift: UInt64 = 0
while at < buf.count {
let c = buf[at]; at += 1
v |= UInt64(c & 0x7f) << shift
if c < 0x80 { return v }
shift += 7
}
return 0
}
mutating func int() -> Int { let u = uvarint(); return Int(Int64(bitPattern: (u >> 1) ^ (0 &- (u & 1)))) }
mutating func bool() -> Bool { guard at < buf.count else { return false }; at += 1; return buf[at - 1] != 0 }
mutating func float() -> Double {
guard at + 8 <= buf.count else { at = buf.count; return 0 }
var bits: UInt64 = 0
for i in 0..<8 { bits |= UInt64(buf[at + i]) << (8 * UInt64(i)) }
at += 8
return Double(bitPattern: bits)
}
mutating func bytes() -> [UInt8] {
let n = Int(uvarint())
guard n >= 0, at + n <= buf.count else { at = buf.count; return [] }
defer { at += n }
return Array(buf[at..<at + n])
}
mutating func string() -> String { String(decoding: bytes(), as: UTF8.self) }
mutating func strings() -> [String] {
let n = Int(uvarint())
var s: [String] = []
for _ in 0..<min(n, buf.count - at) { s.append(string()) }
return s
}
mutating func floats() -> [Double] {
let n = Int(uvarint())
var f: [Double] = []
for _ in 0..<min(n, (buf.count - at) / 8) { f.append(float()) }
return f
}
}
`
func swiftSource() []byte {
var b bytes.Buffer
fmt.Fprintf(&b, "// %s\n\n// swiftlint:disable all\n", header)
b.WriteString(swiftCodec)
str := func(name string, fs []field, decode, encode bool) {
fmt.Fprintf(&b, "\npublic struct %s {\n", name)
for _, f := range fs {
fmt.Fprintf(&b, " public var %s: %s = %s\n", lower(f.name), swiftTypes[f.typ], swiftZero[f.typ])
}
b.WriteString(" public init() {}\n")
if decode {
b.WriteString(" init(_ r: inout WireReader) {\n")
for _, f := range fs {
fmt.Fprintf(&b, " %s = r.%s()\n", lower(f.name), f.typ)
}
b.WriteString(" }\n")
}
if encode {
b.WriteString(" func encode(_ w: inout WireWriter) {\n")
for _, f := range fs {
fmt.Fprintf(&b, " w.%s(%s)\n", f.typ, lower(f.name))
}
b.WriteString(" }\n")
}
b.WriteString("}\n")
}
// Calls: the host decodes them and encodes their replies.
for _, m := range calls {
if len(m.args) > 0 {
str(m.name+"Call", m.args, true, false)
}
if m.wait {
str(m.name+"Reply", m.reply, false, true)
}
}
b.WriteString("\n/// The calls Go makes of the host, on the main thread.\npublic protocol HostCalls: AnyObject {\n")
for _, m := range calls {
sig := "func " + lower(m.name) + "("
if len(m.args) > 0 {
sig += "_ c: " + m.name + "Call"
}
sig += ")"
if m.wait {
sig += " -> " + m.name + "Reply"
}
if m.doc != "" {
fmt.Fprintf(&b, " /// %s\n", m.doc)
}
fmt.Fprintf(&b, " %s\n", sig)
}
b.WriteString("}\n\n/// Runs a call on h and encodes its reply, nil for a call not waited for.\npublic func dispatchCall(_ h: HostCalls, _ buf: UnsafeRawBufferPointer) -> [UInt8]? {\n var r = WireReader(buf)\n var w = WireWriter()\n switch r.uvarint() {\n")
for i, m := range calls {
fmt.Fprintf(&b, " case %d:\n", i+1)
arg := ""
if len(m.args) > 0 {
arg = m.name + "Call(&r)"
}
if m.wait {
fmt.Fprintf(&b, " h.%s(%s).encode(&w)\n return w.buf\n", lower(m.name), arg)
} else {
fmt.Fprintf(&b, " h.%s(%s)\n return nil\n", lower(m.name), arg)
}
}
b.WriteString(" default:\n return nil\n }\n}\n")
// Events: the host encodes them and decodes their replies.
b.WriteString("\n/// Encodes the events the host sends Go.\npublic enum Event {\n")
for i, m := range events {
if m.doc != "" {
fmt.Fprintf(&b, " /// %s\n", m.doc)
}
var params []string
for _, f := range m.args {
params = append(params, lower(f.name)+": "+swiftTypes[f.typ])
}
fmt.Fprintf(&b, " public static func %s(%s) -> [UInt8] {\n var w = WireWriter()\n w.uvarint(%d)\n", lower(m.name), strings.Join(params, ", "), i+1)
for _, f := range m.args {
fmt.Fprintf(&b, " w.%s(%s)\n", f.typ, lower(f.name))
}
b.WriteString(" return w.buf\n }\n")
}
b.WriteString("}\n")
for _, m := range events {
if m.wait {
str(m.name+"Reply", m.reply, true, false)
}
}
return b.Bytes()
}
// ---- Kotlin
var kotlinTypes = map[string]string{"int": "Long", "float": "Double", "bool": "Boolean", "string": "String", "bytes": "ByteArray", "strings": "List<String>", "floats": "DoubleArray"}
var kotlinZero = map[string]string{"int": "0L", "float": "0.0", "bool": "false", "string": `""`, "bytes": "ByteArray(0)", "strings": "emptyList()", "floats": "DoubleArray(0)"}
const kotlinCodec = `
/** Writes the values of a message, as package wire encodes them. */
class WireWriter {
private var buf = ByteArray(64)
var size = 0
private set
private fun room(n: Int) {
if (size + n > buf.size) buf = buf.copyOf(maxOf(buf.size * 2, size + n))
}
fun uvarint(v: Long) {
room(10)
var x = v
while (x and 0x7fL.inv() != 0L) {
buf[size++] = ((x and 0x7f) or 0x80).toByte()
x = x ushr 7
}
buf[size++] = x.toByte()
}
fun int(v: Long) = uvarint((v shl 1) xor (v shr 63))
fun bool(v: Boolean) { room(1); buf[size++] = if (v) 1 else 0 }
fun float(v: Double) {
room(8)
val bits = java.lang.Double.doubleToRawLongBits(v)
for (i in 0 until 8) buf[size++] = (bits ushr (8 * i)).toByte()
}
fun bytes(v: ByteArray) { uvarint(v.size.toLong()); room(v.size); v.copyInto(buf, size); size += v.size }
fun string(v: String) = bytes(v.toByteArray(Charsets.UTF_8))
fun strings(v: List<String>) { uvarint(v.size.toLong()); for (s in v) string(s) }
fun floats(v: DoubleArray) { uvarint(v.size.toLong()); for (f in v) float(f) }
fun toByteArray(): ByteArray = buf.copyOf(size)
}
/** Reads the values of a message; past its end they read as zero. */
class WireReader(private val buf: ByteArray) {
private var at = 0
/** Whether all of the message was read. */
fun done() = at >= buf.size
fun uvarint(): Long {
var v = 0L
var shift = 0
while (at < buf.size) {
val c = buf[at++].toInt() and 0xff
v = v or ((c and 0x7f).toLong() shl shift)
if (c < 0x80) return v
shift += 7
}
return 0
}
fun int(): Long { val u = uvarint(); return (u ushr 1) xor -(u and 1) }
fun bool(): Boolean = if (at < buf.size) buf[at++].toInt() != 0 else false
fun float(): Double {
if (at + 8 > buf.size) { at = buf.size; return 0.0 }
var bits = 0L
for (i in 0 until 8) bits = bits or ((buf[at + i].toLong() and 0xff) shl (8 * i))
at += 8
return java.lang.Double.longBitsToDouble(bits)
}
fun bytes(): ByteArray {
val n = uvarint().toInt()
if (n < 0 || at + n > buf.size) { at = buf.size; return ByteArray(0) }
val b = buf.copyOfRange(at, at + n)
at += n
return b
}
fun string(): String = String(bytes(), Charsets.UTF_8)
fun strings(): List<String> {
val n = uvarint().toInt()
val s = ArrayList<String>(minOf(n, buf.size - at).coerceAtLeast(0))
for (i in 0 until minOf(n, buf.size - at)) s.add(string())
return s
}
fun floats(): DoubleArray {
val n = minOf(uvarint().toInt(), (buf.size - at) / 8).coerceAtLeast(0)
return DoubleArray(n) { float() }
}
}
`
func kotlinSource() []byte {
var b bytes.Buffer
fmt.Fprintf(&b, "// %s\n\n@file:Suppress(\"unused\", \"MemberVisibilityCanBePrivate\")\n\npackage dev.mygo\n", header)
b.WriteString(kotlinCodec)
class := func(name string, fs []field, decode, encode bool) {
fmt.Fprintf(&b, "\nclass %s(", name)
var ps []string
for _, f := range fs {
ps = append(ps, fmt.Sprintf("\n @JvmField var %s: %s = %s", lower(f.name), kotlinTypes[f.typ], kotlinZero[f.typ]))
}
b.WriteString(strings.Join(ps, ","))
if len(fs) > 0 {
b.WriteString(",\n")
}
b.WriteString(") {\n")
if decode {
b.WriteString(" constructor(r: WireReader) : this() {\n")
for _, f := range fs {
fmt.Fprintf(&b, " %s = r.%s()\n", lower(f.name), f.typ)
}
b.WriteString(" }\n")
}
if encode {
b.WriteString(" fun encode(w: WireWriter) {\n")
for _, f := range fs {
fmt.Fprintf(&b, " w.%s(%s)\n", f.typ, lower(f.name))
}
b.WriteString(" }\n")
}
b.WriteString("}\n")
}
for _, m := range calls {
if len(m.args) > 0 {
class(m.name+"Call", m.args, true, false)
}
if m.wait {
class(m.name+"Reply", m.reply, false, true)
}
}
b.WriteString("\n/** The calls Go makes of the host, on the UI thread. */\ninterface HostCalls {\n")
for _, m := range calls {
sig := "fun " + lower(m.name) + "("
if len(m.args) > 0 {
sig += "c: " + m.name + "Call"
}
sig += ")"
if m.wait {
sig += ": " + m.name + "Reply"
}
if m.doc != "" {
fmt.Fprintf(&b, " /** %s */\n", m.doc)
}
fmt.Fprintf(&b, " %s\n", sig)
}
b.WriteString("}\n\n/** Runs a call on h and encodes its reply, null for a call not waited for. */\nfun dispatchCall(h: HostCalls, buf: ByteArray): ByteArray? {\n val r = WireReader(buf)\n val w = WireWriter()\n when (r.uvarint().toInt()) {\n")
for i, m := range calls {
arg := ""
if len(m.args) > 0 {
arg = m.name + "Call(r)"
}
if m.wait {
fmt.Fprintf(&b, " %d -> { h.%s(%s).encode(w); return w.toByteArray() }\n", i+1, lower(m.name), arg)
} else {
fmt.Fprintf(&b, " %d -> h.%s(%s)\n", i+1, lower(m.name), arg)
}
}
b.WriteString(" }\n return null\n}\n\n/** Encodes the events the host sends Go. */\nobject Event {\n")
for i, m := range events {
if m.doc != "" {
fmt.Fprintf(&b, " /** %s */\n", m.doc)
}
var ps []string
for _, f := range m.args {
ps = append(ps, lower(f.name)+": "+kotlinTypes[f.typ])
}
fmt.Fprintf(&b, " @JvmStatic fun %s(%s): ByteArray {\n val w = WireWriter()\n w.uvarint(%d)\n", lower(m.name), strings.Join(ps, ", "), i+1)
for _, f := range m.args {
fmt.Fprintf(&b, " w.%s(%s)\n", f.typ, lower(f.name))
}
b.WriteString(" return w.toByteArray()\n }\n")
}
b.WriteString("}\n")
for _, m := range events {
if m.wait {
class(m.name+"Reply", m.reply, true, false)
}
}
return b.Bytes()
}
+30
View File
@@ -0,0 +1,30 @@
package main
import (
"bytes"
"os"
"path/filepath"
"testing"
)
// The generated files are what the spec makes: run go generate in
// internal/mobile/wire after changing it.
func TestUpToDate(t *testing.T) {
for path, want := range map[string][]byte{goOut: goSource(), swiftOut: swiftSource(), kotlinOut: kotlinSource()} {
got, err := os.ReadFile(filepath.Join("..", path))
if err != nil {
t.Fatal(err)
}
if !bytes.Equal(got, want) {
t.Errorf("%s is out of date: run go generate ./internal/mobile/wire", path)
}
}
}
func TestLower(t *testing.T) {
for in, want := range map[string]string{"ID": "id", "URLs": "urls", "SafeTop": "safeTop", "HTMLText": "htmlText", "BaseURL": "baseURL", "PNG": "png"} {
if got := lower(in); got != want {
t.Errorf("lower(%q) = %q, want %q", in, got, want)
}
}
}
+272
View File
@@ -0,0 +1,272 @@
package main
// field is a field of a message: its name, in Go's form, and its type:
// int, float, bool, string, bytes or strings.
type field struct{ name, typ string }
// msg is a message. A call goes from Go to the host, which runs it on the
// UI thread; an event from the host to Go, which handles it on its main
// thread. reply lists what the receiver answers: a message without one
// is not waited for (wait false), so that a call or an event costs its
// sender nothing; one with wait set is, even with no fields to answer.
type msg struct {
name string
doc string
args []field
reply []field
wait bool
}
func f(name, typ string) field { return field{name, typ} }
// calls go from Go to the host.
var calls = []msg{
{name: "AppInfo", doc: "the app's bundle and the system's settings, asked once at start", wait: true, reply: []field{
f("Name", "string"), f("Version", "string"), f("Identifier", "string"),
f("FilesDir", "string"), f("CacheDir", "string"), f("TempDir", "string"), f("DocumentsDir", "string"),
f("ResourcesDir", "string"),
f("Languages", "strings"), f("RegionLocale", "string"), f("FirstWeekday", "int"), f("HourCycle", "int"),
f("System", "string"), f("SystemVersion", "string"), f("Model", "string"), f("Restoring", "bool"), f("Background", "bool"),
}},
{name: "TimeZone", doc: "the name of the system's time zone; any thread", wait: true, reply: []field{f("ID", "string")}},
{name: "Theme", doc: "the appearance and the accessibility preferences", wait: true, reply: []field{
f("Dark", "bool"), f("Accent", "int"), f("ReduceMotion", "bool"), f("ReduceTransparency", "bool"),
f("IncreaseContrast", "bool"), f("TextScale", "float"),
}},
{name: "SetAppearance", doc: `the appearance the app asks for: "light", "dark" or "system"`, args: []field{f("Source", "string")}},
{name: "Screen", doc: "the screen's size in DIPs and scale", wait: true, reply: []field{
f("Width", "float"), f("Height", "float"), f("Scale", "float"),
}},
{name: "Log", doc: "a line the app wrote to its standard output or error", args: []field{f("Error", "bool"), f("Line", "string")}},
{name: "CreateWindow", doc: "the screen's content: a web view, or a surface for native UI", wait: true,
args: []field{
f("ID", "int"), f("Surface", "bool"), f("OwnScene", "bool"), f("Background", "int"), f("HasBackground", "bool"),
f("Schemes", "strings"), f("Scripts", "strings"), f("ScriptFlags", "strings"),
f("UserAgent", "string"), f("UserAgentSuffix", "string"), f("Inspectable", "bool"),
f("Autoplay", "bool"), f("SwipeNavigation", "bool"), f("PinchZoom", "bool"),
f("Parent", "int"), f("ViewType", "string"), f("ViewArgs", "string"),
},
reply: []field{f("Error", "string"), f("Layer", "int")}},
{name: "FirstFrame", doc: "the window's content presented its first frame", args: []field{f("ID", "int")}},
{name: "PlaceViews", doc: "where a surface shows the windows it holds (Parent), under it, in the order painted; the others hide. Places: encoded by Go (encodePlaces)",
args: []field{f("ID", "int"), f("Places", "bytes")}},
{name: "ShowWindow", args: []field{f("ID", "int")}},
{name: "HideWindow", args: []field{f("ID", "int")}},
{name: "CloseWindow", args: []field{f("ID", "int")}},
{name: "SetBackground", args: []field{f("ID", "int"), f("Color", "int")}},
{name: "Focus", args: []field{f("ID", "int")}},
{name: "SetTitle", doc: "the window's title, which a navigation bar shows", args: []field{f("ID", "int"), f("Title", "string")}},
{name: "CreateTabs", doc: "a bar of tabs, whose tabs AddTab adds before ShowTabs shows it", args: []field{f("ID", "int")}},
{name: "AddTab", args: []field{f("ID", "int"), f("Window", "int"), f("Title", "string"), f("Symbol", "string"), f("Icon", "bytes")}},
{name: "ShowTabs", args: []field{f("ID", "int")}},
{name: "SelectTab", args: []field{f("ID", "int"), f("Index", "int")}},
{name: "SetTabBadge", args: []field{f("ID", "int"), f("Index", "int"), f("Badge", "string")}},
{name: "CloseTabs", args: []field{f("ID", "int")}},
{name: "PushWindow", doc: "shows Child over Parent in Parent's stack, under a bar with its Title and a back button",
args: []field{f("Parent", "int"), f("Child", "int"), f("Title", "string"), f("Animated", "bool")}},
{name: "PopWindow", args: []field{f("ID", "int"), f("Animated", "bool")}},
{name: "SetStack", doc: "a router's pages as the window's stack of screens, its first page and those deeper (Titles, told apart by Keys): the screens of the keys the stack shows stay, the others are pushed, popped or replaced; none take the stack away. Answered once the screen going out of sight holds what the surface shows, as the surface is about to show the page coming",
wait: true, args: []field{f("ID", "int"), f("Titles", "strings"), f("Keys", "strings")}},
{name: "StackShown", doc: "the surface shows the page of the stack's last screen, after SetStack or StackPopped", args: []field{f("ID", "int")}},
{name: "LoadURL", args: []field{f("ID", "int"), f("URL", "string")}},
{name: "LoadHTML", args: []field{f("ID", "int"), f("HTML", "string"), f("BaseURL", "string")}},
{name: "Reload", args: []field{f("ID", "int"), f("IgnoreCache", "bool")}},
{name: "StopLoading", args: []field{f("ID", "int")}},
{name: "GoBack", args: []field{f("ID", "int")}},
{name: "GoForward", args: []field{f("ID", "int")}},
{name: "Eval", args: []field{f("ID", "int"), f("JS", "string")}},
{name: "CallAsync", doc: "runs Body as an async function's; AsyncResult answers", args: []field{f("ID", "int"), f("Req", "int"), f("Body", "string")}},
{name: "SetZoom", args: []field{f("ID", "int"), f("Factor", "float")}},
{name: "SetUserAgent", args: []field{f("ID", "int"), f("UserAgent", "string")}},
{name: "SetUserScripts", args: []field{f("ID", "int"), f("Scripts", "strings"), f("ScriptFlags", "strings")}},
{name: "CapturePage", doc: "a PNG of the page; Captured answers", args: []field{f("ID", "int"), f("Req", "int")}},
{name: "UserAgent", wait: true, args: []field{f("ID", "int")}, reply: []field{f("UserAgent", "string")}},
{name: "SchemeRespond", doc: "the status and headers of a SchemeRequest (Header: names and values in turn)",
args: []field{f("Req", "int"), f("Status", "int"), f("Header", "strings")}},
{name: "SchemeData", args: []field{f("Req", "int"), f("Data", "bytes")}},
{name: "SchemeFinish", args: []field{f("Req", "int")}},
{name: "SchemeFail", args: []field{f("Req", "int"), f("Message", "string")}},
{name: "MessageBox", doc: "an alert; MessageBoxResult answers",
args: []field{f("Req", "int"), f("Type", "string"), f("Title", "string"), f("Message", "string"),
f("Detail", "string"), f("Buttons", "strings"), f("DefaultID", "int"), f("CancelID", "int")}},
{name: "OpenFiles", doc: "the system's picker of documents; FilesResult answers with copies the app may read",
args: []field{f("Req", "int"), f("Multiple", "bool"), f("Directories", "bool"), f("Extensions", "strings")}},
{name: "ShareFile", doc: "the share sheet of a file, as the place to save it", args: []field{f("Path", "string")}},
{name: "ClipboardText", wait: true, reply: []field{f("Text", "string"), f("OK", "bool")}},
{name: "SetClipboardText", args: []field{f("Text", "string")}},
{name: "OpenURL", doc: "opens a URL in the app the system has for it", wait: true, args: []field{f("URL", "string")}, reply: []field{f("OK", "bool")}},
{name: "SecretGet", wait: true, args: []field{f("Service", "string"), f("Account", "string")},
reply: []field{f("Value", "bytes"), f("Found", "bool"), f("Error", "string")}},
{name: "SecretSet", wait: true, args: []field{f("Service", "string"), f("Account", "string"), f("Value", "bytes")},
reply: []field{f("Error", "string")}},
{name: "SecretDelete", wait: true, args: []field{f("Service", "string"), f("Account", "string")},
reply: []field{f("Error", "string")}},
{name: "Notify", doc: "a local notification; NotifyDone answers once the system has it",
args: []field{f("Req", "int"), f("NotificationID", "string"), f("Title", "string"), f("Subtitle", "string"),
f("Body", "string"), f("Group", "string"), f("Silent", "bool")}},
{name: "RemoveNotification", args: []field{f("NotificationID", "string")}},
{name: "RemoveAllNotifications"},
{name: "KeepAwake", doc: "keeps the screen on while the app shows", args: []field{f("On", "bool")}},
{name: "NetworkStatus", wait: true, reply: []field{f("Online", "bool"), f("Metered", "bool")}},
{name: "WatchNetwork", doc: "starts NetworkChanged"},
{name: "Battery", wait: true, reply: []field{f("Level", "float"), f("Charging", "bool"), f("LowPower", "bool")}},
{name: "SetSystemBars", doc: `the icons of the system's bars ("auto", "light" or "dark"), and whether the bars hide`,
args: []field{f("Style", "string"), f("Hidden", "bool")}},
{name: "SetOrientations", doc: "the orientations the screen may take: 1 portrait, 2 upside down, 4 landscape left, 8 landscape right; 0 any",
args: []field{f("Mask", "int")}},
{name: "Share", doc: "the share sheet of text, a link and files; ShareResult answers", args: []field{f("Req", "int"), f("Text", "string"),
f("URL", "string"), f("Paths", "strings"), f("X", "float"), f("Y", "float")}},
{name: "SaveFile", doc: "the system's picker of where to keep a copy of Path under Name; FilesResult answers with the place, empty when dismissed",
args: []field{f("Req", "int"), f("Path", "string"), f("Name", "string")}},
{name: "ClipboardImage", wait: true, reply: []field{f("PNG", "bytes")}},
{name: "SetClipboardImage", args: []field{f("PNG", "bytes")}},
{name: "PopupMenu", doc: "the system's menu at a point of the window: Items are encoded by Go (encodeMenu); MenuPicked answers with the item's ID, 0 when dismissed",
args: []field{f("ID", "int"), f("Req", "int"), f("X", "float"), f("Y", "float"), f("Items", "bytes")}},
{name: "SetBarItems", doc: "the buttons at the end of the window's navigation bar; BarItemClicked tells which: titles, symbols and icons by index",
args: []field{f("ID", "int"), f("Titles", "strings"), f("Symbols", "strings"), f("Icons", "strings")}},
{name: "PluginCall", doc: "a call of a plugin's native code: Args and PluginResult's Result are JSON", args: []field{f("Req", "int"),
f("Plugin", "string"), f("Method", "string"), f("Args", "string")}},
{name: "AudioOpen", doc: "opens the sound's output: stereo at Rate frames a second, holding about Ahead milliseconds; on the caller's thread", wait: true,
args: []field{f("Rate", "int"), f("Ahead", "int")}, reply: []field{f("Error", "string")}},
{name: "AudioWrite", doc: "plays interleaved stereo float32 samples after those written, waiting while the output holds enough; on the caller's thread", wait: true,
args: []field{f("Samples", "bytes")}, reply: []field{f("Error", "string")}},
{name: "AudioClose", wait: true},
{name: "Haptic", doc: `"selection", "light", "medium", "heavy", "success", "warning" or "error"`, args: []field{f("Kind", "string")}},
// Native UI.
{name: "RequestFrame", doc: "asks for a Frame at the next refresh of the display", args: []field{f("ID", "int")}},
{name: "SetTextInput", doc: "whether the keyboard shows and what for: the input's traits (platform.TextTraits), and its text. Show counts the requests to show the keyboard again. Offsets are UTF-16 units of the document, of which Text is the part around the selection, from Base; MarkStart is -1 without marked text. A window without Document takes text without one, as a terminal: the keyboard sees none",
args: []field{f("ID", "int"), f("Active", "bool"), f("Show", "int"), f("Serial", "int"), f("X", "float"), f("Y", "float"), f("Width", "float"), f("Height", "float"),
f("Document", "bool"), f("Multiline", "bool"), f("Secure", "bool"), f("Keyboard", "string"), f("ReturnKey", "string"),
f("Capitalize", "string"), f("Autocorrect", "string"), f("Autofill", "string"),
f("Text", "string"), f("Base", "int"), f("Length", "int"), f("SelStart", "int"), f("SelEnd", "int"), f("MarkStart", "int"), f("MarkEnd", "int")}},
{name: "SetCursor", doc: "the pointer's shape, for a mouse or a trackpad", args: []field{f("ID", "int"), f("Cursor", "string")}},
{name: "AccessibilityChanged", doc: "the tree of accessible elements changed; Focus names the one with the focus",
args: []field{f("ID", "int"), f("Focus", "int")}},
{name: "Announce", args: []field{f("Text", "string")}},
{name: "ShowMenu", doc: "the system's edit menu at a point, with the actions given (cut, copy, paste, selectAll); TextCommand answers",
args: []field{f("ID", "int"), f("X", "float"), f("Y", "float"), f("Actions", "strings")}},
{name: "SetBackAvailable", doc: "whether the content takes the system's back", args: []field{f("ID", "int"), f("On", "bool")}},
{name: "ShowMagnifier", doc: "the system's magnifier of what is at a point", args: []field{f("ID", "int"), f("X", "float"), f("Y", "float")}},
{name: "HideMagnifier", args: []field{f("ID", "int")}},
{name: "TextMetrics", doc: "the metrics of a font (Android's Paint): ascent and descent, x-height, underline and strikethrough", wait: true,
args: []field{f("Family", "string"), f("Size", "float"), f("Weight", "int"), f("Italic", "bool")},
reply: []field{f("Ascent", "float"), f("Descent", "float"), f("XHeight", "float"), f("UnderlinePosition", "float"),
f("UnderlineThickness", "float"), f("StrikePosition", "float")}},
{name: "MeasureText", doc: "how wide each of Texts is in a font, kerned unless NoKern", wait: true,
args: []field{f("Family", "string"), f("Size", "float"), f("Weight", "int"), f("Italic", "bool"), f("NoKern", "bool"),
f("Texts", "strings")},
reply: []field{f("Widths", "floats")}},
{name: "TextAdvances", doc: "the advance of each UTF-16 unit of Text laid out as a whole (getTextRunAdvances)", wait: true,
args: []field{f("Family", "string"), f("Size", "float"), f("Weight", "int"), f("Italic", "bool"), f("NoKern", "bool"),
f("Text", "string"), f("RTL", "bool")},
reply: []field{f("Advances", "floats")}},
{name: "DrawText", doc: "draws Text in white at Scale pixels per DIP, its pen DX pixels right of a pixel's edge: its ink's box from the pen and its pixels, a byte of coverage each, or premultiplied RGBA when Color", wait: true,
args: []field{f("Family", "string"), f("Size", "float"), f("Weight", "int"), f("Italic", "bool"), f("Text", "string"),
f("Scale", "float"), f("DX", "float")},
reply: []field{f("Left", "int"), f("Top", "int"), f("Width", "int"), f("Height", "int"), f("Color", "bool"), f("Pixels", "bytes")}},
{name: "RegisterFont", doc: "adds a font file under Family, or its own family when empty", wait: true,
args: []field{f("Data", "bytes"), f("Family", "string")}, reply: []field{f("Family", "string"), f("Error", "string")}},
}
// events go from the host to Go.
var events = []msg{
{name: "Ready", doc: "the app finished launching"},
{name: "Active", doc: "the app is in front, or no longer", args: []field{f("Active", "bool")}},
{name: "Background", doc: "the app goes to the background (true) or came back. The host waits: iOS ends apps that use the GPU in the background, so that frames stop before it returns", wait: true, args: []field{f("Background", "bool")}},
{name: "ThemeChanged"},
{name: "LocaleChanged"},
{name: "TimeZoneChanged", args: []field{f("ID", "string")}},
{name: "OpenURLs", args: []field{f("URLs", "strings")}},
{name: "MemoryWarning"},
{name: "Terminating", doc: "the process ends once Go answers", wait: true},
{name: "Resized", doc: "the window's size in DIPs, the scale, and the insets of what covers it: the system's bars, the cutout, the keyboard",
args: []field{f("ID", "int"), f("Width", "float"), f("Height", "float"), f("Scale", "float"),
f("SafeTop", "float"), f("SafeLeft", "float"), f("SafeBottom", "float"), f("SafeRight", "float"), f("Keyboard", "float")}},
{name: "BackGesture", doc: `the system's gesture of going back, as it goes: Phase is "started", "progress" or "cancelled"`,
args: []field{f("ID", "int"), f("Phase", "string"), f("Progress", "float")}},
{name: "StatusBarTapped", doc: "a tap on iOS's status bar"},
{name: "ViewPressed", doc: "a finger went down on a view a surface holds, which takes it", args: []field{f("ID", "int"), f("X", "float"), f("Y", "float")}},
{name: "PluginResult", args: []field{f("Req", "int"), f("Result", "string"), f("Error", "string"), f("Code", "string")}},
{name: "PluginEvent", doc: "an event of a plugin's native code: Data is JSON", args: []field{f("Plugin", "string"), f("Name", "string"), f("Data", "string")}},
{name: "NetworkChanged", args: []field{f("Online", "bool"), f("Metered", "bool")}},
{name: "ShareResult", args: []field{f("Req", "int"), f("Error", "string")}},
{name: "MenuPicked", args: []field{f("Req", "int"), f("Item", "int")}},
{name: "BarItemClicked", args: []field{f("ID", "int"), f("Index", "int")}},
{name: "TabSelected", doc: "the user chose tab Index", args: []field{f("ID", "int"), f("Index", "int")}},
{name: "StackPopped", doc: "the user took screens off a window's stack (SetStack): Depth stay", args: []field{f("ID", "int"), f("Depth", "int")}},
{name: "Popped", doc: "the window left its stack: the back button, a swipe, Android's back, or PopWindow", args: []field{f("ID", "int")}},
{name: "BackPressed", doc: "Android's back: whether the app took it", wait: true, args: []field{f("ID", "int")}, reply: []field{f("Handled", "bool")}},
{name: "Message", doc: "a message the page's bridge posted", args: []field{f("ID", "int"), f("Text", "string")}},
{name: "WillNavigate", wait: true,
args: []field{f("ID", "int"), f("URL", "string"), f("MainFrame", "bool"), f("UserInitiated", "bool"), f("Unasked", "bool"), f("Reload", "bool")},
reply: []field{f("Allow", "bool")}},
{name: "NewWindow", doc: "window.open or a link to _blank: whether the app opened it", wait: true,
args: []field{f("ID", "int"), f("URL", "string"), f("UserInitiated", "bool")}, reply: []field{f("Handled", "bool")}},
{name: "PageState", doc: "what the page is at, after any change of it",
args: []field{f("ID", "int"), f("URL", "string"), f("Title", "string"), f("Loading", "bool"), f("CanGoBack", "bool"), f("CanGoForward", "bool")}},
{name: "NavigationStarted", args: []field{f("ID", "int"), f("URL", "string")}},
{name: "NavigationCommitted", args: []field{f("ID", "int"), f("URL", "string")}},
{name: "LoadFinished", args: []field{f("ID", "int")}},
{name: "LoadFailed", args: []field{f("ID", "int"), f("URL", "string"), f("Code", "int"), f("Description", "string")}},
{name: "ClosedByPage", args: []field{f("ID", "int")}},
{name: "WindowFront", doc: "the user went to a window of its own scene, or (0) to the app's first", args: []field{f("ID", "int")}},
{name: "ProcessGone", args: []field{f("ID", "int"), f("Reason", "string")}},
{name: "PermissionRequested", wait: true, args: []field{f("ID", "int"), f("Kinds", "strings"), f("Origin", "string")}, reply: []field{f("Allow", "bool")}},
{name: "SchemeRequest", doc: "a request of one of the app's schemes (Header: names and values in turn)",
args: []field{f("ID", "int"), f("Req", "int"), f("Method", "string"), f("URL", "string"), f("Header", "strings"),
f("Body", "bytes"), f("HasBody", "bool")}},
{name: "SchemeCancel", args: []field{f("Req", "int")}},
{name: "AsyncResult", args: []field{f("Req", "int"), f("Result", "string"), f("Error", "string")}},
{name: "Captured", args: []field{f("Req", "int"), f("PNG", "bytes"), f("Error", "string")}},
{name: "MessageBoxResult", args: []field{f("Req", "int"), f("Response", "int")}},
{name: "FilesResult", args: []field{f("Req", "int"), f("Paths", "strings"), f("Error", "string")}},
{name: "NotifyDone", args: []field{f("Req", "int"), f("Error", "string")}},
{name: "NotificationClicked", args: []field{f("NotificationID", "string")}},
// Native UI.
{name: "Frame", doc: "the display refreshes: draw a frame if one was asked for", args: []field{f("ID", "int")}},
{name: "SurfaceChanged", doc: "the native surface to draw on (a CAMetalLayer, an ANativeWindow), 0 when gone",
args: []field{f("ID", "int"), f("Handle", "int"), f("Width", "float"), f("Height", "float"), f("Scale", "float"), f("Refresh", "float")}},
{name: "SurfaceDestroyed", doc: "the native surface goes: the host waits for Go to let go of it", wait: true, args: []field{f("ID", "int")}},
{name: "Touch", doc: `a finger, a pen or a mouse: Phase is "down", "move", "up" or "cancel", Kind "touch", "pen" or "mouse"`,
args: []field{f("ID", "int"), f("Pointer", "int"), f("Phase", "string"), f("Kind", "string"), f("X", "float"), f("Y", "float"),
f("Pressure", "float"), f("Buttons", "int"), f("Time", "float")}},
{name: "Scroll", doc: "a mouse's or a trackpad's scrolling, in DIPs", args: []field{f("ID", "int"), f("X", "float"), f("Y", "float"),
f("DX", "float"), f("DY", "float"), f("Precise", "bool"), f("Phase", "string")}},
{name: "Key", doc: "a hardware keyboard's key: Down, its name (as ui names keys) and the text it types",
args: []field{f("ID", "int"), f("Down", "bool"), f("Key", "string"), f("Text", "string"), f("Mods", "int"), f("Repeated", "bool")},
reply: []field{f("Handled", "bool")}, wait: true},
{name: "TextReplace", doc: "the keyboard put Text in Start to End of the document, or with no range in place of the marked text or the selection; answers TextStateReply", wait: true,
args: []field{f("ID", "int"), f("HasRange", "bool"), f("Start", "int"), f("End", "int"), f("Text", "string")}},
{name: "TextMark", doc: "the input method composes Text over Start to End, or with no range over the marked text or the selection; SelStart and SelEnd are in Text; answers TextStateReply", wait: true,
args: []field{f("ID", "int"), f("HasRange", "bool"), f("Start", "int"), f("End", "int"), f("Text", "string"), f("SelStart", "int"), f("SelEnd", "int")}},
{name: "TextUnmark", doc: "the marked text stays as text; answers TextStateReply", wait: true, args: []field{f("ID", "int")}},
{name: "TextDelete", doc: "the keyboard deleted Before units before the selection and After after it; answers TextStateReply", wait: true,
args: []field{f("ID", "int"), f("Before", "int"), f("After", "int")}},
{name: "TextSelect", doc: "the keyboard moved the selection; answers TextStateReply", wait: true, args: []field{f("ID", "int"), f("Start", "int"), f("End", "int")}},
{name: "TextCommand", doc: `an editing action of the keyboard or the edit menu: "newline", "tab", "deleteBackward", "deleteForward", "cut", "copy", "paste", "selectAll", "left", …; answers TextStateReply`, wait: true,
args: []field{f("ID", "int"), f("Command", "string")}},
{name: "TextState", doc: "the text around the selection, and the selection", wait: true,
args: []field{f("ID", "int")}, reply: []field{f("Text", "string"), f("Base", "int"), f("Length", "int"), f("SelStart", "int"), f("SelEnd", "int"),
f("MarkStart", "int"), f("MarkEnd", "int"), f("X", "float"), f("Y", "float"), f("Width", "float"), f("Height", "float")}},
{name: "TextRange", doc: "a part of the document outside the text the host has", wait: true,
args: []field{f("ID", "int"), f("Start", "int"), f("End", "int")}, reply: []field{f("Text", "string"), f("Start", "int"), f("End", "int")}},
{name: "TextBounds", doc: "where the range is on screen: its first line's rectangle", wait: true,
args: []field{f("ID", "int"), f("Start", "int"), f("End", "int")}, reply: []field{f("OK", "bool"), f("X", "float"), f("Y", "float"), f("Width", "float"), f("Height", "float"), f("End", "int")}},
{name: "TextIndexAt", doc: "the offset nearest a point of the window", wait: true,
args: []field{f("ID", "int"), f("X", "float"), f("Y", "float")}, reply: []field{f("OK", "bool"), f("Index", "int")}},
{name: "TextInputEnded", doc: "the keyboard went away", args: []field{f("ID", "int")}},
{name: "AccessibilityTree", doc: "the accessible elements, encoded as Nodes: for each, its ID, parent, role, label, value, hint, frame and actions", wait: true,
args: []field{f("ID", "int")}, reply: []field{f("Nodes", "bytes")}},
{name: "AccessibilityAction", doc: `an assistive technology's action on an element: "press", "increment", "decrement", "focus", "scrollForward", …`, wait: true,
args: []field{f("ID", "int"), f("Node", "int"), f("Action", "string")}, reply: []field{f("Handled", "bool")}},
}