This commit is contained in:
zhanggy committed 2025-11-05 14:46:49 +08:00
1 parent fc250c54ed
commit 5eec516459
62 files changed
+3912 -3376

No files matched your search

+26 -26
View File
@@ -1,58 +1,58 @@
import { defineStore } from 'pinia'
import { defineStore } from 'pinia';
export interface UpdateStatus {
status: 'idle' | 'checking' | 'available' | 'not-available' | 'downloading' | 'downloaded' | 'error'
currentVersion?: string
error?: string
progress?: number
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
status: 'idle' as const,
} as UpdateStatus,
updateDialogVisible: false,
downloadProgress: 0
downloadProgress: 0,
}),
getters: {
isUpdateAvailable: (state) => state.updateStatus.status === 'available',
isCheckingForUpdates: (state) => state.updateStatus.status === 'checking',
hasUpdateError: (state) => state.updateStatus.status === 'error'
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 }
this.updateStatus = { status, currentVersion, error };
},
showUpdateDialog() {
this.updateDialogVisible = true
this.updateDialogVisible = true;
},
hideUpdateDialog() {
this.updateDialogVisible = false
this.updateDialogVisible = false;
},
setDownloadProgress(progress: number) {
this.downloadProgress = progress
this.downloadProgress = progress;
},
// 启动更新下载
async startUpdateDownload() {
try {
this.setUpdateStatus('downloading')
const result = await window.mainApi.invoke('msgDownloadUpdate')
this.setUpdateStatus('downloading');
const result = await window.mainApi.invoke('msgDownloadUpdate');
if (result.success) {
this.setUpdateStatus('downloaded')
this.setUpdateStatus('downloaded');
} else {
this.setUpdateStatus('error', undefined, result.error)
this.setUpdateStatus('error', undefined, result.error);
}
} catch (error) {
this.setUpdateStatus('error', undefined, error instanceof Error ? error.message : String(error))
this.setUpdateStatus('error', undefined, error instanceof Error ? error.message : String(error));
}
}
}
})
},
},
});