Files
arcrun-collector/cmd/arcrun-app/build-win.sh
T
Leo d80e9e1357 t196:Windows 版重編(Wails)+MSIX 打包——在 Mac 上交叉編譯,不需 Windows 機器
leo 08-05:「Windows 版一定要重編,因為我只有 Mac,我需要人家測試,
要做到最完善不要給人家找麻煩,然後當測試者給我截圖安裝成功就要提交 ms store」

## 缺口
Windows 打包腳本全在**舊的 arcrun-tray(fyne 版)**,
新的 arcrun-app(Wails,t193/t194 整批 UI 重做)**完全沒有 Windows 產線**
⇒ Windows 封測者只能拿到 v0.15.7 的舊 fyne 版。

## 新增
· tray_windows.go — Windows 系統匣(energye/systray)
  行為與 macOS 版逐項對齊:左鍵開視窗/右鍵只有「結束 Arcrun」/關窗不結束。
  ⚠️ 為什麼 Windows 能用 systray 而 macOS 不能(wiki 有全文):
     macOS 上它在 Wails 之下根本不建托盤(setInternalLoop 只在 systray.Run() 呼叫),
     改用 systray.Run() 又搶 macOS 主 loop ⇒ macOS 最後走原生 NSStatusItem。
     **Windows 走 Win32 訊息迴圈,沒有主執行緒限制**,所以這裡用 systray 是對的,
     不是抄 macOS 失敗的做法。
  trayApp 與 ICO 都在本檔自帶(tray_darwin.go 有 //go:build darwin,Windows 看不到)。
· build-win.sh  — 交叉編譯 zip(CGO_ENABLED=1 + mingw-w64,Wails Windows 要 WebView2 綁定)
  **同綑 collector.exe**:daemon 本體是 collector direct,沒同綑=裝了不會同步
  (t194 在 Mac 版就漏過一次)。supervise.go 的 collectorBinPath() 已處理 .exe 副檔名。
· build-msix.sh — MS Store 用的 msix(沿用 makemsix,Mac 上就打得出來)
  與舊 fyne 版差別:**Wails 是兩個 exe**,兩個都要進 msix root。
  Identity 三值走環境變數(要與 Partner Center 完全一致),預設佔位並印警告。

## 驗
· Windows zip:兩個檔都是正牌 PE(MZ 標頭)/Arcrun.exe 11.4MB+collector.exe 16.1MB
· 退避修復確實編進 Windows 版(不剝符號重編一份,grep 到 MarkFailed/ShouldRetry/
  retrySkipReason 各 2 處;出貨版用 -s -w 剝符號故查不到,屬預期)
· MSIX:16 檔、含 AppxBlockMap;zip 回讀兩個 exe 的 sha256 與原檔**逐一相符**;
  manifest Executable="Arcrun.exe"、Version=0.18.4.0
· **macOS 版不受影響**:編譯通過、三支機械閘全過

## 兩個踩到的坑(已修)
· zip 用相對路徑在 cd 後失效(zip I/O error,fallback 湊巧成功但不可靠)⇒ 改絕對路徑
· 全形括號緊接變數會被當成變數名(腳本自己的註解就警告過)⇒ 改 ${VAR}

## 殘項
· Identity 仍是 PLACEHOLDER ⇒ **這顆 msix 還不能送 Store**,等 leo 給 Partner Center 三值
· 未在真 Windows 上跑過(誠實界定:只證明編得出來,不證明跑起來對)
2026-08-05 15:50:57 +08:00

63 lines
2.8 KiB
Bash
Executable File
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.
#!/usr/bin/env bash
# build-win.sh — 打包 Arcrun Windows 版(Wailst1962026-08-05
#
# leo 08-05:「Windows 版一定要重編,因為我只有 Mac,我需要人家測試,
# 要做到最完善不要給人家找麻煩」
#
# 🎯 **在 Mac 上就能交叉編譯**,不需要 Windows 機器/Docker。
# 條件只有一個:`brew install mingw-w64`(提供 x86_64-w64-mingw32-gcc)。
# Wails 的 Windows 版要 CGoWebView2 綁定),所以 CGO_ENABLED=1 + mingw。
#
# 與 build-mac.sh 同一個要點:**必須把 collector 同綑進去**。
# daemon 的本體是 `collector direct`(監看/萃卡/上傳),App 只是門面;
# 沒同綑 ⇒ 使用者裝了也不會同步(t194 在 Mac 版就漏過一次)。
#
# ⚠️ 誠實界定(沿用 build-windows.sh 的自陳):
# 本腳本只證明「**編得出來**」,不證明「**跑起來對**」。
# 托盤圖示會不會出現、WebView2 有沒有裝、SmartScreen 攔截行為,
# **只有真的在 Windows 上跑才驗得到**——那一步歸 leo/封測者真機。
set -euo pipefail
cd "$(dirname "$0")"
export PATH="$PATH:$(go env GOPATH)/bin"
VERSION="${VERSION:-$(git describe --tags --always --dirty 2>/dev/null || echo dev)}"
BUILD_TIME="$(date '+%Y%m%d-%H%M')"
echo "🏷 版本:${VERSION}build ${BUILD_TIME}"
command -v x86_64-w64-mingw32-gcc >/dev/null 2>&1 || {
echo "❌ 缺 mingw-w64Wails Windows 版需要 CGo 交叉編譯器)"
echo " 裝一次就好:brew install mingw-w64"
exit 1
}
echo "① 編 collector.exe(同綑執行檔,純 stdlib、CGO_ENABLED=0"
( cd ../.. && GOOS=windows GOARCH=amd64 CGO_ENABLED=0 \
go build -ldflags "-s -w" -o "cmd/arcrun-app/arcrun-collector.exe" . )
echo "② wails buildwindows/amd64CGo 走 mingw"
CGO_ENABLED=1 CC=x86_64-w64-mingw32-gcc \
wails build -platform windows/amd64 -clean \
-ldflags "-X main.version=${VERSION} -X main.buildTime=${BUILD_TIME}"
OUT="dist"; mkdir -p "$OUT"
STAGE="$(mktemp -d)/Arcrun"
mkdir -p "$STAGE"
echo "③ 同綑 collector.exeApp 用 os.Executable() 找同層,見 supervise.go"
cp build/bin/arcrun-app.exe "$STAGE/Arcrun.exe"
cp arcrun-collector.exe "$STAGE/arcrun-collector.exe"
echo "④ 打包 zip"
# 用絕對路徑:下面會 cd 進暫存目錄打包,相對路徑會找不到(實撞:zip I/O error)。
ZIP="$(cd "$OUT" && pwd)/ArcrunRAG-win-unsigned-${VERSION}.zip"
rm -f "$ZIP"
( cd "$(dirname "$STAGE")" && zip -qr "$ZIP" "Arcrun" )
rm -rf "$(dirname "$STAGE")"
SIZE=$(ls -lh "$ZIP" | awk '{print $5}')
echo "✅ 完成:${ZIP}${SIZE}"
echo
echo "🔬 使用者流程:解壓縮 → 執行 Arcrun.exe"
echo " ⚠️ 未簽章 ⇒ SmartScreen 會攔(「更多資訊」→「仍要執行」)。"
echo " 要免除這一步=上 MS Store(見 build-msix.sh)或買 EV 憑證。"