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:
OpenChamber committed 2026-11-18 13:22:59 +08:00
1 parent 2fb4a8ea79
commit 6c0ee61750
2538 files changed
+675779 -4792

No files matched your search

+130
View File
@@ -0,0 +1,130 @@
// Package bridge embeds the renderer runtime that MyGo injects into pages.
//
// bridge.js is built from ../../packages/bridge by `bun run build` and
// committed, so building a MyGo application never requires Bun.
package bridge
import (
_ "embed"
"encoding/json"
"github.com/egoist/mygo/internal/platform"
)
//go:embed bridge.js
var source string
// Config is passed to the bridge as __MYGO_CONFIG__.
type Config struct {
Platform string `json:"platform"`
WindowID int `json:"windowId"`
Version string `json:"version"`
// Secret prefixes every message the bridge posts.
Secret string `json:"secret"`
// Locale is the language the app shows, e.g. "zh-Hans", and Dir the
// direction it is written in, "ltr" or "rtl", which pages read as
// mygo.locale and mygo.dir from document start.
Locale string `json:"locale"`
Dir string `json:"dir"`
// Fit is the limits of a window that takes the size of its page's
// content (FitContent), nil for other windows.
Fit *FitContent `json:"fit,omitempty"`
}
// Script returns the bridge source configured for one window.
func Script(cfg Config) string {
b, _ := json.Marshal(cfg)
return "(function(__MYGO_CONFIG__){\n" + source + "})(" + string(b) + ");"
}
// TitleBarEvent tells a page of a window with a hidden title bar the room
// the window controls take. The bridge keeps it in the --mygo-titlebar-*
// CSS variables.
const TitleBarEvent = "mygo:title-bar"
// LocaleEvent tells the pages of a window that the language the app shows
// changed, with a Locale. The bridge configuration tells pages the
// language at document start; the event is sent as a page loads too, for
// one that started loading as the language changed, and the bridge tells
// its listeners only of a language the page did not have.
const LocaleEvent = "mygo:locale"
// Locale is the payload of LocaleEvent.
type Locale struct {
Locale string `json:"locale"`
Dir string `json:"dir"`
}
// TitleBar is the payload of TitleBarEvent, in CSS pixels.
type TitleBar struct {
Height float64 `json:"height"`
Left float64 `json:"left"`
Right float64 `json:"right"`
Bottom float64 `json:"bottom"`
}
// NewTitleBar converts the room of the window controls to the CSS pixels
// of a page shown at zoom.
func NewTitleBar(tb platform.TitleBar, zoom float64) TitleBar {
if zoom <= 0 {
zoom = 1
}
return TitleBar{Height: float64(tb.Height) / zoom, Left: float64(tb.Left) / zoom, Right: float64(tb.Right) / zoom, Bottom: float64(tb.Bottom) / zoom}
}
// FitContentEvent tells the page of a window that takes the size of its
// content (FitContent) the limits of that size, with a FitContent, when
// the page's zoom changed them. The bridge configuration tells them at
// document start.
const FitContentEvent = "mygo:fit-content"
// FitContent is the limits of the size of a window that takes its
// content's, in CSS pixels; 0 is none. The bridge lays the page's root
// element out within them.
type FitContent struct {
MinWidth float64 `json:"minWidth"`
MinHeight float64 `json:"minHeight"`
MaxWidth float64 `json:"maxWidth"`
MaxHeight float64 `json:"maxHeight"`
}
// NewFitContent converts the limits of a window's size, in DIPs, to the CSS
// pixels of a page shown at zoom.
func NewFitContent(minSize, maxSize platform.Size, zoom float64) FitContent {
if zoom <= 0 {
zoom = 1
}
return FitContent{
MinWidth: float64(minSize.Width) / zoom,
MinHeight: float64(minSize.Height) / zoom,
MaxWidth: float64(maxSize.Width) / zoom,
MaxHeight: float64(maxSize.Height) / zoom,
}
}
// TitleBarScript delivers TitleBarEvent at document start, after the
// bridge, so that a page lays out around the window controls before it
// first paints.
func TitleBarScript(tb platform.TitleBar, zoom float64) string {
p, _ := json.Marshal(NewTitleBar(tb, zoom))
return `window.__mygo&&window.__mygo.receive({"t":"event","n":"` + TitleBarEvent + `","p":` + string(p) + `});`
}
// WindowActiveEvent tells a page whether its window is drawn as active,
// true or false: the bridge keeps it for mygo-runtime's windowActive(),
// and sets the attribute data-mygo-window-inactive of <html> while it is
// not. Pages start active; a page that loads in an inactive window hears
// it as its DOM is ready.
const WindowActiveEvent = "mygo:window-active"
// PreferencesEvent tells a page the accent color and the accessibility
// settings of the desktop, as mygo.ThemePreferences encodes them. The
// bridge keeps the latest for mygo-runtime's preferences(), the accent in
// the --mygo-accent CSS variable and the text scale in --mygo-text-scale.
const PreferencesEvent = "mygo:preferences"
// PreferencesScript delivers PreferencesEvent with the JSON prefs at
// document start, after the bridge has registered its handler.
func PreferencesScript(prefs []byte) string {
return `window.__mygo&&window.__mygo.receive({"t":"event","n":"` + PreferencesEvent + `","p":` + string(prefs) + `});`
}
+2
View File
@@ -0,0 +1,2 @@
// Code generated by `bun run build` from packages/bridge. DO NOT EDIT.
(()=>{var ae=new Set(["button","checkbox","color","file","hidden","image","radio","range","reset","submit"]);function V(e,t){let n={},o=e?.closest("input,textarea")??null,s=o&&!(o.type&&ae.has(o.type.toLowerCase()));if(s&&!o.readOnly&&!o.disabled)n.e=!0;else if(e?.isContentEditable)n.e=!0;if(s&&o.type?.toLowerCase()!=="password"){let c=o.selectionStart??0,b=o.selectionEnd??0;if(b>c)t=(o.value??"").slice(c,b)}else if(s)t="";if(t)n.s=t;if(!e)return n;let a=e.closest("a[href],area[href]");if(a){let c=typeof a.href==="string"?a.href:a.href?.baseVal??"";if(c)n.l=c;let b=(a.innerText??a.textContent??"").trim();if(b)n.lt=b}let u=e.closest("img");if(u){let c=u.currentSrc||u.src;if(c)n.i=c}let m=e.closest("video,audio");if(m){let c=m.currentSrc||m.src;if(c)n.m=c}return n}var C=null,N=null,W=()=>typeof CSS<"u"&&("highlights"in CSS)&&typeof Highlight<"u";function ce(e,t){let n=[];if(!e||!document.body)return n;let o=t?e:e.toLowerCase(),s=document.createTreeWalker(document.body,NodeFilter.SHOW_TEXT,{acceptNode(a){let u=a.parentElement;if(!u||/^(SCRIPT|STYLE|NOSCRIPT|TEMPLATE|TEXTAREA)$/.test(u.tagName))return NodeFilter.FILTER_REJECT;return u.getClientRects().length?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_REJECT}});for(let a=s.nextNode();a;a=s.nextNode()){let u=t?a.nodeValue:a.nodeValue.toLowerCase();for(let m=u.indexOf(o);m>=0;m=u.indexOf(o,m+o.length)){let c=document.createRange();c.setStart(a,m),c.setEnd(a,m+o.length),n.push(c)}}return n}function de(){if(N||!("adoptedStyleSheets"in document))return;N=new CSSStyleSheet,N.replaceSync("::highlight(mygo-find){background-color:#fdeb62;color:#000}::highlight(mygo-find-active){background-color:#ff9632;color:#000}"),document.adoptedStyleSheets=[...document.adoptedStyleSheets,N]}function q(e,t={}){let n=!!t.matchCase;if(!t.next||!C||C.text!==e||C.matchCase!==n)C={text:e,matchCase:n,ranges:ce(e,n),active:-1};let o=C.ranges.length;if(o===0)return H(),{matches:0,active:0};C.active=C.active<0?t.backward?o-1:0:(C.active+(t.backward?o-1:1))%o;let s=C.ranges[C.active];if(W())de(),CSS.highlights.set("mygo-find",new Highlight(...C.ranges)),CSS.highlights.set("mygo-find-active",new Highlight(s));else{let a=getSelection();a?.removeAllRanges(),a?.addRange(s)}return s.startContainer.parentElement?.scrollIntoView({block:"center",inline:"nearest"}),{matches:o,active:C.active+1}}function H(){if(C&&!W())getSelection()?.removeAllRanges();if(C=null,W())CSS.highlights.delete("mygo-find"),CSS.highlights.delete("mygo-find-active")}function ue(e,t){let n=["width:max-content"];if(e.minWidth>0)n.push(`min-width:${Math.max(e.minWidth-t,0)}px`);if(e.maxWidth>0)n.push(`max-width:${Math.max(e.maxWidth-t,0)}px`);if(e.minHeight>0)n.push(`min-height:${e.minHeight}px`);return`:where(:root){${n.join(";")}}`}function B(e){let t=null;return(n)=>{if(t&&t.w===n.w&&t.h===n.h&&t.sw===n.sw&&t.sh===n.sh)return;t=n,e(n)}}function J(e,t,n){let o=B(n),s=0,a=!1,u=!1,m=()=>t(ue(e,s)),c=(b)=>{let p=document.documentElement;if(!p)return;let h=document.scrollingElement??p,y=Math.max(innerWidth-h.clientWidth,0),O=Math.max(innerHeight-h.clientHeight,0),x=p.getBoundingClientRect(),r=e.maxHeight>0&&x.height>e.maxHeight?y:0;if(r!==s){if(s=r,!b)m(),x=p.getBoundingClientRect();else if(!u)u=!0,requestAnimationFrame(()=>{u=!1,m()})}let S=document.body,E=!!S&&S.scrollWidth>S.clientWidth;o({w:x.width,h:x.height,sw:y,sh:E?O:0})};return m(),{start(){if(a)return;if(a=!0,c(!1),typeof ResizeObserver<"u"&&document.documentElement)new ResizeObserver(()=>c(!0)).observe(document.documentElement);addEventListener("resize",()=>c(!1))},setLimits(b){if(e=b,m(),a)c(!1)},again(){if(o=B(n),a)c(!1)}}}var j=(e)=>setTimeout(()=>{throw e});function Y(e){if(e.reason!==void 0)return e.reason;return Error("mygo: the call was aborted")}class D extends Error{method;constructor(e,t){super(t);this.method=e;this.name="CallError"}}function X(e,t){let n=Math.random().toString(36).slice(2)+Date.now().toString(36),o=new Map,s=new Map,a={accent:null,reduceMotion:!1,reduceTransparency:!1,highContrast:!1,textScale:1},u=0,m=new Map,c=new WeakMap,b=0,p=e.locale||"en",h=e.dir==="rtl"?"rtl":"ltr",y=!0,O=(f)=>t(JSON.stringify(f)),x=(f,...i)=>S(f,i),r=(f,i,l)=>{let d=l?.signal;if(!d)return S(f,i);if(d.aborted)return Promise.reject(Y(d));return S(f,i,d)},S=(f,i,l)=>{let d=++u;return new Promise((L,A)=>{let M;for(let w of i){let v=typeof w==="object"&&w!==null?c.get(w):void 0;if(!v)continue;if(v.id||v.closed){M?.forEach((g)=>{m.delete(g.id),g.id=0}),A(Error("mygo: a channel can be passed to one call, before it is closed"));return}v.id=++b,m.set(v.id,v),(M??=[]).push(v)}let k,P;if(l)k=()=>{o.delete(d),M?.forEach((w)=>{m.delete(w.id),w.id=0});try{O({t:"cancel",id:d,k:n})}catch{}A(Y(l))},l.addEventListener("abort",k,{once:!0}),P=()=>l.removeEventListener("abort",k);o.set(d,{method:f,resolve:L,reject:A,channels:M,done:P});try{O({t:"call",id:d,k:n,m:f,a:i,cancel:l?!0:void 0})}catch(w){if(o.delete(d),k)l?.removeEventListener("abort",k);M?.forEach((v)=>{m.delete(v.id),v.id=0}),A(Line truncated