fix fetch bug
This commit is contained in:
@@ -20,6 +20,19 @@ export const useCatalogStore = defineStore('catalog', {
|
|||||||
lastFetched: 0
|
lastFetched: 0
|
||||||
}),
|
}),
|
||||||
actions: {
|
actions: {
|
||||||
|
async ensureEssentialsAvailable() {
|
||||||
|
const cachedRepo = await invoke('get_essentials') as unknown
|
||||||
|
if (cachedRepo) return true
|
||||||
|
|
||||||
|
try {
|
||||||
|
await invoke('sync_essentials')
|
||||||
|
return true
|
||||||
|
} catch (err) {
|
||||||
|
console.error('Initial sync failed:', err)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
async initializeApp() {
|
async initializeApp() {
|
||||||
if (this.isInitialized) return
|
if (this.isInitialized) return
|
||||||
this.initStatus = '正在加载应用配置...'
|
this.initStatus = '正在加载应用配置...'
|
||||||
@@ -51,15 +64,8 @@ export const useCatalogStore = defineStore('catalog', {
|
|||||||
},
|
},
|
||||||
|
|
||||||
async fetchEssentials() {
|
async fetchEssentials() {
|
||||||
|
await this.ensureEssentialsAvailable()
|
||||||
let response = await invoke('get_essentials_status') as EssentialsStatusResponse
|
let response = await invoke('get_essentials_status') as EssentialsStatusResponse
|
||||||
if ((!response || !response[1]) && !(await invoke('get_essentials') as unknown)) {
|
|
||||||
try {
|
|
||||||
await invoke('sync_essentials')
|
|
||||||
response = await invoke('get_essentials_status') as EssentialsStatusResponse
|
|
||||||
} catch (err) {
|
|
||||||
console.error('Initial sync failed:', err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (response && Array.isArray(response[1])) {
|
if (response && Array.isArray(response[1])) {
|
||||||
this.essentialsVersion = response[0] || ''
|
this.essentialsVersion = response[0] || ''
|
||||||
this.essentials = response[1]
|
this.essentials = response[1]
|
||||||
@@ -93,6 +99,7 @@ export const useCatalogStore = defineStore('catalog', {
|
|||||||
async fetchAllData() {
|
async fetchAllData() {
|
||||||
this.loading = true
|
this.loading = true
|
||||||
try {
|
try {
|
||||||
|
await this.ensureEssentialsAvailable()
|
||||||
const snapshot = await invoke('get_dashboard_snapshot') as DashboardSnapshot
|
const snapshot = await invoke('get_dashboard_snapshot') as DashboardSnapshot
|
||||||
this.applyDashboardSnapshot(snapshot)
|
this.applyDashboardSnapshot(snapshot)
|
||||||
await this.loadIconsForUpdates()
|
await this.loadIconsForUpdates()
|
||||||
|
|||||||
Reference in New Issue
Block a user