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.
61 lines
2.0 KiB
Go
61 lines
2.0 KiB
Go
package mygo
|
|
|
|
import (
|
|
"os"
|
|
"reflect"
|
|
"sync"
|
|
"sync/atomic"
|
|
)
|
|
|
|
// fileStatFields are the indices of the fields of os.fileStat that
|
|
// os.SameFile compares (os/types_windows.go), found once; ok is false
|
|
// when they aren't there as expected.
|
|
var fileStatFields struct {
|
|
// typ is the os package's fileStat, once seen.
|
|
typ atomic.Pointer[reflect.Type]
|
|
once sync.Once
|
|
ok bool
|
|
path, vol, idxhi, idxlo int
|
|
}
|
|
|
|
// rememberFileStatType stores t, in a function of its own so that only a
|
|
// call that stores it moves a copy of t to the heap.
|
|
//
|
|
//go:noinline
|
|
func rememberFileStatType(t reflect.Type) { fileStatFields.typ.Store(&t) }
|
|
|
|
// fileWatchIdentity returns the identity os.SameFile compares, the volume
|
|
// and file index of the os package's fileStat, once it holds them: its
|
|
// path is empty when they were read from a handle or by StatIdentity.
|
|
// Another FileInfo, or one whose ID is still to be read, has none.
|
|
func fileWatchIdentity(info os.FileInfo) (fileWatchID, bool) {
|
|
v := reflect.ValueOf(info)
|
|
if v.Kind() != reflect.Pointer || v.IsNil() {
|
|
return fileWatchID{}, false
|
|
}
|
|
v = v.Elem()
|
|
t := v.Type()
|
|
f := &fileStatFields
|
|
if known := f.typ.Load(); known == nil || *known != t {
|
|
if t.Kind() != reflect.Struct || t.Name() != "fileStat" || t.PkgPath() != "os" {
|
|
return fileWatchID{}, false
|
|
}
|
|
rememberFileStatType(t)
|
|
}
|
|
f.once.Do(func() {
|
|
index := func(name string, kind reflect.Kind) int {
|
|
field, ok := t.FieldByName(name)
|
|
if !ok || field.Type.Kind() != kind || len(field.Index) != 1 {
|
|
return -1
|
|
}
|
|
return field.Index[0]
|
|
}
|
|
f.path, f.vol, f.idxhi, f.idxlo = index("path", reflect.String), index("vol", reflect.Uint32), index("idxhi", reflect.Uint32), index("idxlo", reflect.Uint32)
|
|
f.ok = f.path >= 0 && f.vol >= 0 && f.idxhi >= 0 && f.idxlo >= 0
|
|
})
|
|
if !f.ok || v.Field(f.path).Len() != 0 {
|
|
return fileWatchID{}, false
|
|
}
|
|
return fileWatchID{volume: v.Field(f.vol).Uint(), index: v.Field(f.idxhi).Uint()<<32 | v.Field(f.idxlo).Uint()}, true
|
|
}
|