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
@@ -0,0 +1,179 @@
|
||||
//go:build windows && (amd64 || arm64)
|
||||
|
||||
package windows
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"sync"
|
||||
"syscall"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
// envOptions is an ICoreWebView2EnvironmentOptions, a COM object of ours
|
||||
// that the WebView2 environment reads its options from as it is created:
|
||||
// the language of the browser, which is the language of its own texts (the
|
||||
// context menus, the dialogs of pages) and the first of the pages'
|
||||
// navigator.languages and Accept-Language, further arguments of the
|
||||
// browser (browserArguments) and, when MyGo loads the runtime itself,
|
||||
// the arguments of WEBVIEW2_ADDITIONAL_BROWSER_ARGUMENTS. Its other
|
||||
// options are those of an environment created without options: no version
|
||||
// the runtime must be, no single sign-on. It implements no later version
|
||||
// of the interface, which the environment asks for and does without.
|
||||
//
|
||||
// The objects share one vtable, whose callbacks are created once; they
|
||||
// stay reachable through envOptionsLive until COM releases them.
|
||||
type envOptions struct {
|
||||
vtbl *[11]uintptr
|
||||
refs int32
|
||||
language []uint16 // NUL-terminated, or nil
|
||||
args []uint16 // NUL-terminated, or nil
|
||||
}
|
||||
|
||||
var (
|
||||
iidICoreWebView2EnvironmentOptions = guid("2fde08a8-1e9a-4766-8c05-95a9ceb9d1c5")
|
||||
|
||||
envOptionsVtbl [11]uintptr
|
||||
envOptionsOnce sync.Once
|
||||
envOptionsMu sync.Mutex
|
||||
envOptionsLive = map[uintptr]*envOptions{}
|
||||
)
|
||||
|
||||
const ePointer = 0x80004003 // E_POINTER
|
||||
|
||||
// newEnvOptions returns an options object of language and args, either
|
||||
// of which may be "", holding one reference, which the caller releases.
|
||||
func newEnvOptions(language, args string) uintptr {
|
||||
envOptionsOnce.Do(func() {
|
||||
str := func(get func(o *envOptions) []uint16) uintptr {
|
||||
return syscall.NewCallback(func(this, out uintptr) uintptr {
|
||||
if out == 0 {
|
||||
return ePointer
|
||||
}
|
||||
*(*uintptr)(native(out)) = coTaskString(get(envOptionsOf(this)))
|
||||
return sOK
|
||||
})
|
||||
}
|
||||
ignore := syscall.NewCallback(func(this, value uintptr) uintptr { return sOK })
|
||||
envOptionsVtbl = [11]uintptr{
|
||||
syscall.NewCallback(func(this, riid, out uintptr) uintptr {
|
||||
if out == 0 {
|
||||
return ePointer
|
||||
}
|
||||
iid := *(*GUID)(native(riid))
|
||||
if iid != iidIUnknown && iid != iidICoreWebView2EnvironmentOptions {
|
||||
*(*uintptr)(native(out)) = 0
|
||||
return eNoInterface
|
||||
}
|
||||
*(*uintptr)(native(out)) = this
|
||||
envOptionsRef(this, 1)
|
||||
return sOK
|
||||
}),
|
||||
syscall.NewCallback(func(this uintptr) uintptr { return uintptr(envOptionsRef(this, 1)) }),
|
||||
syscall.NewCallback(func(this uintptr) uintptr { return uintptr(envOptionsRef(this, -1)) }),
|
||||
str(func(o *envOptions) []uint16 { // get_AdditionalBrowserArguments
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
return o.args
|
||||
}),
|
||||
ignore, // put_AdditionalBrowserArguments
|
||||
str(func(o *envOptions) []uint16 { // get_Language
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
return o.language
|
||||
}),
|
||||
ignore, // put_Language
|
||||
// The version of the runtime the app needs at least, which the
|
||||
// official loader picks a runtime by: as Microsoft's options
|
||||
// class does, never none. MyGo needs no newer one than the
|
||||
// first release of WebView2.
|
||||
str(func(*envOptions) []uint16 { return targetBrowserVersion }), // get_TargetCompatibleBrowserVersion
|
||||
ignore, // put_TargetCompatibleBrowserVersion
|
||||
syscall.NewCallback(func(this, out uintptr) uintptr { // get_AllowSingleSignOnUsingOSPrimaryAccount
|
||||
if out == 0 {
|
||||
return ePointer
|
||||
}
|
||||
*(*int32)(native(out)) = 0
|
||||
return sOK
|
||||
}),
|
||||
ignore, // put_AllowSingleSignOnUsingOSPrimaryAccount
|
||||
}
|
||||
})
|
||||
o := &envOptions{vtbl: &envOptionsVtbl, refs: 1}
|
||||
if language != "" {
|
||||
o.language = utf16z(chromiumLanguage(language))
|
||||
}
|
||||
if args != "" {
|
||||
o.args = utf16z(args)
|
||||
}
|
||||
p := uintptr(unsafe.Pointer(o))
|
||||
envOptionsMu.Lock()
|
||||
envOptionsLive[p] = o
|
||||
envOptionsMu.Unlock()
|
||||
return p
|
||||
}
|
||||
|
||||
func envOptionsOf(this uintptr) *envOptions {
|
||||
envOptionsMu.Lock()
|
||||
defer envOptionsMu.Unlock()
|
||||
return envOptionsLive[this]
|
||||
}
|
||||
|
||||
func envOptionsRef(this uintptr, delta int32) int32 {
|
||||
envOptionsMu.Lock()
|
||||
defer envOptionsMu.Unlock()
|
||||
o := envOptionsLive[this]
|
||||
if o == nil {
|
||||
return 0
|
||||
}
|
||||
o.refs += delta
|
||||
if o.refs <= 0 {
|
||||
delete(envOptionsLive, this)
|
||||
return 0
|
||||
}
|
||||
return o.refs
|
||||
}
|
||||
|
||||
// coTaskString returns a copy of a NUL-terminated string that the caller
|
||||
// frees with CoTaskMemFree, as COM getters of strings return them, or 0
|
||||
// for none.
|
||||
func coTaskString(s []uint16) uintptr {
|
||||
if len(s) == 0 {
|
||||
return 0
|
||||
}
|
||||
p, _, _ := procCoTaskMemAlloc.Call(uintptr(len(s) * 2))
|
||||
if p == 0 {
|
||||
return 0
|
||||
}
|
||||
copy(unsafe.Slice((*uint16)(native(p)), len(s)), s)
|
||||
return p
|
||||
}
|
||||
|
||||
// targetBrowserVersion is the version of the first release of WebView2's
|
||||
// runtime.
|
||||
var targetBrowserVersion = utf16z("86.0.616.0")
|
||||
|
||||
// chromiumLanguage returns the language the browser of WebView2 knows a
|
||||
// tag by: Chromium names the scripts of Chinese by the regions that write
|
||||
// them, zh-CN and zh-TW, and reads any other zh as zh-CN.
|
||||
func chromiumLanguage(tag string) string {
|
||||
parts := strings.Split(tag, "-")
|
||||
if !strings.EqualFold(parts[0], "zh") {
|
||||
return tag
|
||||
}
|
||||
for _, p := range parts[1:] {
|
||||
switch strings.ToUpper(p) {
|
||||
case "HK", "MO":
|
||||
return "zh-" + strings.ToUpper(p)
|
||||
case "TW":
|
||||
return "zh-TW"
|
||||
}
|
||||
}
|
||||
for _, p := range parts[1:] {
|
||||
if strings.EqualFold(p, "Hant") {
|
||||
return "zh-TW"
|
||||
}
|
||||
}
|
||||
return "zh-CN"
|
||||
}
|
||||
Reference in new issue
Block a user