- electron/main.cjs: 修复托盘菜单损坏的合并代码(SyntaxError),托盘 3D 意识空间与 ipc 路由改用正确的 backendPort 变量 - 新增 activation.html 激活页(对接 /activate 接口,支持自动识别/8 个服务商) - scripts/package-win.ps1: 打包前切换 better-sqlite3 到 Electron ABI、打包后还原 Node ABI,避免 dev 后端崩溃;内置 npmmirror 工具链镜像 - scripts/gen-icons.ps1 + build/icon.ico: 生成安装包图标(electron-builder 必需) - package.json: build 脚本改用 package-win.ps1(不再依赖 VS 工具链) Co-Authored-By: Claude <noreply@anthropic.com>
57 lines
2.4 KiB
PowerShell
57 lines
2.4 KiB
PowerShell
# package-win.ps1 — Build the Windows NSIS installer.
|
|
#
|
|
# better-sqlite3 is a native module and its binary must match the runtime ABI:
|
|
# - packaged app / `npm start` → Electron ABI (v130 for Electron 33)
|
|
# - `npm run start:backend` → Node ABI
|
|
# This script swaps the prebuilt binary to Electron ABI before packaging and
|
|
# restores the Node ABI afterwards, so dev backend mode keeps working.
|
|
#
|
|
# No compiler needed: prebuild-install downloads prebuilt binaries (uses the
|
|
# npm prebuild cache when GitHub is unreachable).
|
|
#
|
|
# Usage: powershell -ExecutionPolicy Bypass -File scripts/package-win.ps1
|
|
|
|
param([string]$ElectronVersion = "33.4.11")
|
|
|
|
$ErrorActionPreference = "Stop"
|
|
$root = Split-Path $PSScriptRoot
|
|
Set-Location $root
|
|
|
|
function Invoke-PrebuildInstall {
|
|
param([string]$Runtime, [string]$Target)
|
|
Push-Location "node_modules\better-sqlite3"
|
|
try {
|
|
if ($Runtime -eq "electron") {
|
|
npx prebuild-install --runtime=electron --target=$Target
|
|
} else {
|
|
npx prebuild-install
|
|
}
|
|
if ($LASTEXITCODE -ne 0) { throw "prebuild-install ($Runtime) failed with exit code $LASTEXITCODE" }
|
|
} finally {
|
|
Pop-Location
|
|
}
|
|
}
|
|
|
|
# 1) Swap better-sqlite3 to the Electron-ABI prebuilt binary.
|
|
Invoke-PrebuildInstall -Runtime electron -Target $ElectronVersion
|
|
|
|
try {
|
|
# 2) Package. Point electron-builder at the local electron dist to skip the
|
|
# GitHub download, and mirror NSIS/winCodeSign through npmmirror (GitHub
|
|
# is unreachable on CN networks).
|
|
$env:ELECTRON_BUILDER_BINARIES_MIRROR = "https://cdn.npmmirror.com/binaries/electron-builder-binaries/"
|
|
$dist = Join-Path $root "node_modules\electron\dist"
|
|
npx electron-builder --win "-c.electronDist=$dist"
|
|
if ($LASTEXITCODE -ne 0) { throw "electron-builder failed with exit code $LASTEXITCODE" }
|
|
Write-Host "[package] NSIS installer built:" -ForegroundColor Green
|
|
Get-ChildItem "$root\dist\*.exe" | ForEach-Object { Write-Host " $_" -ForegroundColor Green }
|
|
} finally {
|
|
# 3) Restore the Node-ABI binary so `npm run start:backend` / `npm run dev` keep working.
|
|
try {
|
|
Invoke-PrebuildInstall -Runtime node
|
|
Write-Host "[package] better-sqlite3 restored to Node ABI" -ForegroundColor Cyan
|
|
} catch {
|
|
Write-Host "[package] WARN: failed to restore Node prebuild: $($_.Exception.Message)" -ForegroundColor Yellow
|
|
}
|
|
}
|