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.
76 lines
2.0 KiB
Go
76 lines
2.0 KiB
Go
//go:build linux && !android && (amd64 || arm64)
|
|
|
|
package linux
|
|
|
|
import (
|
|
"fmt"
|
|
"net/url"
|
|
"unsafe"
|
|
|
|
"github.com/ebitengine/purego"
|
|
)
|
|
|
|
// Downloads: the web context reports them, WebKit asks each where to save
|
|
// the file, and reports how it ended ("failed" comes before "finished").
|
|
|
|
type download struct {
|
|
w *window
|
|
url, path string
|
|
err error
|
|
}
|
|
|
|
var (
|
|
downloads = map[ptr]*download{}
|
|
downloadsHooked bool
|
|
|
|
cbDownloadStarted, cbDownloadDestination, cbDownloadFinished, cbDownloadFailed ptr
|
|
)
|
|
|
|
func initDownloadCallbacks() {
|
|
cbDownloadStarted = purego.NewCallback(func(ctx, d, data ptr) {
|
|
w := theBackend.byWebView[webkitDownloadGetWebView(d)]
|
|
if w == nil {
|
|
return
|
|
}
|
|
downloads[d] = &download{w: w, url: goStr(webkitURIRequestGetURI(webkitDownloadGetRequest(d)))}
|
|
connect(d, "decide-destination", cbDownloadDestination, 0)
|
|
connect(d, "finished", cbDownloadFinished, 0)
|
|
connect(d, "failed", cbDownloadFailed, 0)
|
|
})
|
|
cbDownloadDestination = purego.NewCallback(func(d, suggested, data ptr) bool {
|
|
dl := downloads[d]
|
|
if dl == nil {
|
|
return false
|
|
}
|
|
dl.path = dl.w.h.DownloadStarted(dl.url, goStr(suggested))
|
|
if dl.path == "" {
|
|
delete(downloads, d)
|
|
webkitDownloadCancel(d)
|
|
return true
|
|
}
|
|
webkitDownloadSetAllowOverwrite(d, true)
|
|
webkitDownloadSetDestination(d, cs((&url.URL{Scheme: "file", Path: dl.path}).String()))
|
|
return true
|
|
})
|
|
cbDownloadFailed = purego.NewCallback(func(d, gerr, data ptr) {
|
|
if dl := downloads[d]; dl != nil {
|
|
// GError: domain, code, then the message.
|
|
dl.err = fmt.Errorf("mygo: download failed: %s", goStr(*(*ptr)(unsafe.Add(*(*unsafe.Pointer)(unsafe.Pointer(&gerr)), 8))))
|
|
}
|
|
})
|
|
cbDownloadFinished = purego.NewCallback(func(d, data ptr) {
|
|
if dl := downloads[d]; dl != nil {
|
|
delete(downloads, d)
|
|
dl.w.h.DownloadFinished(dl.url, dl.path, dl.err)
|
|
}
|
|
})
|
|
}
|
|
|
|
// hookDownloads listens to the downloads of the web context once.
|
|
func hookDownloads() {
|
|
if !downloadsHooked {
|
|
downloadsHooked = true
|
|
connect(webkitWebContextGetDefault(), "download-started", cbDownloadStarted, 0)
|
|
}
|
|
}
|