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
+117
@@ -0,0 +1,117 @@
|
||||
// Package watchdriver runs the native file watchers of the backends on one
|
||||
// goroutine each: the goroutine owns the system's handles, adds and removes
|
||||
// targets between waits, and reports what the system tells it.
|
||||
package watchdriver
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"sync"
|
||||
|
||||
"github.com/egoist/mygo/internal/platform"
|
||||
)
|
||||
|
||||
// Driver is a backend's watcher. Every method but Wake runs on the
|
||||
// goroutine of its Watch. Wait blocks until the system reports changes or
|
||||
// Wake is called; an error it returns ends the watch.
|
||||
type Driver interface {
|
||||
Add(platform.FileWatchTarget) error
|
||||
Remove(id uint64)
|
||||
Wait() ([]platform.FileWatchNotice, error)
|
||||
Wake()
|
||||
Close()
|
||||
}
|
||||
|
||||
// errClosed is what Add returns once the watch has stopped.
|
||||
var errClosed = errors.New("file watch closed")
|
||||
|
||||
type command struct {
|
||||
target platform.FileWatchTarget
|
||||
remove uint64
|
||||
reply chan error
|
||||
}
|
||||
|
||||
// Watch is a platform.FileWatch running a Driver.
|
||||
type Watch struct {
|
||||
driver Driver
|
||||
notify func(platform.FileWatchNotice)
|
||||
mu sync.Mutex
|
||||
queue []command
|
||||
closed bool
|
||||
done chan struct{}
|
||||
}
|
||||
|
||||
// New starts the goroutine of d, which calls notify with what d reports.
|
||||
func New(d Driver, notify func(platform.FileWatchNotice)) *Watch {
|
||||
w := &Watch{driver: d, notify: notify, done: make(chan struct{})}
|
||||
go w.run()
|
||||
return w
|
||||
}
|
||||
|
||||
// Add enrolls t and returns once the driver has.
|
||||
func (w *Watch) Add(t platform.FileWatchTarget) error {
|
||||
reply := make(chan error, 1)
|
||||
if !w.send(command{target: t, reply: reply}) {
|
||||
return errClosed
|
||||
}
|
||||
select {
|
||||
case err := <-reply:
|
||||
return err
|
||||
case <-w.done:
|
||||
return errClosed
|
||||
}
|
||||
}
|
||||
|
||||
func (w *Watch) Remove(id uint64) { w.send(command{remove: id}) }
|
||||
|
||||
// Close stops the goroutine and waits until the driver has closed.
|
||||
func (w *Watch) Close() {
|
||||
w.mu.Lock()
|
||||
w.closed = true
|
||||
w.mu.Unlock()
|
||||
w.driver.Wake()
|
||||
<-w.done
|
||||
}
|
||||
|
||||
func (w *Watch) send(c command) bool {
|
||||
w.mu.Lock()
|
||||
if w.closed {
|
||||
w.mu.Unlock()
|
||||
return false
|
||||
}
|
||||
w.queue = append(w.queue, c)
|
||||
w.mu.Unlock()
|
||||
w.driver.Wake()
|
||||
return true
|
||||
}
|
||||
|
||||
func (w *Watch) run() {
|
||||
defer close(w.done)
|
||||
defer w.driver.Close()
|
||||
for {
|
||||
w.mu.Lock()
|
||||
queue, closed := w.queue, w.closed
|
||||
w.queue = nil
|
||||
w.mu.Unlock()
|
||||
if closed {
|
||||
return
|
||||
}
|
||||
for _, c := range queue {
|
||||
if c.reply != nil {
|
||||
c.reply <- w.driver.Add(c.target)
|
||||
} else {
|
||||
w.driver.Remove(c.remove)
|
||||
}
|
||||
}
|
||||
notices, err := w.driver.Wait()
|
||||
for _, n := range notices {
|
||||
w.notify(n)
|
||||
}
|
||||
if err != nil {
|
||||
w.mu.Lock()
|
||||
w.closed = true
|
||||
w.mu.Unlock()
|
||||
w.notify(platform.FileWatchNotice{Err: err})
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
package watchdriver
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"testing"
|
||||
|
||||
"github.com/egoist/mygo/internal/platform"
|
||||
)
|
||||
|
||||
type testDriver struct {
|
||||
wake chan struct{}
|
||||
added []uint64
|
||||
removed []uint64
|
||||
fail chan error
|
||||
closed bool
|
||||
}
|
||||
|
||||
func (d *testDriver) Add(t platform.FileWatchTarget) error {
|
||||
d.added = append(d.added, t.ID)
|
||||
if t.ID == 0 {
|
||||
return platform.ErrUnsupported
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func (d *testDriver) Remove(id uint64) { d.removed = append(d.removed, id) }
|
||||
func (d *testDriver) Wait() ([]platform.FileWatchNotice, error) {
|
||||
select {
|
||||
case <-d.wake:
|
||||
return []platform.FileWatchNotice{{Target: 1}}, nil
|
||||
case err := <-d.fail:
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
func (d *testDriver) Wake() {
|
||||
select {
|
||||
case d.wake <- struct{}{}:
|
||||
default:
|
||||
}
|
||||
}
|
||||
func (d *testDriver) Close() { d.closed = true }
|
||||
|
||||
func TestWatch(t *testing.T) {
|
||||
d := &testDriver{wake: make(chan struct{}, 1), fail: make(chan error)}
|
||||
notices := make(chan platform.FileWatchNotice, 16)
|
||||
w := New(d, func(n platform.FileWatchNotice) { notices <- n })
|
||||
if err := w.Add(platform.FileWatchTarget{ID: 1}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := w.Add(platform.FileWatchTarget{ID: 0}); err != platform.ErrUnsupported {
|
||||
t.Fatalf("Add = %v", err)
|
||||
}
|
||||
w.Remove(1)
|
||||
// Commands run in order and Add returns once the driver has run it, so
|
||||
// Remove has too before the failure below, which the driver could
|
||||
// otherwise pick over the wake that Remove left.
|
||||
if err := w.Add(platform.FileWatchTarget{ID: 3}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if n := <-notices; n.Target != 1 {
|
||||
t.Fatalf("notice %+v", n)
|
||||
}
|
||||
// An error from Wait ends the watch, and is the last notice.
|
||||
failure := errors.New("failure")
|
||||
d.fail <- failure
|
||||
for n := range notices {
|
||||
if n.Err != nil {
|
||||
if n.Err != failure {
|
||||
t.Fatalf("notice %+v", n)
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
if err := w.Add(platform.FileWatchTarget{ID: 2}); err == nil {
|
||||
t.Fatal("added to a stopped watch")
|
||||
}
|
||||
w.Close()
|
||||
if !d.closed || len(d.added) != 3 || len(d.removed) != 1 {
|
||||
t.Fatalf("driver %+v", d)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user