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

+34 -8
View File
@@ -99,6 +99,16 @@ jobs:
go build -trimpath -ldflags "-s -w" -o dist/windows/browser-install.exe ./cmd/browser-install
go build -trimpath -ldflags "-s -w -H=windowsgui" -o dist/windows/xianyu-tray.exe ./cmd/tray
- name: 预下载 Windows Chromium runtime
shell: pwsh
run: |
New-Item -ItemType Directory -Force -Path dist/windows/playwright-runtime/amd64/playwright-driver | Out-Null
New-Item -ItemType Directory -Force -Path dist/windows/playwright-runtime/amd64/playwright-browsers | Out-Null
& dist/windows/browser-install.exe `
-driver-dir "$PWD/dist/windows/playwright-runtime/amd64/playwright-driver" `
-browser-dir "$PWD/dist/windows/playwright-runtime/amd64/playwright-browsers"
if ($LASTEXITCODE -ne 0) { throw 'Windows Playwright runtime 下载失败' }
- name: 导入 Windows 签名证书
shell: pwsh
env:
@@ -119,7 +129,7 @@ jobs:
run: |
& packaging/windows/sign.ps1 `
-PfxPath $env:WINDOWS_SIGNING_PFX_PATH `
-Files 'dist/windows/xianyu-server.exe','dist/windows/browser-install.exe','dist/windows/xianyu-tray.exe'
-Files 'dist/windows/xianyu-server.exe','dist/windows/xianyu-tray.exe'
- name: 安装 Inno Setup
shell: pwsh
@@ -151,7 +161,7 @@ jobs:
env:
APP_VERSION: ${{ env.APP_VERSION }}
run: |
Compress-Archive -Path dist/windows/xianyu-server.exe,dist/windows/browser-install.exe,dist/windows/xianyu-tray.exe -DestinationPath "dist/windows/Ydisks-Xianyu-Helper-${env:APP_VERSION}-binaries.zip"
Compress-Archive -Path dist/windows/xianyu-server.exe,dist/windows/xianyu-tray.exe -DestinationPath "dist/windows/Ydisks-Xianyu-Helper-${env:APP_VERSION}-binaries.zip"
- name: 上传 Windows 安装包
uses: actions/upload-artifact@v7
@@ -194,9 +204,22 @@ jobs:
GOOS=darwin GOARCH="$arch" CGO_ENABLED=1 go build -trimpath -ldflags='-s -w' -o "dist/macos/$arch/browser-install" ./cmd/browser-install
GOOS=darwin GOARCH="$arch" CGO_ENABLED=1 go build -trimpath -ldflags='-s -w' -o "dist/macos/$arch/xianyu-tray" ./cmd/tray
done
lipo -create dist/macos/arm64/xianyu-server dist/macos/amd64/xianyu-server -output dist/macos/xianyu-server
lipo -create dist/macos/arm64/browser-install dist/macos/amd64/browser-install -output dist/macos/browser-install
lipo -create dist/macos/arm64/xianyu-tray dist/macos/amd64/xianyu-tray -output dist/macos/xianyu-tray
- name: 预下载 macOS Chromium runtime
run: |
set -Eeuo pipefail
mkdir -p dist/macos/playwright-runtime/arm64/playwright-driver
mkdir -p dist/macos/playwright-runtime/arm64/playwright-browsers
mkdir -p dist/macos/playwright-runtime/amd64/playwright-driver
mkdir -p dist/macos/playwright-runtime/amd64/playwright-browsers
PLAYWRIGHT_HOST_PLATFORM_OVERRIDE=mac14-arm64 \
dist/macos/arm64/browser-install \
-driver-dir "$PWD/dist/macos/playwright-runtime/arm64/playwright-driver" \
-browser-dir "$PWD/dist/macos/playwright-runtime/arm64/playwright-browsers"
PLAYWRIGHT_HOST_PLATFORM_OVERRIDE=mac14 \
arch -x86_64 dist/macos/amd64/browser-install \
-driver-dir "$PWD/dist/macos/playwright-runtime/amd64/playwright-driver" \
-browser-dir "$PWD/dist/macos/playwright-runtime/amd64/playwright-browsers"
- name: 导入 macOS 签名证书
env:
@@ -231,17 +254,20 @@ jobs:
security unlock-keychain -p "$keychain_password" "$keychain_path"
echo "MACOS_SIGNING_KEYCHAIN=$keychain_path" >> "$GITHUB_ENV"
- name: 构建 macOS pkg
- name: 构建 macOS arm64 与 amd64 安装包
env:
MACOS_SIGNING_IDENTITY: ${{ secrets.MACOS_SIGNING_IDENTITY }}
MACOS_INSTALLER_SIGNING_IDENTITY: ${{ secrets.MACOS_INSTALLER_SIGNING_IDENTITY }}
run: |
set -Eeuo pipefail
chmod +x packaging/macos/build-pkg.sh
packaging/macos/build-pkg.sh "$APP_VERSION" "$PWD/dist/macos"
for arch in arm64 amd64; do
packaging/macos/build-pkg.sh "$APP_VERSION" "$PWD/dist/macos" "$arch"
done
- name: 上传 macOS 安装包
uses: actions/upload-artifact@v7
with:
name: ydisks-xianyu-helper-macos-${{ env.APP_VERSION }}
path: dist/macos/Ydisks-Xianyu-Helper-${{ env.APP_VERSION }}.pkg
path: dist/macos/Ydisks-Xianyu-Helper-${{ env.APP_VERSION }}-*.pkg
if-no-files-found: error
+1 -1
View File
@@ -7,7 +7,7 @@ import (
"fmt"
"os"
"github.com/playwright-community/playwright-go"
"github.com/mxschmitt/playwright-go"
)
func main() {
+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)
}
}
-23
View File
@@ -37,7 +37,6 @@ func onReady() {
startItem := systray.AddMenuItem("启动服务", "启动后台服务")
stopItem := systray.AddMenuItem("停止服务", "停止后台服务")
restartItem := systray.AddMenuItem("重启服务", "重启后台服务")
browserItem := systray.AddMenuItem("安装/修复 Chromium", "准备 Playwright Chromium")
systray.AddSeparator()
quitItem := systray.AddMenuItem("退出托盘", "只退出菜单栏控制器")
@@ -62,11 +61,6 @@ func onReady() {
runServiceAction(statusItem, "重启服务", "restart")
}
}()
go func() {
for range browserItem.ClickedCh {
_ = installBrowser()
}
}()
go func() {
for range quitItem.ClickedCh {
if err := quitTray(); err != nil {
@@ -79,23 +73,6 @@ func onReady() {
}()
}
func installBrowser() error {
path := strings.TrimSpace(os.Getenv("XIANYU_BROWSER_INSTALL"))
if path == "" {
executable, err := os.Executable()
if err != nil {
return err
}
path = executable
if runtime.GOOS == "darwin" {
path = strings.Replace(path, "/Contents/MacOS/Ydisks闲鱼助手", "/Contents/Helpers/browser-install", 1)
} else {
path = strings.Replace(path, "xianyu-tray.exe", "browser-install.exe", 1)
}
}
return exec.Command(path).Run()
}
func refreshStatus(item *systray.MenuItem) {
client := &http.Client{Timeout: 2 * time.Second}
for {
+2 -2
View File
@@ -8,7 +8,7 @@ require (
github.com/go-chi/chi/v5 v5.3.0
github.com/go-sql-driver/mysql v1.10.0
github.com/jackc/pgx/v5 v5.10.0
github.com/playwright-community/playwright-go v0.5700.1
github.com/mxschmitt/playwright-go v0.6100.0
github.com/pressly/goose/v3 v3.27.1
github.com/sashabaranov/go-openai v1.41.2
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e
@@ -23,7 +23,7 @@ require (
filippo.io/edwards25519 v1.2.0 // indirect
github.com/deckarep/golang-set/v2 v2.8.0 // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/go-jose/go-jose/v3 v3.0.4 // indirect
github.com/go-jose/go-jose/v3 v3.0.5 // indirect
github.com/go-stack/stack v1.8.1 // indirect
github.com/godbus/dbus/v5 v5.1.0 // indirect
github.com/google/uuid v1.6.0 // indirect
+4 -4
View File
@@ -13,8 +13,8 @@ github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkp
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
github.com/go-chi/chi/v5 v5.3.0 h1:halUjDxhshgXHMrao5bB8eNBXo/rnzwr8m5m36glehM=
github.com/go-chi/chi/v5 v5.3.0/go.mod h1:R+tYY2hNuVUUjxoPtqUdgBqevM9s9njzkTLutVsOCto=
github.com/go-jose/go-jose/v3 v3.0.4 h1:Wp5HA7bLQcKnf6YYao/4kpRpVMp/yf6+pJKV8WFSaNY=
github.com/go-jose/go-jose/v3 v3.0.4/go.mod h1:5b+7YgP7ZICgJDBdfjZaIt+H/9L9T/YQrVfLAMboGkQ=
github.com/go-jose/go-jose/v3 v3.0.5 h1:BLLJWbC4nMZOfuPVxoZIxeYsn6Nl2r1fITaJ78UQlVQ=
github.com/go-jose/go-jose/v3 v3.0.5/go.mod h1:5b+7YgP7ZICgJDBdfjZaIt+H/9L9T/YQrVfLAMboGkQ=
github.com/go-sql-driver/mysql v1.10.0 h1:Q+1LV8DkHJvSYAdR83XzuhDaTykuDx0l6fkXxoWCWfw=
github.com/go-sql-driver/mysql v1.10.0/go.mod h1:M+cqaI7+xxXGG9swrdeUIoPG3Y3KCkF0pZej+SK+nWk=
github.com/go-stack/stack v1.8.1 h1:ntEHSVwIt7PNXNpgPmVfMrNhLtgjlmnZha2kOpuRiDw=
@@ -40,10 +40,10 @@ github.com/mattn/go-isatty v0.0.21 h1:xYae+lCNBP7QuW4PUnNG61ffM4hVIfm+zUzDuSzYLG
github.com/mattn/go-isatty v0.0.21/go.mod h1:ZXfXG4SQHsB/w3ZeOYbR0PrPwLy+n6xiMrJlRFqopa4=
github.com/mfridman/interpolate v0.0.2 h1:pnuTK7MQIxxFz1Gr+rjSIx9u7qVjf5VOoM/u6BbAxPY=
github.com/mfridman/interpolate v0.0.2/go.mod h1:p+7uk6oE07mpE/Ik1b8EckO0O4ZXiGAfshKBWLUM9Xg=
github.com/mxschmitt/playwright-go v0.6100.0 h1:HYNnbGZsTHz8veJyDGe4fU1iPxfvXqzmwKchzuvGCsY=
github.com/mxschmitt/playwright-go v0.6100.0/go.mod h1:A7VtrS3j/c8ToGnSVUaOfNtQQVxi6JotUS0jeuus6r4=
github.com/ncruces/go-strftime v1.0.0 h1:HMFp8mLCTPp341M/ZnA4qaf7ZlsbTc+miZjCLOFAw7w=
github.com/ncruces/go-strftime v1.0.0/go.mod h1:Fwc5htZGVVkseilnfgOVb9mKy6w1naJmn9CehxcKcls=
github.com/playwright-community/playwright-go v0.5700.1 h1:PNFb1byWqrTT720rEO0JL88C6Ju0EmUnR5deFLvtP/U=
github.com/playwright-community/playwright-go v0.5700.1/go.mod h1:MlSn1dZrx8rszbCxY6x3qK89ZesJUYVx21B2JnkoNF0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/pressly/goose/v3 v3.27.1 h1:6uEvcprBybDmW4hcz3gYujhARhye+GoWKhEWyzD5sh4=
+1 -1
View File
@@ -10,7 +10,7 @@ import (
"sync/atomic"
"time"
"github.com/playwright-community/playwright-go"
"github.com/mxschmitt/playwright-go"
"xianyu-go/internal/xianyu/cookierefresh"
)
+1 -1
View File
@@ -6,7 +6,7 @@ import (
"sync"
"time"
"github.com/playwright-community/playwright-go"
"github.com/mxschmitt/playwright-go"
"xianyu-go/internal/xianyu/cookierefresh"
)
+1 -1
View File
@@ -5,7 +5,7 @@ import (
"fmt"
"time"
"github.com/playwright-community/playwright-go"
"github.com/mxschmitt/playwright-go"
"xianyu-go/internal/xianyu/cookierefresh"
)
+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,
+34 -1
View File
@@ -1,10 +1,13 @@
package browser
import (
"os"
"path/filepath"
"runtime"
"testing"
"time"
playwright "github.com/playwright-community/playwright-go"
playwright "github.com/mxschmitt/playwright-go"
)
// TestChromiumLaunchArgs 验证启动参数含关键安全/反检测项。
@@ -28,6 +31,36 @@ func TestChromiumLaunchArgs(t *testing.T) {
}
}
func TestPackagedPlaywrightRuntimeReady(t *testing.T) {
runtimeRoot := t.TempDir()
driverDir := filepath.Join(runtimeRoot, "driver")
browserDir := filepath.Join(runtimeRoot, "browsers")
if err := os.MkdirAll(filepath.Join(driverDir, "package"), 0o755); err != nil {
t.Fatal(err)
}
if err := os.MkdirAll(filepath.Join(browserDir, "chromium-1228"), 0o755); err != nil {
t.Fatal(err)
}
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.WriteFile(path, []byte("runtime"), 0o755); err != nil {
t.Fatal(err)
}
}
t.Setenv("PLAYWRIGHT_DRIVER_PATH", driverDir)
t.Setenv("PLAYWRIGHT_BROWSERS_PATH", browserDir)
t.Setenv("PLAYWRIGHT_CHROMIUM_EXECUTABLE_PATH", "")
if !packagedPlaywrightRuntimeReady() {
t.Fatal("预置 Playwright runtime 应被识别")
}
}
// newTestManager 构造一个不触网的 Manager(pool 空,maxSize 小便于测试驱逐)。
func newTestManager(maxSize int) *Manager {
return &Manager{
+1 -1
View File
@@ -9,7 +9,7 @@ import (
"sync"
"time"
"github.com/playwright-community/playwright-go"
"github.com/mxschmitt/playwright-go"
"xianyu-go/internal/xianyu/cookierefresh"
"xianyu-go/internal/xianyu/mtop"
+1 -1
View File
@@ -8,7 +8,7 @@ import (
"strings"
"time"
"github.com/playwright-community/playwright-go"
"github.com/mxschmitt/playwright-go"
)
// loginFormSelectors 登录表单选择器,主页面和 iframe 中都要找。
+1 -1
View File
@@ -7,7 +7,7 @@ import (
"strings"
"time"
"github.com/playwright-community/playwright-go"
"github.com/mxschmitt/playwright-go"
"xianyu-go/internal/logsafe"
)
+1 -1
View File
@@ -7,7 +7,7 @@ import (
"strings"
"time"
"github.com/playwright-community/playwright-go"
"github.com/mxschmitt/playwright-go"
)
// sliderSelectors 按优先级排列的滑块相关选择器(移植自 xianyu_slider_stealth.py)。
+1 -1
View File
@@ -10,7 +10,7 @@ import (
"strings"
"time"
"github.com/playwright-community/playwright-go"
"github.com/mxschmitt/playwright-go"
)
const (
+1 -1
View File
@@ -12,7 +12,7 @@ import (
"strings"
"time"
"github.com/playwright-community/playwright-go"
"github.com/mxschmitt/playwright-go"
)
var fallbackTrackSelectors = []string{
@@ -11,7 +11,7 @@ import (
"testing"
"time"
"github.com/playwright-community/playwright-go"
"github.com/mxschmitt/playwright-go"
)
func TestReferencePlaywrightSliderBrowserIntegration(t *testing.T) {
+1 -1
View File
@@ -7,7 +7,7 @@ import (
"testing"
"time"
"github.com/playwright-community/playwright-go"
"github.com/mxschmitt/playwright-go"
)
type cookieReadResult struct {
+41 -8
View File
@@ -3,26 +3,44 @@ set -eu
VERSION="${1:?version is required}"
DIST_DIR="${2:?dist directory is required}"
ARCH="${3:?architecture is required (arm64 or amd64)}"
SCRIPT_DIR="$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)"
PROJECT_ROOT="$(CDPATH= cd -- "$SCRIPT_DIR/../.." && pwd)"
ROOT_DIR="$DIST_DIR/pkgroot"
BIN_DIR="$DIST_DIR/$ARCH"
ROOT_DIR="$DIST_DIR/pkgroot-$ARCH"
APP_DIR="$ROOT_DIR/Applications/Ydisks闲鱼助手"
APP="$APP_DIR/Ydisks闲鱼助手.app"
PACKAGE_PATH="$DIST_DIR/Ydisks-Xianyu-Helper-$VERSION.pkg"
UNSIGNED_PACKAGE_PATH="$DIST_DIR/.Ydisks-Xianyu-Helper-$VERSION.unsigned.pkg"
PACKAGE_PATH="$DIST_DIR/Ydisks-Xianyu-Helper-$VERSION-$ARCH.pkg"
UNSIGNED_PACKAGE_PATH="$DIST_DIR/.Ydisks-Xianyu-Helper-$VERSION-$ARCH.unsigned.pkg"
case "$ARCH" in
arm64|amd64) ;;
*) echo "不支持的 macOS 架构:$ARCH" >&2; exit 1 ;;
esac
if [ ! -x "$BIN_DIR/xianyu-server" ] || [ ! -x "$BIN_DIR/xianyu-tray" ]; then
echo "缺少 $ARCH 架构的桌面二进制:$BIN_DIR" >&2
exit 1
fi
if [ ! -d "$DIST_DIR/playwright-runtime/$ARCH/playwright-driver" ] || \
[ ! -d "$DIST_DIR/playwright-runtime/$ARCH/playwright-browsers" ]; then
echo "缺少 $ARCH 架构的 Playwright runtime:$DIST_DIR/playwright-runtime/$ARCH" >&2
exit 1
fi
rm -rf "$ROOT_DIR"
mkdir -p "$APP/Contents/MacOS" "$APP/Contents/Helpers" "$APP/Contents/Resources"
cp "$DIST_DIR/xianyu-server" "$APP/Contents/Helpers/xianyu-server"
cp "$DIST_DIR/browser-install" "$APP/Contents/Helpers/browser-install"
cp "$DIST_DIR/xianyu-tray" "$APP/Contents/MacOS/Ydisks闲鱼助手"
cp "$BIN_DIR/xianyu-server" "$APP/Contents/Helpers/xianyu-server"
cp "$BIN_DIR/xianyu-tray" "$APP/Contents/MacOS/Ydisks闲鱼助手"
cp "$SCRIPT_DIR/uninstall.command" "$APP_DIR/卸载 Ydisks闲鱼助手.command"
cp "$SCRIPT_DIR/com.ydisks.xianyu-helper.server.plist.template" "$APP/Contents/Resources/"
cp "$SCRIPT_DIR/com.ydisks.xianyu-helper.tray.plist.template" "$APP/Contents/Resources/"
mkdir -p "$APP/Contents/Resources/playwright-runtime/$ARCH"
cp -R "$DIST_DIR/playwright-runtime/$ARCH/." "$APP/Contents/Resources/playwright-runtime/$ARCH/"
cp "$PROJECT_ROOT/icon/macos/Assets.car" "$APP/Contents/Resources/Assets.car"
cp "$PROJECT_ROOT/icon/macos/icon.icns" "$APP/Contents/Resources/icon.icns"
sed "s/__VERSION__/$VERSION/g" "$SCRIPT_DIR/Info.plist" > "$APP/Contents/Info.plist"
chmod 0755 "$APP/Contents/MacOS/Ydisks闲鱼助手" "$APP/Contents/Helpers/xianyu-server" "$APP/Contents/Helpers/browser-install" "$APP_DIR/卸载 Ydisks闲鱼助手.command"
chmod 0755 "$APP/Contents/MacOS/Ydisks闲鱼助手" "$APP/Contents/Helpers/xianyu-server" "$APP_DIR/卸载 Ydisks闲鱼助手.command"
if [ -n "${MACOS_SIGNING_IDENTITY:-}" ]; then
sign_code() {
@@ -36,9 +54,24 @@ if [ -n "${MACOS_SIGNING_IDENTITY:-}" ]; then
fi
}
# Playwright runtime 中包含 Node 和 Chromium.app,必须在 App 签名之前完成签名。
find "$APP/Contents/Resources/playwright-runtime" -type f -print | while IFS= read -r executable; do
if file "$executable" | grep -q 'Mach-O'; then
sign_code "$executable"
fi
done
find "$APP/Contents/Resources/playwright-runtime" -type d -name '*.app' -print | while IFS= read -r nested_app; do
if [ -n "${MACOS_SIGNING_KEYCHAIN:-}" ]; then
codesign --force --deep --sign "$MACOS_SIGNING_IDENTITY" \
--keychain "$MACOS_SIGNING_KEYCHAIN" --timestamp=none "$nested_app"
else
codesign --force --deep --sign "$MACOS_SIGNING_IDENTITY" \
--timestamp=none "$nested_app"
fi
done
# macOS 代码签名必须从内部组件开始,最后再签名 App 包本身。
sign_code "$APP/Contents/Helpers/xianyu-server"
sign_code "$APP/Contents/Helpers/browser-install"
sign_code "$APP/Contents/MacOS/Ydisks闲鱼助手"
sign_code "$APP"
codesign --verify --deep --strict --verbose=2 "$APP"
@@ -7,6 +7,7 @@
<array>
<string>__SERVER__</string>
<string>-addr</string><string>127.0.0.1:8080</string>
<string>-playwright-runtime-root</string><string>__RUNTIME_ROOT__</string>
</array>
<key>WorkingDirectory</key><string>__DATA_DIR__</string>
<key>RunAtLoad</key><true/>
+18 -10
View File
@@ -28,23 +28,34 @@ fi
SERVER="$APP/Contents/Helpers/xianyu-server"
TRAY="$APP/Contents/MacOS/Ydisks闲鱼助手"
BROWSER_INSTALL="$APP/Contents/Helpers/browser-install"
RUNTIME_ROOT="$APP/Contents/Resources/playwright-runtime"
CONSOLE_USER="$(stat -f '%Su' /dev/console)"
if [ "$CONSOLE_USER" = "root" ] || [ -z "$CONSOLE_USER" ]; then
echo "没有登录用户,跳过 LaunchAgent 和 Chromium 初始化;登录后请重新打开应用。"
echo "没有登录用户,跳过 LaunchAgent;登录后请重新打开应用。"
exit 0
fi
UID_VALUE="$(id -u "$CONSOLE_USER")"
HOME_DIR="$(dscl . -read "/Users/$CONSOLE_USER" NFSHomeDirectory | awk '{print $2}')"
DATA_DIR="$HOME_DIR/Library/Application Support/YdisksXianyuHelper"
DRIVER_DIR="$DATA_DIR/playwright-driver"
BROWSER_DIR="$DATA_DIR/playwright-browsers"
LOG_DIR="$HOME_DIR/Library/Logs/YdisksXianyuHelper"
AGENT_DIR="$HOME_DIR/Library/LaunchAgents"
mkdir -p "$DATA_DIR" "$DRIVER_DIR" "$BROWSER_DIR" "$LOG_DIR" "$AGENT_DIR"
RUNTIME_ARCH=""
for candidate_arch in arm64 amd64; do
if [ -d "$RUNTIME_ROOT/$candidate_arch/playwright-driver" ] && [ -d "$RUNTIME_ROOT/$candidate_arch/playwright-browsers" ]; then
RUNTIME_ARCH="$candidate_arch"
break
fi
done
if [ -z "$RUNTIME_ARCH" ]; then
echo "安装包缺少完整的 Playwright runtime:$RUNTIME_ROOT"
exit 1
fi
echo "使用 $RUNTIME_ARCH 架构的 Playwright runtime。"
mkdir -p "$DATA_DIR" "$LOG_DIR" "$AGENT_DIR"
chown -R "$CONSOLE_USER" "$DATA_DIR" "$LOG_DIR" "$AGENT_DIR"
escape_sed() {
@@ -55,6 +66,7 @@ SERVER_ESCAPED="$(escape_sed "$SERVER")"
TRAY_ESCAPED="$(escape_sed "$TRAY")"
DATA_ESCAPED="$(escape_sed "$DATA_DIR")"
LOG_ESCAPED="$(escape_sed "$LOG_DIR")"
RUNTIME_ROOT_ESCAPED="$(escape_sed "$RUNTIME_ROOT")"
SERVER_LABEL="com.ydisks.xianyu-helper.server"
TRAY_LABEL="com.ydisks.xianyu-helper.tray"
@@ -63,6 +75,7 @@ tray_plist="$AGENT_DIR/$TRAY_LABEL.plist"
sed -e "s|__SERVER__|$SERVER_ESCAPED|g" \
-e "s|__DATA_DIR__|$DATA_ESCAPED|g" \
-e "s|__LOG_DIR__|$LOG_ESCAPED|g" \
-e "s|__RUNTIME_ROOT__|$RUNTIME_ROOT_ESCAPED|g" \
"$APP/Contents/Resources/com.ydisks.xianyu-helper.server.plist.template" > "$server_plist"
sed -e "s|__TRAY__|$TRAY_ESCAPED|g" \
"$APP/Contents/Resources/com.ydisks.xianyu-helper.tray.plist.template" > "$tray_plist"
@@ -79,11 +92,6 @@ launchctl bootout "gui/$UID_VALUE/$LEGACY_SERVER_LABEL" >/dev/null 2>&1 || true
launchctl bootout "gui/$UID_VALUE/$LEGACY_TRAY_LABEL" >/dev/null 2>&1 || true
rm -f "$AGENT_DIR/$LEGACY_SERVER_LABEL.plist" "$AGENT_DIR/$LEGACY_TRAY_LABEL.plist"
launchctl asuser "$UID_VALUE" env HOME="$HOME_DIR" "$BROWSER_INSTALL" \
-driver-dir "$DRIVER_DIR" -browser-dir "$BROWSER_DIR" >>"$INSTALL_LOG" 2>&1 || {
echo "Chromium 自动安装失败,详情已写入 $INSTALL_LOG"
}
launchctl bootstrap "gui/$UID_VALUE" "$server_plist"
launchctl bootstrap "gui/$UID_VALUE" "$tray_plist"
launchctl kickstart -k "gui/$UID_VALUE/$SERVER_LABEL"
+2 -5
View File
@@ -22,21 +22,18 @@ SolidCompression=yes
[Files]
Source: "..\..\dist\windows\xianyu-server.exe"; DestDir: "{app}"; Flags: ignoreversion
Source: "..\..\dist\windows\browser-install.exe"; DestDir: "{app}"; Flags: ignoreversion
Source: "..\..\dist\windows\xianyu-tray.exe"; DestDir: "{app}"; Flags: ignoreversion
Source: "..\..\icon\windows\icon.ico"; DestDir: "{app}"; Flags: ignoreversion
Source: "..\..\dist\windows\playwright-runtime\*"; DestDir: "{app}\playwright-runtime"; Flags: recursesubdirs createallsubdirs ignoreversion
[Dirs]
Name: "{#AppDataDir}\data"
Name: "{#AppDataDir}\playwright-driver"
Name: "{#AppDataDir}\playwright-browsers"
[Registry]
Root: HKCU; Subkey: "Software\Microsoft\Windows\CurrentVersion\Run"; ValueType: string; ValueName: "YdisksXianyuHelperTray"; ValueData: "{app}\xianyu-tray.exe"; Flags: uninsdeletevalue
[Run]
Filename: "{sys}\sc.exe"; Parameters: "create YdisksXianyuHelper binPath= ""{app}\xianyu-server.exe -service -workdir {#AppDataDir} -data-key-file {#AppDataDir}\data-key -addr 127.0.0.1:8080 -playwright-driver-dir {#AppDataDir}\playwright-driver -playwright-browser-dir {#AppDataDir}\playwright-browsers"" start= delayed-auto"; Flags: runhidden waituntilterminated
Filename: "{app}\browser-install.exe"; Parameters: "-driver-dir ""{#AppDataDir}\playwright-driver"" -browser-dir ""{#AppDataDir}\playwright-browsers"""; Flags: waituntilterminated
Filename: "{sys}\sc.exe"; Parameters: "create YdisksXianyuHelper binPath= ""{app}\xianyu-server.exe -service -workdir {#AppDataDir} -data-key-file {#AppDataDir}\data-key -addr 127.0.0.1:8080 -playwright-runtime-root ""{app}\playwright-runtime""" start= delayed-auto"; Flags: runhidden waituntilterminated
Filename: "{sys}\sc.exe"; Parameters: "start YdisksXianyuHelper"; Flags: runhidden waituntilterminated
Filename: "{app}\xianyu-tray.exe"; Description: "启动菜单栏控制器"; Flags: nowait postinstall skipifsilent