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
@@ -1,6 +1,72 @@
|
||||
<script setup lang="tsx">
|
||||
import { DefaultLayout } from '@/renderer/components/layout'
|
||||
import GlobalDialog from '@/renderer/components/GlobalDialog.vue'
|
||||
import UpdateDialog from '@/renderer/components/UpdateDialog.vue'
|
||||
import { onMounted } from 'vue'
|
||||
import { useAppStore } from '@/renderer/store/app'
|
||||
|
||||
// 使用应用商店来管理应用状态
|
||||
const appStore = useAppStore()
|
||||
|
||||
onMounted(() => {
|
||||
// 在应用启动时检查更新
|
||||
setTimeout(() => {
|
||||
checkForUpdates()
|
||||
}, 3000) // 延迟3秒后检查更新,避免影响应用启动速度
|
||||
|
||||
// 监听主进程发来的更新相关事件
|
||||
window.mainApi.on('update-available', (_, info) => {
|
||||
appStore.setUpdateStatus('available', info.version)
|
||||
})
|
||||
|
||||
window.mainApi.on('update-not-available', (_, info) => {
|
||||
appStore.setUpdateStatus('not-available', info.version)
|
||||
})
|
||||
|
||||
window.mainApi.on('update-error', (_, error) => {
|
||||
appStore.setUpdateStatus('error', undefined, error.message || String(error))
|
||||
})
|
||||
|
||||
window.mainApi.on('update-download-progress', (_, progress) => {
|
||||
// 这个事件通过pinia状态管理,不需要在这里单独处理
|
||||
console.log('下载进度:', progress)
|
||||
})
|
||||
|
||||
window.mainApi.on('update-downloaded', (_, info) => {
|
||||
appStore.setUpdateStatus('downloaded')
|
||||
console.log('更新已下载,准备安装:', info)
|
||||
})
|
||||
})
|
||||
|
||||
const checkForUpdates = async () => {
|
||||
try {
|
||||
// 显示检查更新状态
|
||||
appStore.setUpdateStatus('checking')
|
||||
|
||||
// 调用主进程检查更新
|
||||
const result = await window.mainApi.invoke('msgCheckForUpdates')
|
||||
|
||||
if (result.error) {
|
||||
console.error('检查更新时出错:', result.error)
|
||||
appStore.setUpdateStatus('error', result.error)
|
||||
return
|
||||
}
|
||||
|
||||
if (result.updateAvailable) {
|
||||
// 发现新版本,显示更新提示
|
||||
appStore.setUpdateStatus('available', result.currentVersion)
|
||||
} else {
|
||||
// 当前已是最新版本
|
||||
appStore.setUpdateStatus('not-available', result.currentVersion)
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('检查更新时出错:', error)
|
||||
appStore.setUpdateStatus(
|
||||
'error',
|
||||
error instanceof Error ? error.message : String(error)
|
||||
)
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@@ -8,6 +74,7 @@ import GlobalDialog from '@/renderer/components/GlobalDialog.vue'
|
||||
<router-view />
|
||||
</DefaultLayout>
|
||||
<GlobalDialog />
|
||||
<UpdateDialog />
|
||||
</template>
|
||||
|
||||
<style>
|
||||
|
||||
Reference in new issue
Block a user