feat: 拆分 macOS 架构安装包并内置浏览器运行时

将 macOS 安装包拆分为 arm64 与 amd64 两个独立产物,每个安装包只携带对应架构的服务、托盘程序、Playwright driver 和 Chromium。

调整桌面端 CI,在构建阶段预下载并组装 Playwright runtime;服务启动时按当前进程架构解析 runtime 根目录,避免安装后联网下载 Chromium。

移除 Windows/macOS 安装阶段的 browser-install 调用和托盘中的安装/修复 Chromium 菜单,保留 Linux 安装脚本的既有流程。

升级 Playwright Go 依赖到 v0.6100.0,并迁移导入路径;仅按本次授权修改 CAPTCHA 相关文件的 import 行,不改变 CAPTCHA 行为。

验证:go test ./...、go vet ./...、macOS 安装脚本语法、Workflow YAML 语法、Windows amd64 交叉编译及两个 macOS pkg 的本地组装。
This commit is contained in:
Christ committed 2026-08-12 01:09:59 +08:00
1 parent d4e9717570
commit 1ac6912c7b
24 files changed
+242 -93

No files matched your search

+38 -18
View File
@@ -31,24 +31,25 @@ import (
)
type serverOptions struct {
dbPath string
dbURL string
addr string
webDir string
workDir string
playwrightDriverDir string
playwrightBrowserDir string
dataKeyFile string
secure bool
noBrowser bool
verbose bool
logLevel string
logFormat string
initAdmin bool
ensureAdmin bool
adminEmail string
adminPassword string
service bool
dbPath string
dbURL string
addr string
webDir string
workDir string
playwrightRuntimeRoot string
playwrightDriverDir string
playwrightBrowserDir string
dataKeyFile string
secure bool
noBrowser bool
verbose bool
logLevel string
logFormat string
initAdmin bool
ensureAdmin bool
adminEmail string
adminPassword string
service bool
}
const (
@@ -90,6 +91,7 @@ func parseOptions() serverOptions {
flag.StringVar(&opts.addr, "addr", ":8080", "HTTP 监听地址")
flag.StringVar(&opts.webDir, "web", "", "前端静态资源目录(含 index.html)")
flag.StringVar(&opts.workDir, "workdir", "", "服务工作目录;用于桌面服务固定数据和浏览器目录")
flag.StringVar(&opts.playwrightRuntimeRoot, "playwright-runtime-root", "", "随安装包分发的 Playwright runtime 根目录")
flag.StringVar(&opts.playwrightDriverDir, "playwright-driver-dir", "", "Playwright driver 目录")
flag.StringVar(&opts.playwrightBrowserDir, "playwright-browser-dir", "", "Playwright 浏览器缓存目录")
flag.StringVar(&opts.dataKeyFile, "data-key-file", "", "XIANYU_DATA_KEY 持久化文件;不存在时自动生成")
@@ -115,6 +117,7 @@ func runServer(parent context.Context, opts serverOptions) error {
if err != nil {
return err
}
applyPlaywrightRuntimeRoot(&opts)
if dataDir != "" {
if err := os.MkdirAll(dataDir, 0o700); err != nil {
return fmt.Errorf("创建应用数据目录失败: %w", err)
@@ -276,6 +279,23 @@ func runServer(parent context.Context, opts serverOptions) error {
return runErr
}
func applyPlaywrightRuntimeRoot(opts *serverOptions) {
if opts == nil {
return
}
root := strings.TrimSpace(opts.playwrightRuntimeRoot)
if root == "" {
return
}
archRoot := filepath.Join(root, runtime.GOARCH)
if opts.playwrightDriverDir == "" {
opts.playwrightDriverDir = filepath.Join(archRoot, "playwright-driver")
}
if opts.playwrightBrowserDir == "" {
opts.playwrightBrowserDir = filepath.Join(archRoot, "playwright-browsers")
}
}
// resolveDataDir 返回桌面端的标准用户数据目录。
// Linux/Docker 保留原有相对路径行为;macOS 和 Windows 在没有显式 -workdir
// 时使用当前用户的系统配置目录,避免把具体用户路径写进安装包或代码。
+13
View File
@@ -4,6 +4,7 @@ import (
"context"
"os"
"path/filepath"
"runtime"
"testing"
"xianyu-go/internal/db"
@@ -91,3 +92,15 @@ func TestResolveDBPathPreservesCustomPath(t *testing.T) {
t.Fatalf("custom database path changed: got %q want %q", got, custom)
}
}
func TestPlaywrightRuntimeRootUsesProcessArchitecture(t *testing.T) {
opts := serverOptions{playwrightRuntimeRoot: filepath.Join(t.TempDir(), "playwright-runtime")}
applyPlaywrightRuntimeRoot(&opts)
wantRoot := filepath.Join(opts.playwrightRuntimeRoot, runtime.GOARCH)
if opts.playwrightDriverDir != filepath.Join(wantRoot, "playwright-driver") {
t.Fatalf("driver 目录=%q", opts.playwrightDriverDir)
}
if opts.playwrightBrowserDir != filepath.Join(wantRoot, "playwright-browsers") {
t.Fatalf("browser 目录=%q", opts.playwrightBrowserDir)
}
}