optimize fetch logic
This commit is contained in:
@@ -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<any>,
|
||||
// 然后同步本地软件安装/更新状态,不再强制联网下载 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();
|
||||
|
||||
Reference in New Issue
Block a user