From 7afdc845fa11c7603b7ce2e713d1612530df3166 Mon Sep 17 00:00:00 2001 From: Julian Freeman Date: Mon, 30 Mar 2026 19:34:14 -0400 Subject: [PATCH] optimize fetch logic --- src/store/software.ts | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/src/store/software.ts b/src/store/software.ts index 29eb43d..f91480f 100644 --- a/src/store/software.ts +++ b/src/store/software.ts @@ -118,10 +118,21 @@ export const useSoftwareStore = defineStore('software', { }, async fetchEssentials() { - const res = await invoke('get_essentials') as any; - if (res) { - this.essentials = res.essentials; - this.essentialsVersion = res.version; + let repo = await invoke('get_essentials') as any; + + // 如果本地没有文件,则尝试联网获取一次 + if (!repo) { + try { + await invoke('sync_essentials'); + repo = await invoke('get_essentials') as any; + } catch (err) { + console.error('Initial sync failed:', err); + } + } + + if (repo) { + this.essentials = repo.essentials; + this.essentialsVersion = repo.version; } else { this.essentials = []; this.essentialsVersion = ''; @@ -161,23 +172,15 @@ export const useSoftwareStore = defineStore('software', { async fetchAllData() { this.loading = true; try { - // 在获取全量数据之前,先同步云端清单 - await invoke('sync_essentials').catch(() => {}); + // 先确保加载了必备清单(内部处理本地缺失逻辑) + await this.fetchEssentials(); - const [repo, all, updates] = await Promise.all([ - invoke('get_essentials') as Promise, + // 然后同步本地软件安装/更新状态,不再强制联网下载 JSON + const [all, updates] = await Promise.all([ invoke('get_all_software'), invoke('get_updates') ]); - if (repo) { - this.essentials = repo.essentials; - this.essentialsVersion = repo.version; - } else { - this.essentials = []; - this.essentialsVersion = ''; - } - this.allSoftware = all as any[]; this.updates = updates as any[]; this.lastFetched = Date.now();