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
+141
@@ -0,0 +1,141 @@
|
||||
//go:build darwin
|
||||
|
||||
// Package kqueue watches files with kqueue's vnode events, for iOS, which
|
||||
// has no FSEvents: a descriptor for every file and directory watched,
|
||||
// opened for events only, as fsnotify does. A directory's event says
|
||||
// that its entries changed, not which, so the core lists it again; a
|
||||
// file's says that it was written.
|
||||
package kqueue
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"syscall"
|
||||
|
||||
"github.com/egoist/mygo/internal/platform"
|
||||
"github.com/egoist/mygo/internal/watchdriver"
|
||||
)
|
||||
|
||||
// vnodeEvents are what a target's descriptor reports.
|
||||
const vnodeEvents = syscall.NOTE_DELETE | syscall.NOTE_WRITE | syscall.NOTE_EXTEND | syscall.NOTE_ATTRIB | syscall.NOTE_LINK | syscall.NOTE_RENAME | syscall.NOTE_REVOKE
|
||||
|
||||
// watch is a watch's driver: a kqueue of its own, with a user event that
|
||||
// wakes Wait, and a descriptor for each target.
|
||||
type watch struct {
|
||||
kq int
|
||||
targets map[uint64]int // descriptors, by ID
|
||||
ids map[int]uint64 // IDs, by descriptor
|
||||
dirs map[int]bool
|
||||
}
|
||||
|
||||
// New starts a watch with a kqueue of its own.
|
||||
func New(notify func(platform.FileWatchNotice)) (platform.FileWatch, error) {
|
||||
kq, err := syscall.Kqueue()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
syscall.CloseOnExec(kq)
|
||||
wake := syscall.Kevent_t{Ident: 0, Filter: syscall.EVFILT_USER, Flags: syscall.EV_ADD | syscall.EV_CLEAR}
|
||||
if _, err := syscall.Kevent(kq, []syscall.Kevent_t{wake}, nil, nil); err != nil {
|
||||
syscall.Close(kq)
|
||||
return nil, err
|
||||
}
|
||||
d := &watch{kq: kq, targets: make(map[uint64]int), ids: make(map[int]uint64), dirs: make(map[int]bool)}
|
||||
return watchdriver.New(d, notify), nil
|
||||
}
|
||||
|
||||
func (d *watch) Add(t platform.FileWatchTarget) error {
|
||||
if t.Subtree {
|
||||
return platform.ErrUnsupported
|
||||
}
|
||||
if m := t.Info.Mode(); !m.IsDir() && !m.IsRegular() {
|
||||
// Links, pipes and devices: their directory names what happens
|
||||
// to them, and opening a pipe would wait for its writer.
|
||||
return nil
|
||||
}
|
||||
fd, err := syscall.Open(t.Path, syscall.O_EVTONLY|syscall.O_NONBLOCK|syscall.O_NOFOLLOW|syscall.O_CLOEXEC, 0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
var st syscall.Stat_t
|
||||
if err := syscall.Fstat(fd, &st); err != nil {
|
||||
syscall.Close(fd)
|
||||
return err
|
||||
}
|
||||
if seen, ok := t.Info.Sys().(*syscall.Stat_t); !ok || seen.Dev != st.Dev || seen.Ino != st.Ino {
|
||||
syscall.Close(fd)
|
||||
return errors.New("watch target identity changed")
|
||||
}
|
||||
ev := syscall.Kevent_t{Ident: uint64(fd), Filter: syscall.EVFILT_VNODE, Flags: syscall.EV_ADD | syscall.EV_CLEAR, Fflags: vnodeEvents}
|
||||
if _, err := syscall.Kevent(d.kq, []syscall.Kevent_t{ev}, nil, nil); err != nil {
|
||||
syscall.Close(fd)
|
||||
return err
|
||||
}
|
||||
d.targets[t.ID] = fd
|
||||
d.ids[fd] = t.ID
|
||||
d.dirs[fd] = t.Directory
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d *watch) Remove(id uint64) {
|
||||
if fd, ok := d.targets[id]; ok {
|
||||
d.forget(fd)
|
||||
}
|
||||
}
|
||||
|
||||
// forget closes a target's descriptor, which takes its events, queued
|
||||
// ones included, off the kqueue.
|
||||
func (d *watch) forget(fd int) {
|
||||
delete(d.targets, d.ids[fd])
|
||||
delete(d.ids, fd)
|
||||
delete(d.dirs, fd)
|
||||
syscall.Close(fd)
|
||||
}
|
||||
|
||||
func (d *watch) Wait() ([]platform.FileWatchNotice, error) {
|
||||
var events [64]syscall.Kevent_t
|
||||
n, err := syscall.Kevent(d.kq, nil, events[:], nil)
|
||||
if err == syscall.EINTR {
|
||||
return nil, nil
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var notices []platform.FileWatchNotice
|
||||
for _, ev := range events[:n] {
|
||||
if ev.Filter != syscall.EVFILT_VNODE {
|
||||
continue // Wake
|
||||
}
|
||||
fd := int(ev.Ident)
|
||||
id, ok := d.ids[fd]
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
var kind platform.FileWatchKind
|
||||
switch f := ev.Fflags; {
|
||||
case f&(syscall.NOTE_DELETE|syscall.NOTE_RENAME|syscall.NOTE_REVOKE) != 0:
|
||||
// The descriptor follows the file wherever it went: the core
|
||||
// enrolls what is at the path now.
|
||||
kind = platform.FileWatchLost
|
||||
d.forget(fd)
|
||||
case !d.dirs[fd] && f&(syscall.NOTE_WRITE|syscall.NOTE_EXTEND) != 0:
|
||||
kind = platform.FileWatchWrite
|
||||
}
|
||||
// A directory written to gained or lost entries, which listing it
|
||||
// again finds; NOTE_ATTRIB is dirty, as metadata alone is not a
|
||||
// write.
|
||||
notices = append(notices, platform.FileWatchNotice{Target: id, Kind: kind})
|
||||
}
|
||||
return notices, nil
|
||||
}
|
||||
|
||||
func (d *watch) Wake() {
|
||||
ev := syscall.Kevent_t{Ident: 0, Filter: syscall.EVFILT_USER, Fflags: syscall.NOTE_TRIGGER}
|
||||
syscall.Kevent(d.kq, []syscall.Kevent_t{ev}, nil, nil)
|
||||
}
|
||||
|
||||
func (d *watch) Close() {
|
||||
for fd := range d.ids {
|
||||
d.forget(fd)
|
||||
}
|
||||
syscall.Close(d.kq)
|
||||
}
|
||||
+108
@@ -0,0 +1,108 @@
|
||||
//go:build darwin
|
||||
|
||||
package kqueue
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"syscall"
|
||||
"testing"
|
||||
|
||||
"github.com/egoist/mygo/internal/platform"
|
||||
"github.com/egoist/mygo/internal/wait"
|
||||
)
|
||||
|
||||
func TestKqueueWatch(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
sub := filepath.Join(dir, "sub")
|
||||
file := filepath.Join(dir, "file")
|
||||
if err := os.Mkdir(sub, 0700); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := os.WriteFile(file, nil, 0600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := syscall.Mkfifo(filepath.Join(dir, "pipe"), 0600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
notices := make(chan platform.FileWatchNotice, 16)
|
||||
w, err := New(func(n platform.FileWatchNotice) { notices <- n })
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer w.Close()
|
||||
add := func(id uint64, path string, subtree bool) error {
|
||||
t.Helper()
|
||||
info, err := os.Lstat(path)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
return w.Add(platform.FileWatchTarget{ID: id, Path: path, Directory: info.IsDir(), Info: info, Subtree: subtree})
|
||||
}
|
||||
if err := add(1, dir, true); err != platform.ErrUnsupported {
|
||||
t.Fatalf("subtree: %v", err)
|
||||
}
|
||||
// A pipe is skipped rather than opened, which would wait for a writer.
|
||||
for id, path := range map[uint64]string{1: dir, 2: sub, 3: file, 4: filepath.Join(dir, "pipe")} {
|
||||
if err := add(id, path, false); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
next := func(want platform.FileWatchNotice) {
|
||||
t.Helper()
|
||||
for {
|
||||
n := wait.For(t, "notice", notices)
|
||||
if n == want {
|
||||
return
|
||||
}
|
||||
if n.Err != nil || n.Kind == platform.FileWatchLost {
|
||||
t.Fatalf("notice %+v, want %+v", n, want)
|
||||
}
|
||||
}
|
||||
}
|
||||
if err := os.WriteFile(filepath.Join(sub, "new"), nil, 0600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
next(platform.FileWatchNotice{Target: 2, Kind: platform.FileWatchDirty})
|
||||
if err := os.WriteFile(file, []byte("written"), 0600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
next(platform.FileWatchNotice{Target: 3, Kind: platform.FileWatchWrite})
|
||||
// A file replaced: its watch is lost, and its directory changed.
|
||||
if err := os.Rename(filepath.Join(sub, "new"), file); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
next(platform.FileWatchNotice{Target: 3, Kind: platform.FileWatchLost})
|
||||
// The lost target is gone: its ID can be enrolled again.
|
||||
if err := add(3, file, false); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := os.WriteFile(file, []byte("again"), 0600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
next(platform.FileWatchNotice{Target: 3, Kind: platform.FileWatchWrite})
|
||||
// A target removed reports nothing more: the Add after it waits
|
||||
// until the driver has taken it off.
|
||||
w.Remove(2)
|
||||
if err := add(6, dir, false); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := os.RemoveAll(sub); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
next(platform.FileWatchNotice{Target: 1, Kind: platform.FileWatchDirty})
|
||||
// A replacement racing the enrollment is not watched in its place.
|
||||
info, err := os.Lstat(file)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := os.Remove(file); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := os.WriteFile(file, nil, 0600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := w.Add(platform.FileWatchTarget{ID: 5, Path: file, Info: info}); err == nil {
|
||||
t.Fatal("watched a replacement")
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user