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:
72
src/stores/update.ts
Normal file
72
src/stores/update.ts
Normal 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);
|
||||
}
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user