feat: integrate electron-updater for in-app auto-update

Replace the manual "jump to GitHub Release" update flow with native
in-app auto-update powered by electron-updater. The app now silently
downloads updates in the background and prompts the user to restart
when ready. Browser mode (`npm run dev`) retains the existing polling
fallback via `/api/app/updates`.

Main process (electron/updater.ts — new):
- Wrap electron-updater's autoUpdater, forward lifecycle events
  (checking / available / downloading / downloaded / error) to the
  renderer via IPC channel `updater:status`
- Register `updater:check` and `updater:quit-and-install` IPC handlers
- Auto-check 10s after launch, then every 4 hours
- Only initialized in packaged mode (!isDev)

Preload bridge (electron/preload.ts):
- Expose `updater` namespace with checkForUpdates, quitAndInstall,
  and onStatus callback (same pattern as install.onProgress)

Type declarations (src/types/electron.d.ts):
- Add UpdateStatusEvent, ElectronUpdaterAPI interfaces
- Add optional `updater` field to ElectronAPI

Update hook (src/hooks/useUpdate.ts):
- Extend UpdateInfo with downloadProgress, readyToInstall, isNativeUpdate
- Add quitAndInstall to UpdateContextValue

Renderer — dual-mode logic (src/components/layout/AppShell.tsx):
- Detect `window.electronAPI?.updater` to choose between native IPC
  subscription (Electron) and HTTP polling (browser)
- Map IPC events to UpdateInfo state, including download progress

UI components:
- UpdateDialog: three footer states — View Release (browser), progress
  bar + disabled button (downloading), Restart to Update (ready)
- UpdateBanner (new): persistent top banner when update is downloaded,
  shown even after dialog is dismissed
- NavRail: settings dot turns green + pulse when readyToInstall
- GeneralSection: UpdateCard shows download %, restart button, or
  View Release depending on mode

Build & CI:
- electron-builder.yml: add `publish` config (github provider) to
  generate latest-mac.yml / latest.yml metadata + blockmap files
- build.yml: change --publish never to --publish always with GH_TOKEN;
  release job now uses `gh release edit` instead of create

i18n:
- Add 6 translation keys (en + zh) for update UI strings

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
7418andClaude Opus 4.6 committed 2026-02-26 11:16:41 +08:00
1 parent 7cd0cb5aab
commit 762953b2ad
16 files changed
+474 -92

No files matched your search

+21 -51
View File
@@ -39,16 +39,9 @@ jobs:
run: npm run electron:build
- name: Package for Windows
run: npx electron-builder --win --config electron-builder.yml --publish never
- name: Upload Windows artifacts
uses: actions/upload-artifact@v4
with:
name: windows
path: |
release/*.exe
release/*.zip
if-no-files-found: warn
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: npx electron-builder --win --config electron-builder.yml --publish always
build-macos:
if: ${{ github.event_name == 'push' || inputs.platform == 'all' || inputs.platform == 'macos' }}
@@ -71,14 +64,9 @@ jobs:
run: npm run electron:build
- name: Package for macOS (${{ matrix.arch }})
run: npx electron-builder --mac --${{ matrix.arch }} --config electron-builder.yml --publish never
- name: Upload macOS artifacts
uses: actions/upload-artifact@v4
with:
name: macos-${{ matrix.arch }}
path: release/*.dmg
if-no-files-found: warn
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: npx electron-builder --mac --${{ matrix.arch }} --config electron-builder.yml --publish always
build-linux:
if: ${{ github.event_name == 'push' || inputs.platform == 'all' || inputs.platform == 'linux' }}
@@ -101,17 +89,9 @@ jobs:
run: npm run electron:build
- name: Package for Linux (${{ matrix.arch }})
run: npx electron-builder --linux --${{ matrix.arch }} --config electron-builder.yml --publish never
- name: Upload Linux artifacts
uses: actions/upload-artifact@v4
with:
name: linux-${{ matrix.arch }}
path: |
release/*.AppImage
release/*.deb
release/*.rpm
if-no-files-found: warn
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: npx electron-builder --linux --${{ matrix.arch }} --config electron-builder.yml --publish always
release:
if: ${{ always() && github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') && !contains(needs.*.result, 'cancelled') }}
@@ -122,11 +102,6 @@ jobs:
with:
fetch-depth: 0
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: artifacts
- name: Get version and previous tag
id: meta
run: |
@@ -151,13 +126,7 @@ jobs:
echo "CHANGELOG_EOF"
} >> "$GITHUB_OUTPUT"
- name: Collect release files
run: |
mkdir -p release-files
find artifacts -type f \( -name '*.exe' -o -name '*.dmg' -o -name '*.AppImage' -o -name '*.deb' -o -name '*.rpm' -o -name '*.zip' \) -exec cp {} release-files/ \;
ls -lh release-files/
- name: Create GitHub Release
- name: Update release notes
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
@@ -179,21 +148,21 @@ jobs:
## Installation
**Windows**: 下载 exe 安装包,双击安装,按提示完成即可。
**Windows**: Download the exe installer, double-click to install.
**macOS**:
1. 下载对应芯片架构的 DMG 文件
2. 打开 DMG,将 CodePilot 拖入 Applications 文件夹
3. 首次打开时如遇安全提示,前往 **系统设置 → 隐私与安全性** 点击"仍要打开"
4. 在 Settings 页面配置 Anthropic API Key 或环境变量
1. Download the DMG for your chip architecture
2. Open the DMG, drag CodePilot into Applications
3. If you see a security prompt on first launch, go to **System Settings > Privacy & Security** and click "Open Anyway"
4. Configure your Anthropic API Key in Settings
**Linux**: 使用 AppImage 直接运行,或通过 deb/rpm 包安装。
**Linux**: Run the AppImage directly, or install via deb/rpm package.
## Requirements
- Windows 10+ / macOS 12.0+ / Linux (glibc 2.31+)
- Anthropic API Key 或已配置 `ANTHROPIC_API_KEY` 环境变量
- 如需使用代码相关功能,建议安装 Claude Code CLI
- Anthropic API Key or `ANTHROPIC_API_KEY` environment variable
- Claude Code CLI recommended for code features
## Changelog
NOTES_EOF
@@ -207,8 +176,9 @@ jobs:
CHANGELOG_INLINE_EOF
fi
gh release create "${GITHUB_REF_NAME}" \
# Update the draft release created by electron-builder with full notes
gh release edit "${GITHUB_REF_NAME}" \
--title "CodePilot v${VERSION}" \
--notes-file release-notes.md \
--latest \
release-files/*
--draft=false