Files
openchamber-android-native/third_party/mygo/ui/diagnostics.go
T
OpenChamber 6c0ee61750 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.
2026-11-18 13:22:59 +08:00

67 lines
1.8 KiB
Go

package ui
import (
"fmt"
"log"
"runtime"
"strconv"
"strings"
)
// maxWarnings is how many warnings the inspector keeps, the latest.
const maxWarnings = 50
// duplicateKey reports an element given the key of another element of
// the pass under the same parent: they have one ID, and so share one
// state, so that the pointer, the focus and scrolling meant for one go to
// the other. A Tester panics (engine.strict), so that tests fail where the
// key was given; apps log it once, and the inspector lists it.
func (rt *engine) duplicateKey(id uint64, k any) {
msg := fmt.Sprintf("ui: two elements under one parent have the key %#v, and share one state: give each a key of its own", k)
if at := callSite(); at != "" {
msg += " (" + at + ")"
}
if rt.strict {
panic(msg)
}
if rt.dupKeys == nil {
rt.dupKeys = map[uint64]bool{}
}
if rt.dupKeys[id] {
return
}
rt.dupKeys[id] = true
log.Print(msg)
rt.warn(msg)
}
// warn notes a warning for the inspector.
func (rt *engine) warn(msg string) {
if len(rt.warnings) == maxWarnings {
copy(rt.warnings, rt.warnings[1:])
rt.warnings = rt.warnings[:maxWarnings-1]
}
rt.warnings = append(rt.warnings, msg)
rt.insp.changed = true
}
// uiPackage prefixes the names of the functions of package ui.
const uiPackage = "github.com/egoist/mygo/ui."
// callSite returns the file and line of the innermost call outside package
// ui on the stack: the app's code that built an element, or "".
func callSite() string {
var pcs [32]uintptr
n := runtime.Callers(2, pcs[:])
frames := runtime.CallersFrames(pcs[:n])
for {
f, more := frames.Next()
if f.Function != "" && !strings.HasPrefix(f.Function, uiPackage) && !strings.HasPrefix(f.Function, "runtime.") && !strings.HasPrefix(f.Function, "testing.") {
return f.File + ":" + strconv.Itoa(f.Line)
}
if !more {
return ""
}
}
}