This commit is contained in:
Julian Freeman
2026-04-18 15:27:00 -04:00
parent bba113e089
commit fe86431899
7 changed files with 266 additions and 123 deletions

View File

@@ -29,6 +29,11 @@ export interface LogEntry {
status: 'info' | 'success' | 'error';
}
interface SyncEssentialsResult {
status: 'updated' | 'cache_used';
message: string;
}
export const useSoftwareStore = defineStore('software', {
state: () => ({
essentials: [] as any[],
@@ -140,8 +145,9 @@ export const useSoftwareStore = defineStore('software', {
async syncEssentials() {
this.loading = true;
try {
await invoke('sync_essentials');
const result = await invoke('sync_essentials') as SyncEssentialsResult;
await this.fetchEssentials();
return result;
} finally {
this.loading = false;
}
@@ -200,6 +206,7 @@ export const useSoftwareStore = defineStore('software', {
try {
const res = await invoke('get_updates')
this.updates = res as any[]
await this.loadIconsForUpdates()
if (this.selectedUpdateIds.length === 0) this.selectAll('update');
} finally {
this.loading = false
@@ -225,6 +232,7 @@ export const useSoftwareStore = defineStore('software', {
]);
this.allSoftware = all as any[];
this.updates = updates as any[];
await this.loadIconsForUpdates()
this.lastFetched = Date.now();
if (this.selectedEssentialIds.length === 0) this.selectAll('essential');
} finally {
@@ -284,6 +292,17 @@ export const useSoftwareStore = defineStore('software', {
this.updates.find(s => s.id === id) ||
this.allSoftware.find(s => s.id === id)
},
async loadIconsForUpdates() {
const targets = this.updates.filter(item => !item.icon_url && item.id && item.name);
await Promise.allSettled(targets.map(async (item) => {
const iconUrl = await invoke('get_software_icon', { id: item.id, name: item.name }) as string | null;
if (!iconUrl) return;
const target = this.updates.find(update => update.id === item.id);
if (target) {
target.icon_url = iconUrl;
}
}));
},
initListener() {
if ((window as any).__tauri_listener_init) return;
(window as any).__tauri_listener_init = true;