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.
78 lines
1.9 KiB
Go
78 lines
1.9 KiB
Go
package mygo
|
|
|
|
import (
|
|
"io/fs"
|
|
"net/url"
|
|
"os"
|
|
"strings"
|
|
"sync"
|
|
)
|
|
|
|
// The app's frontend is its web UI. Windows load it with URLs without a
|
|
// scheme, such as "/" or "/settings" (see WindowOptions.URL), which resolve
|
|
// against:
|
|
//
|
|
// - the dev server at devUrl (mygo.config.ts) while `mygo dev` runs the app;
|
|
// - otherwise mygo://localhost/, which serves the frontendDist files that
|
|
// `mygo build` embeds into the app (see SetFrontend).
|
|
//
|
|
// The mygo scheme serves the frontend unless the app handles it itself with
|
|
// Protocol.Handle.
|
|
const frontendScheme = "mygo"
|
|
|
|
var frontend struct {
|
|
sync.Mutex
|
|
fsys fs.FS
|
|
}
|
|
|
|
// SetFrontend serves fsys as the app's frontend at mygo://localhost/. Paths
|
|
// without a file extension that match no file serve index.html, for
|
|
// client-side routing.
|
|
//
|
|
// `mygo build` calls it with the frontendDist files it embeds into the app,
|
|
// so apps rarely need to. Call it to ship a frontend without the mygo CLI,
|
|
// e.g. from an embed.FS.
|
|
func SetFrontend(fsys fs.FS) {
|
|
frontend.Lock()
|
|
frontend.fsys = fsys
|
|
frontend.Unlock()
|
|
}
|
|
|
|
// devURL returns the dev server `mygo dev` points the app at, or "".
|
|
func devURL() string {
|
|
if !IsDev() {
|
|
return ""
|
|
}
|
|
return os.Getenv("MYGO_DEV_URL")
|
|
}
|
|
|
|
// resolveURL resolves a URL without a scheme against the frontend.
|
|
func resolveURL(raw string) (string, error) {
|
|
ref, err := url.Parse(raw)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
if ref.Scheme != "" {
|
|
return raw, nil
|
|
}
|
|
base := frontendScheme + "://localhost/"
|
|
if d := devURL(); d != "" {
|
|
base = d
|
|
}
|
|
b, err := url.Parse(base)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
return b.ResolveReference(ref).String(), nil
|
|
}
|
|
|
|
// isDevOrigin reports whether origin ("scheme://host") is the dev server's.
|
|
func isDevOrigin(origin string) bool {
|
|
d := devURL()
|
|
if d == "" {
|
|
return false
|
|
}
|
|
u, err := url.Parse(d)
|
|
return err == nil && strings.EqualFold(u.Scheme+"://"+u.Host, origin)
|
|
}
|