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
+33
@@ -0,0 +1,33 @@
|
||||
//go:build js
|
||||
|
||||
package media
|
||||
|
||||
import "syscall/js"
|
||||
|
||||
// On browsers, a picture's surface is the video element that plays it,
|
||||
// which WebGL uploads from GPU to GPU: Surface.Native holds the number
|
||||
// AddElement gave it, which ElementOf takes back.
|
||||
|
||||
var (
|
||||
elements = map[uintptr]js.Value{}
|
||||
lastElement uintptr
|
||||
)
|
||||
|
||||
// AddElement numbers a video element, for a surface's Native.
|
||||
func AddElement(v js.Value) uintptr {
|
||||
lastElement++
|
||||
elements[lastElement] = v
|
||||
return lastElement
|
||||
}
|
||||
|
||||
// ElementOf returns the video element of a number AddElement gave, or
|
||||
// undefined once RemoveElement removed it.
|
||||
func ElementOf(n uintptr) js.Value {
|
||||
if v, ok := elements[n]; ok {
|
||||
return v
|
||||
}
|
||||
return js.Undefined()
|
||||
}
|
||||
|
||||
// RemoveElement forgets the video element of a number.
|
||||
func RemoveElement(n uintptr) { delete(elements, n) }
|
||||
+79
@@ -0,0 +1,79 @@
|
||||
// Package media is the contract between ui's VideoPlayer and the engines
|
||||
// that play video with the system's media frameworks (package ui/video):
|
||||
// AVFoundation on macOS, Media Foundation on Windows, GStreamer on Linux
|
||||
// and the video element in browsers. An engine decodes, plays the sound
|
||||
// and keeps the clock; the player asks it, as each frame of the window
|
||||
// builds, which picture is due, and shows it where the engine left it
|
||||
// (scene.Surface), without a copy.
|
||||
package media
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/egoist/mygo/internal/scene"
|
||||
)
|
||||
|
||||
// An Engine plays one video. Its methods are called on the main thread,
|
||||
// one at a time, except Close, which may be called from any goroutine
|
||||
// once nothing else is.
|
||||
type Engine interface {
|
||||
// SetWake gives the function the engine calls, from any goroutine,
|
||||
// when the window showing the video should build a frame: the first
|
||||
// picture came, the state changed, a seek landed. The first picture
|
||||
// needs its wake even where Frame is what takes it, as Loading to
|
||||
// Ready: only a frame of the window calls Frame, and none may come
|
||||
// otherwise (#1830). A change Frame itself makes needs none: the
|
||||
// player reads the state again after it. It may be called before the
|
||||
// engine is ready and again later; a nil func stops it.
|
||||
SetWake(wake func())
|
||||
// Frame returns the picture due at t, a time of the monotonic clock
|
||||
// at which the frame being built shows, and whether it is another
|
||||
// picture than the last Frame returned; ok is false while there is
|
||||
// none yet. The picture stays valid until Frame returns another, or
|
||||
// the engine closes.
|
||||
Frame(t time.Time) (f Picture, changed, ok bool)
|
||||
// Interval is how long a picture shows at the video's nominal rate at
|
||||
// rate 1, for the window to ask for its next frame as each comes due;
|
||||
// 0 for an engine that wakes the window as each picture comes due.
|
||||
Interval() time.Duration
|
||||
// State reports how loading and playing go, and the error that
|
||||
// stopped the video, if any.
|
||||
State() (State, error)
|
||||
// Size is the size of the pictures in pixels, 0×0 until known.
|
||||
Size() (w, h int)
|
||||
Duration() time.Duration // 0 until known, or for a live stream
|
||||
Position() time.Duration
|
||||
Play()
|
||||
Pause()
|
||||
Seek(time.Duration)
|
||||
SetLoop(bool)
|
||||
SetRate(float64)
|
||||
SetVolume(float64)
|
||||
SetMuted(bool)
|
||||
Close() error
|
||||
}
|
||||
|
||||
// A Picture is a frame of video where the engine left it.
|
||||
type Picture struct {
|
||||
Surface *scene.Surface
|
||||
W, H int
|
||||
// RGBA converts it to premultiplied RGBA, for the CPU renderer and
|
||||
// captures, into dst when it has room.
|
||||
RGBA func(dst []byte) []byte
|
||||
}
|
||||
|
||||
// State is the state of an engine.
|
||||
type State uint8
|
||||
|
||||
const (
|
||||
// Loading is before the video's first picture and size are known.
|
||||
Loading State = iota
|
||||
// Ready is playing or paused with pictures to show.
|
||||
Ready
|
||||
// Buffering waits for data that a stream is still downloading.
|
||||
Buffering
|
||||
// Ended is past the end of a video that does not loop.
|
||||
Ended
|
||||
// Failed is a video that stopped with an error.
|
||||
Failed
|
||||
)
|
||||
@@ -0,0 +1,27 @@
|
||||
// Package mediatest runs the tests of packages that play video with the
|
||||
// system's media framework (package ui/video) as an app runs: on macOS
|
||||
// while the main thread runs its run loop, for AVFoundation, which loads
|
||||
// and plays a video through the main queue.
|
||||
//
|
||||
// func TestMain(m *testing.M) { mediatest.Main(m) }
|
||||
package mediatest
|
||||
|
||||
import (
|
||||
"os"
|
||||
"runtime"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// The main goroutine stays on the main thread, for Main to run its run
|
||||
// loop there.
|
||||
func init() { runtime.LockOSThread() }
|
||||
|
||||
// Main runs the tests and exits with their status, on macOS while the
|
||||
// main thread runs its run loop.
|
||||
func Main(m *testing.M) {
|
||||
if runLoop == nil {
|
||||
os.Exit(m.Run())
|
||||
}
|
||||
go func() { os.Exit(m.Run()) }()
|
||||
runLoop()
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package mediatest
|
||||
|
||||
import "github.com/ebitengine/purego"
|
||||
|
||||
// runLoop is CFRunLoopRun, which runs the main thread's run loop, the
|
||||
// main queue's blocks with it, for ever.
|
||||
var runLoop func()
|
||||
|
||||
func init() {
|
||||
cf, err := purego.Dlopen("/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation", purego.RTLD_GLOBAL|purego.RTLD_NOW)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
purego.RegisterLibFunc(&runLoop, cf, "CFRunLoopRun")
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
//go:build !darwin
|
||||
|
||||
package mediatest
|
||||
|
||||
// runLoop is nil where the media framework needs no run loop of the main
|
||||
// thread's.
|
||||
var runLoop func()
|
||||
Reference in new issue
Block a user