feat: implement auto-update functionality with GitHub integration
- Added AutoUpdater class to manage update checks and downloads. - Integrated auto-updater in the main process after the main window is created. - Enhanced preload script to expose update-related IPC channels. - Created UpdateDialog component to handle user interactions for updates. - Implemented state management for update status using Pinia store. - Added localization support for update messages in multiple languages. - Documented auto-update configuration steps for private GitHub repositories. - Created .env.example for GitHub token configuration.
This commit is contained in:
1 parent
ac5488a21d
commit
0eb2dcf8c2
22 files changed
+882
-92
No files matched your search
@@ -0,0 +1,58 @@
|
||||
import { defineStore } from 'pinia'
|
||||
|
||||
export interface UpdateStatus {
|
||||
status: 'idle' | 'checking' | 'available' | 'not-available' | 'downloading' | 'downloaded' | 'error'
|
||||
currentVersion?: string
|
||||
error?: string
|
||||
progress?: number
|
||||
}
|
||||
|
||||
export const useAppStore = defineStore('app', {
|
||||
state: () => ({
|
||||
updateStatus: {
|
||||
status: 'idle' as const
|
||||
} as UpdateStatus,
|
||||
updateDialogVisible: false,
|
||||
downloadProgress: 0
|
||||
}),
|
||||
|
||||
getters: {
|
||||
isUpdateAvailable: (state) => state.updateStatus.status === 'available',
|
||||
isCheckingForUpdates: (state) => state.updateStatus.status === 'checking',
|
||||
hasUpdateError: (state) => state.updateStatus.status === 'error'
|
||||
},
|
||||
|
||||
actions: {
|
||||
setUpdateStatus(status: UpdateStatus['status'], currentVersion?: string, error?: string) {
|
||||
this.updateStatus = { status, currentVersion, error }
|
||||
},
|
||||
|
||||
showUpdateDialog() {
|
||||
this.updateDialogVisible = true
|
||||
},
|
||||
|
||||
hideUpdateDialog() {
|
||||
this.updateDialogVisible = false
|
||||
},
|
||||
|
||||
setDownloadProgress(progress: number) {
|
||||
this.downloadProgress = progress
|
||||
},
|
||||
|
||||
// 启动更新下载
|
||||
async startUpdateDownload() {
|
||||
try {
|
||||
this.setUpdateStatus('downloading')
|
||||
const result = await window.mainApi.invoke('msgDownloadUpdate')
|
||||
|
||||
if (result.success) {
|
||||
this.setUpdateStatus('downloaded')
|
||||
} else {
|
||||
this.setUpdateStatus('error', undefined, result.error)
|
||||
}
|
||||
} catch (error) {
|
||||
this.setUpdateStatus('error', undefined, error instanceof Error ? error.message : String(error))
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
Reference in new issue
Block a user