- Add AppUpdater module with update lifecycle management - Create UpdateSettings UI component with progress display - Add Progress UI component based on Radix UI - Create update Zustand store for state management - Register update IPC handlers in main process - Auto-check for updates on production startup - Add commit documentation for commits 2-6
4.7 KiB
4.7 KiB
Commit 6: Auto-Update Functionality
Summary
Integrate electron-updater for automatic application updates with a comprehensive UI for checking, downloading, and installing updates.
Changes
Electron Main Process
electron/main/updater.ts (New)
Complete auto-update module:
AppUpdater Class:
- Extends EventEmitter for event-based notifications
- Configures electron-updater settings
- Manages update lifecycle
Methods:
setMainWindow(window)- Set window for IPCgetStatus()- Get current update statuscheckForUpdates()- Check for available updatesdownloadUpdate()- Download available updatequitAndInstall()- Install update and restartsetChannel(channel)- Set update channel (stable/beta/dev)setAutoDownload(enable)- Configure auto-downloadgetCurrentVersion()- Get app version
Update Status:
idle- No update activitychecking- Checking for updatesavailable- Update availablenot-available- Already on latestdownloading- Download in progressdownloaded- Ready to installerror- Update failed
IPC Handlers (registerUpdateHandlers):
update:status- Get current statusupdate:version- Get app versionupdate:check- Trigger update checkupdate:download- Start downloadupdate:install- Install and restartupdate:setChannel- Change update channelupdate:setAutoDownload- Toggle auto-download
Events forwarded to renderer:
update:status-changedupdate:checkingupdate:availableupdate:not-availableupdate:progressupdate:downloadedupdate:error
electron/main/index.ts
- Import and register update handlers
- Auto-check for updates in production (10s delay)
electron/preload/index.ts
- Added all update IPC channels
React Renderer
src/stores/update.ts (New)
Zustand store for update state:
- State:
status,currentVersion,updateInfo,progress,error,isInitialized - Actions:
init,checkForUpdates,downloadUpdate,installUpdate,setChannel,setAutoDownload,clearError - Listens for all update events from main process
src/components/settings/UpdateSettings.tsx (New)
Update UI component:
- Current version display
- Status indicator with icon
- Status text description
- Action buttons (Check/Download/Install/Retry)
- Download progress bar with transfer stats
- Update info card (version, date, release notes)
- Error details display
Progress Display:
- Transferred / Total bytes
- Transfer speed (bytes/second)
- Progress percentage bar
src/components/ui/progress.tsx (New)
Radix UI Progress component for download visualization.
src/pages/Settings/index.tsx
- Replaced manual update section with
UpdateSettingscomponent - Added
useUpdateStorefor version display - Removed unused state and effect hooks
Technical Details
Update Flow
App Start (Production)
|
v
10s Delay
|
v
checkForUpdates()
|
+-- No Update --> status: 'not-available'
|
+-- Update Found --> status: 'available'
|
v
[User Action]
|
v
downloadUpdate()
|
v
status: 'downloading'
progress events
|
v
status: 'downloaded'
|
v
[User Action]
|
v
quitAndInstall()
|
v
App Restarts
electron-updater Configuration
autoUpdater.autoDownload = false; // Manual download trigger
autoUpdater.autoInstallOnAppQuit = true; // Install on quit
autoUpdater.logger = customLogger; // Console logging
Update Channels
stable- Production releasesbeta- Pre-release testingdev- Development builds
Progress Info Interface
interface ProgressInfo {
total: number; // Total bytes
delta: number; // Bytes since last event
transferred: number; // Bytes downloaded
percent: number; // 0-100
bytesPerSecond: number; // Transfer speed
}
UI States
| Status | Icon | Action Button |
|---|---|---|
| idle | RefreshCw (gray) | Check for Updates |
| checking | Loader2 (spin, blue) | Checking... (disabled) |
| available | Download (green) | Download Update |
| downloading | Download (pulse, blue) | Downloading... (disabled) |
| downloaded | CheckCircle2 (green) | Install & Restart |
| error | AlertCircle (red) | Retry |
| not-available | CheckCircle2 (green) | Check for Updates |
Dependencies
- electron-updater ^6.3.9 (already installed)
- @radix-ui/react-progress ^1.1.1 (already installed)
Version
v0.1.0-alpha (incremental)