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
+146
@@ -0,0 +1,146 @@
|
||||
//go:build darwin && !ios
|
||||
|
||||
package darwin
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/ebitengine/purego/objc"
|
||||
"github.com/egoist/mygo/internal/platform"
|
||||
)
|
||||
|
||||
// contentRules is the code of content rules, which LinkContentRules
|
||||
// links: the backend's methods are linked into every app, and only call
|
||||
// it.
|
||||
var contentRules struct {
|
||||
compile func(b *Backend, id, identifier, rules string, done func(any, error))
|
||||
set func(w *window, lists []any)
|
||||
}
|
||||
|
||||
// LinkContentRules links the code of content rules, when the app first
|
||||
// compiles rules.
|
||||
func LinkContentRules() {
|
||||
contentRules.compile, contentRules.set = compileContentRules, setContentRules
|
||||
}
|
||||
|
||||
func (a appController) CompileContentRules(id, identifier, rules string, done func(any, error)) {
|
||||
if contentRules.compile == nil {
|
||||
done(nil, platform.ErrUnsupported)
|
||||
return
|
||||
}
|
||||
contentRules.compile(a.b, id, identifier, rules, done)
|
||||
}
|
||||
|
||||
func (w *window) SetContentRules(lists []any) {
|
||||
if contentRules.set != nil {
|
||||
contentRules.set(w, lists)
|
||||
}
|
||||
}
|
||||
|
||||
// compileContentRules makes a WKContentRuleList in the default
|
||||
// WKContentRuleListStore, which keeps compiled lists in the app's
|
||||
// container across launches: the list kept as identifier, else one
|
||||
// compiled from rules, after which the lists of id's earlier rules go.
|
||||
// The handle is the list, retained for good: a page may apply it at any
|
||||
// time.
|
||||
func compileContentRules(b *Backend, contentID, identifier, rules string, done func(any, error)) {
|
||||
if class("WKContentRuleListStore") == 0 {
|
||||
done(nil, fmt.Errorf("content rules need macOS 10.13 or newer: %w", platform.ErrUnsupported))
|
||||
return
|
||||
}
|
||||
finish := func(list, err id) {
|
||||
switch {
|
||||
case list != 0:
|
||||
done(retain(list), nil)
|
||||
case err != 0:
|
||||
done(nil, contentRulesError(err))
|
||||
default:
|
||||
done(nil, fmt.Errorf("WebKit made no list"))
|
||||
}
|
||||
}
|
||||
store := retain(send(class("WKContentRuleListStore"), "defaultStore"))
|
||||
compile := func() {
|
||||
compiled := newBlock(func(_ objc.Block, list, err id) {
|
||||
retain(list)
|
||||
retain(err)
|
||||
b.runOnMain(func() {
|
||||
defer release(store)
|
||||
defer release(list)
|
||||
defer release(err)
|
||||
if list != 0 {
|
||||
removeStaleContentRules(store, contentID, identifier)
|
||||
}
|
||||
finish(list, err)
|
||||
})
|
||||
})
|
||||
send(store, "compileContentRuleListForIdentifier:encodedContentRuleList:completionHandler:",
|
||||
uintptr(nsString(identifier)), uintptr(nsString(rules)), uintptr(compiled))
|
||||
compiled.Release()
|
||||
}
|
||||
withPool(func() {
|
||||
found := newBlock(func(_ objc.Block, list, _ id) {
|
||||
retain(list)
|
||||
b.runOnMain(func() {
|
||||
defer release(list)
|
||||
if list == 0 {
|
||||
withPool(compile)
|
||||
return
|
||||
}
|
||||
release(store)
|
||||
finish(list, 0)
|
||||
})
|
||||
})
|
||||
send(store, "lookUpContentRuleListForIdentifier:completionHandler:", uintptr(nsString(identifier)), uintptr(found))
|
||||
found.Release()
|
||||
})
|
||||
}
|
||||
|
||||
// contentRulesError describes an error of the store, which puts what is
|
||||
// wrong with the rules in NSHelpAnchorErrorKey.
|
||||
func contentRulesError(err id) error {
|
||||
info := send(err, "userInfo")
|
||||
if reason := send(info, "objectForKey:", uintptr(nsString("NSHelpAnchor"))); reason != 0 {
|
||||
return fmt.Errorf("%s", goString(reason))
|
||||
}
|
||||
return nsError(err)
|
||||
}
|
||||
|
||||
// removeStaleContentRules removes the lists the store keeps for id but
|
||||
// current.
|
||||
func removeStaleContentRules(store id, contentID, current string) {
|
||||
retain(store)
|
||||
listed := newBlock(func(_ objc.Block, identifiers id) {
|
||||
var stale []string
|
||||
withPool(func() {
|
||||
for _, s := range arrayItems(identifiers) {
|
||||
if name := goString(s); platform.StaleContentRules(contentID, current, name) {
|
||||
stale = append(stale, name)
|
||||
}
|
||||
}
|
||||
for _, name := range stale {
|
||||
removed := newBlock(func(objc.Block, id) {})
|
||||
send(store, "removeContentRuleListForIdentifier:completionHandler:", uintptr(nsString(name)), uintptr(removed))
|
||||
removed.Release()
|
||||
}
|
||||
})
|
||||
release(store)
|
||||
})
|
||||
send(store, "getAvailableContentRuleListIdentifiers:", uintptr(listed))
|
||||
listed.Release()
|
||||
}
|
||||
|
||||
// setContentRules replaces the lists of the window's content controller,
|
||||
// which WebKit applies to the loads from then on.
|
||||
func setContentRules(w *window, lists []any) {
|
||||
if w.ucc == 0 || w.closed {
|
||||
return
|
||||
}
|
||||
withPool(func() {
|
||||
send(w.ucc, "removeAllContentRuleLists")
|
||||
for _, l := range lists {
|
||||
if list, ok := l.(id); ok {
|
||||
send(w.ucc, "addContentRuleList:", uintptr(list))
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
Reference in new issue
Block a user