Files
arcrun-collector/cmd/arcrun-tray/embed_windows.go
T
Leo 5e122b47ec feat(t77-lite): Windows 合併成單一 exe——go:embed 把 collector 吃進 tray
leo 07-28:「Windows 解開有 2 個 exe,被瀏覽器擋住,如果只有 1 個,
我還可以把 exe 改成 e_e 讓朋友改回來,但現在這樣完全不行」。
做法:build-windows.sh 先編 collector.exe 到 tray 目錄供 //go:embed,
tray 啟動時 ensureEmbeddedCollector() sha256 比對後解壓到 ~/.arcrun-rag/bin/,
失敗 fallback 同層(舊版相容);Mac 走 build-tag no-op 完全不動。
驗收(總管親跑):PE32+ GUI exe/zip 僅 1 檔 16.9MB<20MB jsDelivr 上限/
collector 特徵字串在 exe 肚裡(grep=1)/Mac go build+test 全綠/tray 測試綠。
(實作=子 CC;build+驗收+commit=總管)
2026-07-28 12:15:13 +08:00

35 lines
975 B
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
//go:build windows
package main
import (
"crypto/sha256"
_ "embed"
"os"
"path/filepath"
)
//go:embed arcrun-collector.exe
var collectorExeBytes []byte
// ensureEmbeddedCollector 把內嵌的 collector.exe 解壓到 ~/.arcrun-rag/bin/。
// 用 sha256 比對避免每次啟動都重寫磁碟;回傳可執行的絕對路徑。
// t77-liteleo 2026-07-28:「Windows 解開有 2 個 exe 被瀏覽器擋住;如果只有 1 個,
// 我還可以把 exe 改成 e_e 讓朋友改回來」)
func ensureEmbeddedCollector() (string, error) {
dest := filepath.Join(appDir(), "bin", "arcrun-collector.exe")
embedded := sha256.Sum256(collectorExeBytes)
if existing, err := os.ReadFile(dest); err == nil {
if sha256.Sum256(existing) == embedded {
return dest, nil
}
}
if err := os.MkdirAll(filepath.Dir(dest), 0o755); err != nil {
return "", err
}
if err := os.WriteFile(dest, collectorExeBytes, 0o755); err != nil {
return "", err
}
return dest, nil
}