fix updating ui
This commit is contained in:
@@ -46,24 +46,27 @@ export const useSoftwareStore = defineStore('software', {
|
||||
});
|
||||
},
|
||||
sortedUpdates: (state) => [...state.updates].sort(sortByName),
|
||||
sortedAllSoftware: (state) => [...state.allSoftware].sort(sortByName)
|
||||
sortedAllSoftware: (state) => [...state.allSoftware].sort(sortByName),
|
||||
// 全局繁忙状态:只要有任何软件在等待或安装中,就锁定关键操作
|
||||
isBusy: (state) => {
|
||||
const allItems = [...state.essentials, ...state.updates, ...state.allSoftware];
|
||||
return allItems.some(item => item.status === 'pending' || item.status === 'installing');
|
||||
}
|
||||
},
|
||||
actions: {
|
||||
async initializeApp() {
|
||||
if (this.isInitialized) return;
|
||||
|
||||
this.initStatus = '正在同步 Winget 模块...';
|
||||
try {
|
||||
await invoke('initialize_app');
|
||||
this.isInitialized = true;
|
||||
} catch (err) {
|
||||
this.initStatus = '环境配置失败,请检查运行日志';
|
||||
console.error('Init failed:', err);
|
||||
// 即使失败也允许进入,让用户看日志
|
||||
setTimeout(() => { this.isInitialized = true; }, 2000);
|
||||
}
|
||||
},
|
||||
toggleSelection(id: string, type: 'essential' | 'update') {
|
||||
if (this.isBusy) return; // 繁忙时禁止修改勾选
|
||||
const list = type === 'essential' ? this.selectedEssentialIds : this.selectedUpdateIds;
|
||||
const index = list.indexOf(id);
|
||||
if (index === -1) list.push(id);
|
||||
@@ -95,6 +98,7 @@ export const useSoftwareStore = defineStore('software', {
|
||||
this.essentials = await invoke('get_essentials')
|
||||
},
|
||||
async fetchUpdates() {
|
||||
if (this.isBusy) return;
|
||||
this.loading = true
|
||||
try {
|
||||
const res = await invoke('get_updates')
|
||||
@@ -105,6 +109,7 @@ export const useSoftwareStore = defineStore('software', {
|
||||
}
|
||||
},
|
||||
async fetchAll() {
|
||||
if (this.isBusy) return;
|
||||
this.loading = true
|
||||
try {
|
||||
const res = await invoke('get_all_software')
|
||||
@@ -114,6 +119,7 @@ export const useSoftwareStore = defineStore('software', {
|
||||
}
|
||||
},
|
||||
async syncDataIfNeeded(force = false) {
|
||||
if (this.isBusy) return;
|
||||
const now = Date.now();
|
||||
const CACHE_TIMEOUT = 5 * 60 * 1000;
|
||||
if (!force && this.allSoftware.length > 0 && (now - this.lastFetched < CACHE_TIMEOUT)) {
|
||||
@@ -140,8 +146,12 @@ export const useSoftwareStore = defineStore('software', {
|
||||
}
|
||||
},
|
||||
async install(id: string) {
|
||||
// 这里的 logic 同时负责单个安装和批量安装的任务入队
|
||||
const software = this.findSoftware(id)
|
||||
if (software) software.status = 'pending'
|
||||
if (software) {
|
||||
// 进入队列前统一标记为等待中
|
||||
software.status = 'pending';
|
||||
}
|
||||
await invoke('install_software', { id })
|
||||
},
|
||||
findSoftware(id: string) {
|
||||
|
||||
Reference in New Issue
Block a user