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
Vendored
+144
@@ -0,0 +1,144 @@
|
||||
package audio
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"runtime"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
// A device is the system's audio output, opened by openDevice to hold
|
||||
// about ahead of what is heard.
|
||||
type device interface {
|
||||
// write plays interleaved stereo frames after those written before,
|
||||
// waiting while the device holds enough already. An error closes the
|
||||
// device, and the output opens it again.
|
||||
write(samples []float32) error
|
||||
close()
|
||||
}
|
||||
|
||||
// idleClose is how long the output stays open with nothing playing.
|
||||
const idleClose = 5 * time.Second
|
||||
|
||||
var (
|
||||
openOutput = openDevice // tests replace it
|
||||
|
||||
wake = make(chan struct{}, 1)
|
||||
runOnce sync.Once
|
||||
testMode bool // tests mix by hand
|
||||
)
|
||||
|
||||
// wakeOutput starts the output, or tells it a voice started. The caller
|
||||
// holds mu.
|
||||
func wakeOutput() {
|
||||
if testMode {
|
||||
return
|
||||
}
|
||||
runOnce.Do(func() { go run() })
|
||||
select {
|
||||
case wake <- struct{}{}:
|
||||
default:
|
||||
}
|
||||
}
|
||||
|
||||
func active() bool {
|
||||
mu.Lock()
|
||||
defer mu.Unlock()
|
||||
return len(voices) > 0 && !testMode
|
||||
}
|
||||
|
||||
// mixFor mixes into buf for an output open at latency lat, and reports
|
||||
// whether anything plays; ok is false, and it mixes nothing, once tests
|
||||
// mix by hand or the latency changed.
|
||||
func mixFor(buf []float32, lat Latency) (busy, ok bool) {
|
||||
mu.Lock()
|
||||
defer mu.Unlock()
|
||||
if testMode || latency != lat {
|
||||
return false, false
|
||||
}
|
||||
return mixLocked(buf), true
|
||||
}
|
||||
|
||||
// run opens the device while anything plays, and mixes into it.
|
||||
func run() {
|
||||
for {
|
||||
for !active() {
|
||||
<-wake
|
||||
}
|
||||
lat := outputLatency()
|
||||
dev, n, err := openOutput(lat.ahead())
|
||||
if err != nil {
|
||||
setErr(err)
|
||||
dev, n = newNullDevice(err != errUnsupported), nullFrames
|
||||
// It holds nothing: what it takes is heard as it takes it.
|
||||
setHeld(0)
|
||||
} else {
|
||||
setErr(nil)
|
||||
setHeld(int64(lat.ahead() * sampleRate / time.Second))
|
||||
}
|
||||
buf := make([]float32, n*channels)
|
||||
idle := time.Duration(0)
|
||||
per := frames(int64(n), sampleRate)
|
||||
for {
|
||||
busy, ok := mixFor(buf, lat)
|
||||
if !ok {
|
||||
break
|
||||
}
|
||||
// write blocks in C, keeping the P, which the runtime would
|
||||
// take back every 10 ms, waking more often after.
|
||||
runtime.Gosched()
|
||||
if err := dev.write(buf); err != nil {
|
||||
// Lost, or a null device trying the real one again.
|
||||
break
|
||||
}
|
||||
if busy {
|
||||
idle = 0
|
||||
} else if idle += per; idle >= idleClose {
|
||||
break
|
||||
}
|
||||
}
|
||||
dev.close()
|
||||
}
|
||||
}
|
||||
|
||||
var errUnsupported = errors.New("audio: no audio output on this platform")
|
||||
|
||||
// nullFrames is how many frames a null device takes at a time: 10 ms.
|
||||
const nullFrames = sampleRate / 100
|
||||
|
||||
// A nullDevice plays nothing, on time: players still end when they would
|
||||
// have. One standing in for a device that failed to open fails after a
|
||||
// while, so that the output tries the device again.
|
||||
type nullDevice struct {
|
||||
next time.Time
|
||||
retry time.Time
|
||||
// now and sleep are its clock, which tests replace.
|
||||
now func() time.Time
|
||||
sleep func(time.Duration)
|
||||
}
|
||||
|
||||
func newNullDevice(retry bool) *nullDevice {
|
||||
d := &nullDevice{next: time.Now(), now: time.Now, sleep: time.Sleep}
|
||||
if retry {
|
||||
d.retry = d.next.Add(2 * time.Second)
|
||||
}
|
||||
return d
|
||||
}
|
||||
|
||||
var errRetry = errors.New("audio: try the device again")
|
||||
|
||||
func (d *nullDevice) write(samples []float32) error {
|
||||
now := d.now()
|
||||
if !d.retry.IsZero() && now.After(d.retry) {
|
||||
return errRetry
|
||||
}
|
||||
if now.Sub(d.next) > 100*time.Millisecond {
|
||||
// Behind, as after a sleep: don't hurry to catch up.
|
||||
d.next = now
|
||||
}
|
||||
d.next = d.next.Add(frames(int64(len(samples)/channels), sampleRate))
|
||||
d.sleep(d.next.Sub(d.now()))
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d *nullDevice) close() {}
|
||||
Reference in new issue
Block a user