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

+6
View File
@@ -0,0 +1,6 @@
//go:build !windows
package webview2
// regString finds nothing: only Windows has a registry.
func regString(machine bool, path, name string) string { return "" }
+51
View File
@@ -0,0 +1,51 @@
package webview2
import (
"syscall"
"unsafe"
)
var (
advapi32 = syscall.NewLazyDLL("advapi32.dll") // a KnownDLL
procRegOpenKeyExW = advapi32.NewProc("RegOpenKeyExW")
procRegQueryValueExW = advapi32.NewProc("RegQueryValueExW")
procRegCloseKey = advapi32.NewProc("RegCloseKey")
)
const (
hkeyCurrentUser = 0x80000001
hkeyLocalMachine = 0x80000002
keyQueryValue = 0x0001
keyWow6432Key = 0x0200
)
// regString reads a string value from the 32-bit view of the registry,
// where EdgeUpdate records its clients.
func regString(machine bool, path, name string) string {
root := uintptr(hkeyCurrentUser)
if machine {
root = hkeyLocalMachine
}
p, err := syscall.UTF16PtrFromString(path)
if err != nil {
return ""
}
n, err := syscall.UTF16PtrFromString(name)
if err != nil {
return ""
}
var key uintptr
if r, _, _ := procRegOpenKeyExW.Call(root, uintptr(unsafe.Pointer(p)), 0, keyQueryValue|keyWow6432Key, uintptr(unsafe.Pointer(&key))); r != 0 {
return ""
}
defer procRegCloseKey.Call(key)
var typ, size uint32
if r, _, _ := procRegQueryValueExW.Call(key, uintptr(unsafe.Pointer(n)), 0, uintptr(unsafe.Pointer(&typ)), 0, uintptr(unsafe.Pointer(&size))); r != 0 || size == 0 {
return ""
}
buf := make([]uint16, size/2+1)
if r, _, _ := procRegQueryValueExW.Call(key, uintptr(unsafe.Pointer(n)), 0, uintptr(unsafe.Pointer(&typ)), uintptr(unsafe.Pointer(&buf[0])), uintptr(unsafe.Pointer(&size))); r != 0 {
return ""
}
return syscall.UTF16ToString(buf)
}
+141
View File
@@ -0,0 +1,141 @@
// Package webview2 finds the Microsoft Edge WebView2 Runtime as
// WebView2Loader.dll does. The Windows backend loads the runtime it finds,
// and `mygo doctor` reports it, so the two never disagree; it builds
// everywhere, and finds no installed runtime but on Windows.
package webview2
import (
"errors"
"fmt"
"os"
"path/filepath"
"runtime"
"strconv"
"strings"
)
// Download is where people get the runtime.
const Download = "https://go.microsoft.com/fwlink/p/?LinkId=2124703"
// channels are the runtime's EdgeUpdate channels, most stable first, the
// order WebView2Loader.dll tries them in.
var channels = []string{
"{F3017226-FE2A-4295-8BDF-00C3A9A7E4C5}", // Stable (Evergreen)
"{2CD8A007-E189-409D-A2C8-9AF4EF3C72AA}", // Beta
"{0D50BFEC-CD6A-4F9A-964C-C7416E3ACB10}", // Dev
"{65C35B14-6C1D-4122-AC46-7148CC9D6497}", // Canary
}
// A runtime's pieces: its browser process at the root of its directory, and
// its client library, which the loader calls, under EBWebView for the
// architecture of the process.
const (
browserExe = "msedgewebview2.exe"
clientDir = "EBWebView"
clientDLL = "EmbeddedBrowserWebView.dll"
)
var errNotInstalled = errors.New("the Microsoft Edge WebView2 Runtime is not installed; get it from " + Download)
// Find returns the directory of the runtime a window showing a web page
// gets, and whether it is a fixed version runtime, named by
// WEBVIEW2_BROWSER_EXECUTABLE_FOLDER, rather than an installed one. Without
// a runtime, the error says why.
func Find() (dir string, fixed bool, err error) {
return find(os.Getenv("WEBVIEW2_BROWSER_EXECUTABLE_FOLDER"), regString)
}
// find is Find with the environment's folder and the registry given: read
// returns a string value of the machine's (HKLM) or the user's (HKCU) key.
func find(fixed string, read func(machine bool, path, name string) string) (string, bool, error) {
if fixed != "" {
if ClientDLL(fixed) == "" {
return "", false, fmt.Errorf("WEBVIEW2_BROWSER_EXECUTABLE_FOLDER=%s holds no WebView2 Runtime: no %s, or no %s", fixed, browserExe, filepath.Join(clientDir, archDir(), clientDLL))
}
return fixed, true, nil
}
// EdgeUpdate records where it installed a channel's runtime, per machine
// and per user, and keeps the record after the files are gone.
stale := ""
for _, channel := range channels {
best, bestVersion := "", []int(nil)
for _, machine := range []bool{true, false} {
dir := read(machine, `SOFTWARE\Microsoft\EdgeUpdate\ClientState\`+channel, clientDir)
if dir == "" {
continue
}
if ClientDLL(dir) == "" {
if stale == "" {
stale = dir
}
continue
}
if v := parseVersion(filepath.Base(dir)); best == "" || compareVersions(v, bestVersion) > 0 {
best, bestVersion = dir, v
}
}
if best != "" {
return best, false, nil
}
}
if stale != "" {
return "", false, fmt.Errorf("the WebView2 Runtime registered at %s is missing or incomplete; reinstall it from %s", stale, Download)
}
return "", false, errNotInstalled
}
// ClientDLL returns the client library of the runtime in dir, or "" when
// dir holds no runtime. The library alone is none: the Edge browser keeps
// one beside itself, whose environments fail with ERROR_NOT_SUPPORTED, so
// the runtime's browser process must be there too.
func ClientDLL(dir string) string {
if _, err := os.Stat(filepath.Join(dir, browserExe)); err != nil {
return ""
}
p := filepath.Join(dir, clientDir, archDir(), clientDLL)
if _, err := os.Stat(p); err != nil {
return ""
}
return p
}
func archDir() string {
switch runtime.GOARCH {
case "arm64":
return "arm64"
case "386":
return "x86"
}
return "x64"
}
func parseVersion(s string) []int {
var v []int
for _, part := range strings.Split(s, ".") {
n, err := strconv.Atoi(part)
if err != nil {
return nil
}
v = append(v, n)
}
return v
}
func compareVersions(a, b []int) int {
for i := 0; i < len(a) || i < len(b); i++ {
var x, y int
if i < len(a) {
x = a[i]
}
if i < len(b) {
y = b[i]
}
if x != y {
if x < y {
return -1
}
return 1
}
}
return 0
}
+149
View File
@@ -0,0 +1,149 @@
package webview2
import (
"os"
"path/filepath"
"strings"
"testing"
)
func touch(t *testing.T, path string) {
t.Helper()
if err := os.MkdirAll(filepath.Dir(path), 0o755); err != nil {
t.Fatal(err)
}
if err := os.WriteFile(path, nil, 0o644); err != nil {
t.Fatal(err)
}
}
// runtimeDir makes a runtime's directory, with what the loader looks for.
func runtimeDir(t *testing.T, version string) string {
dir := filepath.Join(t.TempDir(), version)
touch(t, filepath.Join(dir, browserExe))
touch(t, filepath.Join(dir, clientDir, archDir(), clientDLL))
return dir
}
func TestClientDLL(t *testing.T) {
dir := runtimeDir(t, "154.0.4258.62")
if got, want := ClientDLL(dir), filepath.Join(dir, clientDir, archDir(), clientDLL); got != want {
t.Errorf("ClientDLL of a runtime = %q, want %q", got, want)
}
// The Edge browser's layout: the library without the runtime's browser
// process, whose environments fail with ERROR_NOT_SUPPORTED.
edge := t.TempDir()
touch(t, filepath.Join(edge, clientDir, archDir(), clientDLL))
if got := ClientDLL(edge); got != "" {
t.Errorf("ClientDLL of the library alone = %q, want none", got)
}
browser := t.TempDir()
touch(t, filepath.Join(browser, browserExe))
if got := ClientDLL(browser); got != "" {
t.Errorf("ClientDLL of the browser alone = %q, want none", got)
}
other := t.TempDir()
touch(t, filepath.Join(other, browserExe))
touch(t, filepath.Join(other, clientDir, "other", clientDLL))
if got := ClientDLL(other); got != "" {
t.Errorf("ClientDLL of another architecture's runtime = %q, want none", got)
}
}
func TestFind(t *testing.T) {
key := func(channel string) string { return `SOFTWARE\Microsoft\EdgeUpdate\ClientState\` + channel }
registry := func(values map[bool]map[string]string) func(bool, string, string) string {
return func(machine bool, path, name string) string {
if name != clientDir {
return ""
}
return values[machine][path]
}
}
older, newer := runtimeDir(t, "153.0.1.2"), runtimeDir(t, "154.0.4258.62")
beta := runtimeDir(t, "155.0.1.1")
gone := filepath.Join(t.TempDir(), "154.0.4258.62")
for _, tc := range []struct {
name string
fixed string
values map[bool]map[string]string
dir string
err string
}{
{name: "none", err: "not installed"},
{
name: "machine",
values: map[bool]map[string]string{true: {key(channels[0]): newer}},
dir: newer,
},
{
name: "newest of a channel",
values: map[bool]map[string]string{
true: {key(channels[0]): older},
false: {key(channels[0]): newer},
},
dir: newer,
},
{
name: "stable before beta",
values: map[bool]map[string]string{
true: {key(channels[0]): older, key(channels[1]): beta},
},
dir: older,
},
{
// EdgeUpdate keeps the record of a runtime whose files are gone.
name: "stale",
values: map[bool]map[string]string{true: {key(channels[0]): gone}},
err: gone,
},
{
name: "stale stable, beta installed",
values: map[bool]map[string]string{
true: {key(channels[0]): gone, key(channels[1]): beta},
},
dir: beta,
},
{name: "fixed", fixed: older, dir: older},
{
name: "fixed without a runtime",
fixed: gone,
values: map[bool]map[string]string{true: {key(channels[0]): newer}},
err: "WEBVIEW2_BROWSER_EXECUTABLE_FOLDER",
},
} {
t.Run(tc.name, func(t *testing.T) {
dir, fixed, err := find(tc.fixed, registry(tc.values))
if tc.err != "" {
if err == nil || !strings.Contains(err.Error(), tc.err) {
t.Fatalf("find = %q, %v; want an error naming %q", dir, err, tc.err)
}
return
}
if err != nil || dir != tc.dir || fixed != (tc.fixed != "") {
t.Errorf("find = %q, %v, %v; want %q, %v", dir, fixed, err, tc.dir, tc.fixed != "")
}
})
}
}
func TestCompareVersions(t *testing.T) {
for _, tc := range []struct {
a, b string
want int
}{
{"154.0.4258.62", "154.0.4258.62", 0},
{"155.0.1.1", "154.9.9.9", 1},
{"154.0.4258.62", "154.0.4258.100", -1},
{"154.0", "154.0.1", -1},
{"not-a-version", "1.0.0.0", -1},
} {
if got := compareVersions(parseVersion(tc.a), parseVersion(tc.b)); got != tc.want {
t.Errorf("compareVersions(%q, %q) = %d, want %d", tc.a, tc.b, got, tc.want)
}
}
}