fetch essentials from url

This commit is contained in:
Julian Freeman
2026-03-30 17:45:09 -04:00
parent 8f55da1940
commit 626a9c21b0
7 changed files with 980 additions and 55 deletions

View File

@@ -20,12 +20,16 @@ export const useSoftwareStore = defineStore('software', {
selectedEssentialIds: [] as string[],
selectedUpdateIds: [] as string[],
logs: [] as LogEntry[],
settings: {
repo_url: 'https://karlblue.github.io/winget-repo'
},
loading: false,
isInitialized: false,
initStatus: '正在检查系统环境...',
lastFetched: 0
}),
getters: {
// ... (mergedEssentials, sortedUpdates, sortedAllSoftware, isBusy getters stay the same)
mergedEssentials: (state) => {
return state.essentials.map(item => {
const isInstalled = state.allSoftware.some(s => s.id.toLowerCase() === item.id.toLowerCase());
@@ -55,8 +59,10 @@ export const useSoftwareStore = defineStore('software', {
actions: {
async initializeApp() {
if (this.isInitialized) return;
this.initStatus = '正在同步 Winget 模块...';
this.initStatus = '正在加载应用配置...';
try {
this.settings = await invoke('get_settings');
this.initStatus = '正在同步 Winget 模块...';
await invoke('initialize_app');
this.isInitialized = true;
} catch (err) {
@@ -64,6 +70,23 @@ export const useSoftwareStore = defineStore('software', {
setTimeout(() => { this.isInitialized = true; }, 2000);
}
},
async saveSettings(newSettings: any) {
await invoke('save_settings', { settings: newSettings });
this.settings = newSettings;
},
async syncEssentials() {
this.loading = true;
try {
await invoke('sync_essentials');
await this.fetchEssentials();
} finally {
this.loading = false;
}
},
// ... (Selection methods stay the same)
toggleSelection(id: string, type: 'essential' | 'update') {
if (this.isBusy) return;
const list = type === 'essential' ? this.selectedEssentialIds : this.selectedUpdateIds;
@@ -130,6 +153,9 @@ export const useSoftwareStore = defineStore('software', {
async fetchAllData() {
this.loading = true;
try {
// 在获取全量数据之前,先同步云端清单
await invoke('sync_essentials').catch(() => {});
const [essentials, all, updates] = await Promise.all([
invoke('get_essentials'),
invoke('get_all_software'),