Files
u-desktop/build.ps1
绝尘 f5a473c4b8 新增: 自动升级体系 + WorkerW重建检测 + 知识卡片优化
自动升级:
- 版本变量注入 (-ldflags -X main.version)
- 远程 version.json 检查 + 弹窗提示(非强制右下角/强制居中)
- updater.exe 嵌入主程序, 运行时释放到临时目录
- 下载+SHA256校验+备份+替换+回滚 全流程
- 托盘菜单"检查更新"

稳定性:
- WorkerW 重建自动检测(每10s)并重新嵌入
- 左键托盘点击防抖
- 设置窗口已打开时正确前置

优化:
- 知识卡片prompt改为面向开发者的硬核内容
- 配置目录统一到 ~/.u-desktop/
- 设置窗口WebView2数据目录改为configDir下
2026-05-28 19:06:26 +08:00

91 lines
3.1 KiB
PowerShell
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.
<#
.SYNOPSIS
u-desktop 构建脚本
.PARAMETER Pack
打包为 zip含 WebView2 bootstrapper
#>
param(
[switch]$Pack
)
$ErrorActionPreference = "Stop"
$project = "u-desktop"
$buildDir = "dist"
# 构建 Web UI
Write-Host "=== 构建 Web UI ===" -ForegroundColor Cyan
Push-Location web-ui
npm ci --prefer-offline
npm run build
if ($LASTEXITCODE -ne 0) { Write-Host "Web UI 构建失败" -ForegroundColor Red; exit 1 }
Pop-Location
# 清理
if (Test-Path $buildDir) { Remove-Item $buildDir -Recurse -Force }
New-Item -ItemType Directory -Force -Path $buildDir | Out-Null
# 版本号
$gitHash = git rev-parse --short HEAD
$version = "$(Get-Date -Format 'yyyyMMdd').$gitHash"
Write-Host "=== 构建 $project v$version ===" -ForegroundColor Cyan
# 构建 updater.exe先编译主程序需要 embed
Write-Host "=== 构建 updater ===" -ForegroundColor Cyan
Push-Location updater
go build -ldflags="-s -w -H windowsgui" -o updater.exe .
if ($LASTEXITCODE -ne 0) { Write-Host "updater 构建失败" -ForegroundColor Red; exit 1 }
Pop-Location
Copy-Item "updater/updater.exe" "updater.exe" -Force
Write-Host "updater.exe 已复制到根目录" -ForegroundColor Green
# 构建(隐藏控制台窗口)
$env:GOOS = "windows"
$env:GOARCH = "amd64"
go build -ldflags="-s -w -H windowsgui -X main.version=$version" -o "$buildDir/$project.exe" .
if ($LASTEXITCODE -ne 0) { Write-Host "构建失败" -ForegroundColor Red; exit 1 }
$sizeBefore = [math]::Round((Get-Item "$buildDir/$project.exe").Length / 1MB, 1)
Write-Host "构建完成: $buildDir/$project.exe ($sizeBefore MB)" -ForegroundColor Green
# UPX 压缩
if (Get-Command upx -ErrorAction SilentlyContinue) {
Write-Host "UPX 压缩中..." -ForegroundColor Yellow
upx --best "$buildDir/$project.exe"
$sizeAfter = [math]::Round((Get-Item "$buildDir/$project.exe").Length / 1MB, 1)
Write-Host "UPX 完成: $sizeBefore MB -> $sizeAfter MB" -ForegroundColor Green
} else {
Write-Host "UPX 未安装,跳过压缩" -ForegroundColor Yellow
}
if (-not $Pack) { exit 0 }
# --- 打包 ---
$packDir = "$buildDir\$project-win10-amd64"
if (Test-Path $packDir) { Remove-Item $packDir -Recurse -Force }
New-Item -ItemType Directory -Force -Path $packDir | Out-Null
# 复制 exe
Copy-Item "$buildDir\$project.exe" $packDir
# 下载 WebView2 bootstrapper
$bootstrapper = "$packDir\MicrosoftEdgeWebview2Setup.exe"
Write-Host "下载 WebView2 bootstrapper..." -ForegroundColor Yellow
Invoke-WebRequest -Uri "https://go.microsoft.com/fwlink/p/?LinkId=2124703" -OutFile $bootstrapper -UseBasicParsing
# 写入安装说明
@"
u-desktop v$version
== Windows 10==
MicrosoftEdgeWebview2Setup.exe WebView2
Windows 11 $project.exe
"@ | Out-File "$packDir\README.txt" -Encoding UTF8
# 打包 zip
$zipName = "$project-win10-amd64-v$version.zip"
Compress-Archive -Path $packDir -DestinationPath "$buildDir\$zipName" -Force
Write-Host "打包完成: $buildDir\$zipName" -ForegroundColor Green
# 清理临时目录
Remove-Item $packDir -Recurse -Force