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
+87
@@ -0,0 +1,87 @@
|
||||
//go:build !android
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
type state struct{}
|
||||
|
||||
func before() state { return state{} }
|
||||
|
||||
// usage counts the app's descendants: WebKitGTK's web and network
|
||||
// processes, and what they run.
|
||||
func usage(pid int, _ state) (app, total uint64, procs []int, err error) {
|
||||
procs = append([]int{pid}, descendants(pid)...)
|
||||
for i, p := range procs {
|
||||
pss, err := pssOf(p)
|
||||
if err != nil {
|
||||
if i == 0 {
|
||||
return 0, 0, nil, err
|
||||
}
|
||||
continue
|
||||
}
|
||||
if i == 0 {
|
||||
app = pss
|
||||
}
|
||||
total += pss
|
||||
}
|
||||
return app, total, procs, nil
|
||||
}
|
||||
|
||||
// pssOf returns the proportional set size of pid: its own pages, and its
|
||||
// share of those it shares.
|
||||
func pssOf(pid int) (uint64, error) {
|
||||
b, err := os.ReadFile(fmt.Sprintf("/proc/%d/smaps_rollup", pid))
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
for line := range strings.SplitSeq(string(b), "\n") {
|
||||
if v, ok := strings.CutPrefix(line, "Pss:"); ok {
|
||||
kb, err := strconv.ParseUint(strings.TrimSpace(strings.TrimSuffix(strings.TrimSpace(v), "kB")), 10, 64)
|
||||
return kb << 10, err
|
||||
}
|
||||
}
|
||||
return 0, fmt.Errorf("no Pss in /proc/%d/smaps_rollup", pid)
|
||||
}
|
||||
|
||||
// descendants returns the processes pid started, and theirs.
|
||||
func descendants(pid int) []int {
|
||||
entries, _ := os.ReadDir("/proc")
|
||||
children := map[int][]int{}
|
||||
for _, e := range entries {
|
||||
p, err := strconv.Atoi(e.Name())
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
b, err := os.ReadFile("/proc/" + e.Name() + "/stat")
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
// pid (comm) state ppid …, where comm may hold anything.
|
||||
f := strings.Fields(string(b[strings.LastIndexByte(string(b), ')')+1:]))
|
||||
if len(f) < 2 {
|
||||
continue
|
||||
}
|
||||
if ppid, err := strconv.Atoi(f[1]); err == nil {
|
||||
children[ppid] = append(children[ppid], p)
|
||||
}
|
||||
}
|
||||
var out []int
|
||||
for queue := children[pid]; len(queue) > 0; queue = queue[1:] {
|
||||
out = append(out, queue[0])
|
||||
queue = append(queue, children[queue[0]]...)
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// stop asks the app to quit, which its WebKit processes follow.
|
||||
func stop(p *os.Process, _ []int) error {
|
||||
p.Signal(syscall.SIGTERM)
|
||||
return nil
|
||||
}
|
||||
Reference in new issue
Block a user