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

+43 -2
View File
@@ -1,5 +1,5 @@
// Package browser 用 playwright-go 在进程内驱动 Chromium。
// 首次使用时自动下载 Chromium(playwright.Install),无需手动启动外部服务。
// 安装包提供预置 runtime;开发环境没有预置 runtime 时才自动下载。
package browser
import (
@@ -10,11 +10,13 @@ import (
"net/http"
"net/http/httptest"
"os"
"path/filepath"
"runtime"
"strings"
"sync"
"time"
"github.com/playwright-community/playwright-go"
"github.com/mxschmitt/playwright-go"
"golang.org/x/sync/singleflight"
"xianyu-go/internal/xianyu"
@@ -58,6 +60,42 @@ func skipPlaywrightBrowserDownload() bool {
}
}
func packagedPlaywrightRuntimeReady() bool {
driverDir := strings.TrimSpace(os.Getenv("PLAYWRIGHT_DRIVER_PATH"))
if driverDir == "" {
return false
}
nodeName := "node"
if runtime.GOOS == "windows" {
nodeName = "node.exe"
}
for _, path := range []string{
filepath.Join(driverDir, nodeName),
filepath.Join(driverDir, "package", "cli.js"),
} {
if _, err := os.Stat(path); err != nil {
return false
}
}
if strings.TrimSpace(os.Getenv("PLAYWRIGHT_CHROMIUM_EXECUTABLE_PATH")) != "" {
return true
}
browserDir := strings.TrimSpace(os.Getenv("PLAYWRIGHT_BROWSERS_PATH"))
if browserDir == "" {
return false
}
matches, err := filepath.Glob(filepath.Join(browserDir, "chromium-*"))
if err != nil {
return false
}
for _, match := range matches {
if info, statErr := os.Stat(match); statErr == nil && info.IsDir() {
return true
}
}
return false
}
// Manager 管理浏览器生命周期与按账号复用的上下文池。
type Manager struct {
pw *playwright.Playwright
@@ -108,6 +146,9 @@ func NewManager(logger *slog.Logger) *Manager {
renewLocks: make(map[string]*sync.Mutex),
renewSlots: make(chan struct{}, 3),
installFn: func() error {
if packagedPlaywrightRuntimeReady() {
return nil
}
opts := &playwright.RunOptions{
Browsers: []string{"chromium"},
Verbose: false,