feat: add auto-update functionality with settings UI

- Implement electron-updater integration with IPC handlers for update operations
- Add Pinia store for managing update state and user preferences
- Create settings UI with version display, update controls, and auto-update toggles
- Update IPC constants and preload API for update-related communication
- Refactor preload invoke methods to use async IPC consistently
- Add rounded corners to settings page layout for better visual consistency
This commit is contained in:
DEV_DSW
2026-04-09 15:15:23 +08:00
parent a8bfbff0e9
commit 1aa28a7808
10 changed files with 411 additions and 96 deletions

72
src/stores/update.ts Normal file
View File

@@ -0,0 +1,72 @@
import { defineStore } from 'pinia';
import { IPC_EVENTS, CONFIG_KEYS } from '@lib/constants';
export const useUpdateStore = defineStore('update', {
state: () => ({
status: 'idle' as 'idle' | 'checking' | 'available' | 'downloading' | 'downloaded' | 'error' | 'not-available',
currentVersion: '1.0.0',
updateInfo: null as any,
progress: null as any,
error: null as string | null,
initialized: false,
autoCheckUpdate: true,
autoDownloadUpdate: false,
}),
actions: {
async init() {
if (this.initialized) return;
this.initialized = true;
try {
this.currentVersion = await window.api.invoke(IPC_EVENTS.UPDATE_VERSION);
// Initialize config
const checkUpdate = await window.api.invoke(IPC_EVENTS.GET_CONFIG, CONFIG_KEYS.AUTO_CHECK_UPDATE);
if (checkUpdate !== undefined) this.autoCheckUpdate = checkUpdate;
const downloadUpdate = await window.api.invoke(IPC_EVENTS.GET_CONFIG, CONFIG_KEYS.AUTO_DOWNLOAD_UPDATE);
if (downloadUpdate !== undefined) this.autoDownloadUpdate = downloadUpdate;
} catch (error) {
console.error('Failed to init update store:', error);
}
window.api.on(IPC_EVENTS.UPDATE_STATUS_CHANGED, (data: any) => {
this.status = data.status;
if (data.info) this.updateInfo = data.info;
if (data.progress) this.progress = data.progress;
if (data.error) this.error = data.error;
});
},
async setAutoCheckUpdate(val: boolean) {
this.autoCheckUpdate = val;
window.api.send(IPC_EVENTS.UPDATE_CONFIG, { [CONFIG_KEYS.AUTO_CHECK_UPDATE]: val });
},
async setAutoDownloadUpdate(val: boolean) {
this.autoDownloadUpdate = val;
window.api.send(IPC_EVENTS.UPDATE_CONFIG, { [CONFIG_KEYS.AUTO_DOWNLOAD_UPDATE]: val });
},
async checkUpdate() {
this.error = null;
this.status = 'checking';
try {
await window.api.invoke(IPC_EVENTS.UPDATE_CHECK);
} catch (error) {
this.status = 'error';
this.error = String(error);
}
},
async downloadUpdate() {
this.status = 'downloading';
try {
await window.api.invoke(IPC_EVENTS.UPDATE_DOWNLOAD);
} catch (error) {
this.status = 'error';
this.error = String(error);
}
},
installUpdate() {
window.api.invoke(IPC_EVENTS.UPDATE_INSTALL);
}
}
});