Files
openchamber-android-native/third_party/mygo/internal/prefetch/main.go
T
OpenChamber 6c0ee61750 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.
2026-11-18 13:22:59 +08:00

82 lines
2.3 KiB
Go

// Command prefetch downloads into the user's cache what this repository's
// tests otherwise download there while they run: the native libraries that
// the plugins name in their mygo-plugin.json, for this platform, and on
// Windows the NSIS that mygo build uses. CI runs it before `go test` and
// keeps what it downloads in the Actions cache, under a key of the files
// that pin them, so that the tests do not depend on the network:
//
// go run ./internal/prefetch
//
// It downloads them where the plugins and the CLI look:
// <cache>/mygo/natives/<sha256>/<name> and <cache>/mygo/nsis-<version>.
package main
import (
"context"
"encoding/json"
"fmt"
"log"
"os"
"path/filepath"
"runtime"
"github.com/egoist/mygo/internal/download"
"github.com/egoist/mygo/internal/nsis"
)
func main() {
log.SetFlags(0)
log.SetPrefix("prefetch: ")
cache, err := os.UserCacheDir()
if err != nil {
log.Fatal(err)
}
ctx := context.Background()
manifests, err := filepath.Glob(filepath.Join("plugins", "*", "mygo-plugin.json"))
if err != nil {
log.Fatal(err)
}
if len(manifests) == 0 {
log.Fatal("no plugins/*/mygo-plugin.json: run it at the root of the repository")
}
target := runtime.GOOS + "-" + runtime.GOARCH
for _, manifest := range manifests {
data, err := os.ReadFile(manifest)
if err != nil {
log.Fatal(err)
}
var n struct {
Libraries []struct {
Name string `json:"name"`
Files map[string]struct {
Name string `json:"name"`
URL string `json:"url"`
SHA256 string `json:"sha256"`
} `json:"files"`
} `json:"libraries"`
}
if err := json.Unmarshal(data, &n); err != nil {
log.Fatalf("%s: %v", manifest, err)
}
for _, l := range n.Libraries {
f, ok := l.Files[target]
if !ok {
fmt.Printf("%s has no build for %s\n", l.Name, target)
continue
}
path := filepath.Join(cache, "mygo", "natives", f.SHA256, f.Name)
if err := download.Cached(ctx, download.File{URL: f.URL, SHA256: f.SHA256}, path); err != nil {
log.Fatalf("%s: %v", l.Name, err)
}
fmt.Printf("%s: %s\n", l.Name, path)
}
}
if runtime.GOOS == "windows" {
makensis, err := nsis.Download(ctx, nsis.Dir(), func(url string) download.File { return download.File{URL: url} })
if err != nil {
log.Fatalf("NSIS: %v", err)
}
fmt.Printf("NSIS %s: %s\n", nsis.Release.Version, makensis)
}
}