Skip to content

Commit 8012333

Browse files
ErlichLiuclaude
andcommitted
fix: 修复打包后 Logo 图标路径错误并回归 electron-builder 直接发布
- 主进程用 process.resourcesPath 读打包资源(dev 仍用 __dirname/resources) 修复 ipc.ts resolveAppIconPath / SAVE_RESOURCE_FILE_AS、tray.ts 托盘图标 打包产物 app/dist/ 下无 resources 子目录(被 electron-builder files 规则排除), 旧路径导致外观设置换图标、品牌 Logo 下载、托盘图标全部 404 - 补 resources/proma-logos/proma-transparent.png(UI 列 14 项但源目录缺 1) - 恢复 electron-builder.yml 的 publish.provider: github - release.yml 回归三平台 --publish always 直接上传,移除 publish 汇总 job latest.yml / latest-mac.yml 由 electron-builder 在 tag 构建时自动生成与合并 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent 9577d04 commit 8012333

5 files changed

Lines changed: 33 additions & 97 deletions

File tree

.github/workflows/release.yml

Lines changed: 8 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -90,94 +90,20 @@ jobs:
9090
run: bun run electron:build
9191
working-directory: .
9292

93-
# 打包(不上传发布,避免并行竞态)
94-
- name: 打包 (macOS)
93+
# 打包并发布到 GitHub Releases
94+
- name: 打包并发布 (macOS)
9595
if: matrix.platform == 'mac'
9696
env:
97+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
9798
APPLE_ID: ${{ secrets.APPLE_ID }}
9899
APPLE_APP_SPECIFIC_PASSWORD: ${{ secrets.APPLE_APP_SPECIFIC_PASSWORD }}
99100
APPLE_TEAM_ID: ${{ secrets.APPLE_TEAM_ID }}
100-
run: npx electron-builder --mac ${{ matrix.builder_arg }}
101+
run: npx electron-builder --mac ${{ matrix.builder_arg }} --publish always
101102
working-directory: apps/electron
102103

103-
- name: 打包 (Windows)
104+
- name: 打包并发布 (Windows)
104105
if: matrix.platform == 'win'
105-
run: npx electron-builder --win ${{ matrix.builder_arg }}
106-
working-directory: apps/electron
107-
108-
# 上传产物为 workflow artifact
109-
- name: 上传产物
110-
uses: actions/upload-artifact@v4
111-
with:
112-
name: build-${{ matrix.platform }}-${{ matrix.arch }}
113-
path: apps/electron/out/*
114-
retention-days: 1
115-
116-
publish:
117-
needs: build
118-
runs-on: ubuntu-latest
119-
steps:
120-
- name: 下载 macOS ARM64 产物
121-
uses: actions/download-artifact@v4
122-
with:
123-
name: build-mac-arm64
124-
path: artifacts/mac-arm64
125-
126-
- name: 下载 macOS x64 产物
127-
uses: actions/download-artifact@v4
128-
with:
129-
name: build-mac-x64
130-
path: artifacts/mac-x64
131-
132-
- name: 下载 Windows x64 产物
133-
uses: actions/download-artifact@v4
134-
with:
135-
name: build-win-x64
136-
path: artifacts/win-x64
137-
138-
- name: 汇总产物并合并 latest-mac.yml
139-
run: |
140-
mkdir -p release
141-
142-
# 拷贝 Windows 产物(排除 win-unpacked 中间目录)
143-
cp artifacts/win-x64/*.exe artifacts/win-x64/*.exe.blockmap artifacts/win-x64/latest.yml release/
144-
145-
# 拷贝 macOS 产物(排除 latest-mac.yml,稍后合并)
146-
cp artifacts/mac-x64/*.dmg artifacts/mac-x64/*.zip artifacts/mac-x64/*.zip.blockmap release/ 2>/dev/null || true
147-
cp artifacts/mac-arm64/*.dmg artifacts/mac-arm64/*.zip artifacts/mac-arm64/*.zip.blockmap release/ 2>/dev/null || true
148-
149-
# 合并两份 latest-mac.yml
150-
pip install pyyaml -q
151-
python3 << 'PYEOF'
152-
import yaml
153-
154-
with open('artifacts/mac-x64/latest-mac.yml') as f:
155-
x64 = yaml.safe_load(f)
156-
with open('artifacts/mac-arm64/latest-mac.yml') as f:
157-
arm64 = yaml.safe_load(f)
158-
159-
files = []
160-
if 'files' in x64:
161-
files.extend(x64['files'])
162-
if 'files' in arm64:
163-
files.extend(arm64['files'])
164-
165-
merged = dict(x64)
166-
merged['files'] = files
167-
168-
with open('release/latest-mac.yml', 'w') as f:
169-
yaml.dump(merged, f, default_flow_style=False, allow_unicode=True)
170-
PYEOF
171-
172-
echo "=== release/ 文件列表 ==="
173-
ls -la release/
174-
175-
- name: 创建 GitHub Release
176-
uses: softprops/action-gh-release@v2
177-
with:
178-
name: ${{ github.ref_name }}
179-
files: release/*
180-
draft: false
181-
prerelease: false
182106
env:
183-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
107+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
108+
run: npx electron-builder --win ${{ matrix.builder_arg }} --publish always
109+
working-directory: apps/electron

apps/electron/electron-builder.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,10 @@ nsis:
106106

107107
# ============================================
108108
# 发布配置
109-
# 发布已由 CI workflow (release.yml) 的 publish job 接管,
110-
# 此处注释掉避免 electron-builder 在 tag 构建时自动触发发布
109+
# 每个平台的 build job 通过 --publish always 直接上传到 GitHub Release。
110+
# electron-builder 会自动创建/复用 Release,并在多架构并行上传时合并 latest-mac.yml
111111
# ============================================
112-
# publish:
113-
# provider: github
114-
# owner: ErlichLiu
115-
# repo: Proma
112+
publish:
113+
provider: github
114+
owner: ErlichLiu
115+
repo: Proma
36 KB
Loading

apps/electron/src/main/ipc.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -211,17 +211,24 @@ const HIDDEN_FS_ENTRIES = new Set(['.DS_Store', 'Thumbs.db'])
211211
* - channel:*: 渠道管理相关
212212
* - chat:*: 对话管理 + 消息发送 + 流式事件
213213
*/
214+
/**
215+
* 打包内置资源目录
216+
* dev: __dirname/resources(build:resources 阶段拷贝)
217+
* prod: process.resourcesPath(electron-builder extraResources 产物)
218+
*/
219+
function getBundledResourcesDir(): string {
220+
return app.isPackaged ? process.resourcesPath : join(__dirname, 'resources')
221+
}
222+
214223
/**
215224
* 解析应用图标变体的文件路径
216-
* dev 模式: __dirname/resources/proma-logos/proma-{id}.png
217-
* 生产模式: __dirname/resources/proma-logos/proma-{id}.png(build:resources 阶段已复制)
218225
*/
219226
export function resolveAppIconPath(variantId: string): string | null {
227+
const resourcesDir = getBundledResourcesDir()
220228
if (!variantId || variantId === 'default') {
221-
// 默认图标
222-
return join(__dirname, 'resources/icon.png')
229+
return join(resourcesDir, 'icon.png')
223230
}
224-
return join(__dirname, 'resources/proma-logos', `proma-${variantId}.png`)
231+
return join(resourcesDir, 'proma-logos', `proma-${variantId}.png`)
225232
}
226233

227234
export function registerIpcHandlers(): void {
@@ -562,8 +569,8 @@ export function registerIpcHandlers(): void {
562569
const { writeFileSync, readFileSync, existsSync } = await import('node:fs')
563570
const { join, normalize, sep, extname: pathExtname } = await import('node:path')
564571

565-
// 解析到应用内置 resources 目录
566-
const resourcesDir = normalize(join(__dirname, 'resources'))
572+
// 解析到应用内置 resources 目录(dev 用 __dirname/resources,prod 用 process.resourcesPath)
573+
const resourcesDir = normalize(getBundledResourcesDir())
567574
const fullPath = normalize(join(resourcesDir, resourceRelativePath))
568575

569576
// 安全校验:防止路径穿越(追加 sep 防止 resources-evil 绕过)

apps/electron/src/main/tray.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,11 @@ let tray: Tray | null = null
99
* 所有平台统一使用 Template 图标
1010
*/
1111
function getTrayIconPath(): string {
12-
// resources 在 build:resources 阶段被复制到 dist/ 下,与 main.cjs 同级
13-
const resourcesDir = join(__dirname, 'resources/proma-logos')
12+
// dev: __dirname/resources(build:resources 拷贝产物)
13+
// prod: process.resourcesPath(electron-builder extraResources 产物)
14+
const resourcesDir = app.isPackaged
15+
? join(process.resourcesPath, 'proma-logos')
16+
: join(__dirname, 'resources/proma-logos')
1417
return join(resourcesDir, 'iconTemplate.png')
1518
}
1619

0 commit comments

Comments
 (0)