support disable config
This commit is contained in:
@@ -47,7 +47,8 @@ export const useSoftwareStore = defineStore('software', {
|
||||
initStatus: '正在检查系统环境...',
|
||||
lastFetched: 0,
|
||||
refreshTimer: null as any,
|
||||
batchQueue: [] as string[]
|
||||
batchQueue: [] as string[],
|
||||
postInstallPrefs: {} as Record<string, boolean> // 记录用户对每个软件后安装配置的偏好
|
||||
}),
|
||||
getters: {
|
||||
mergedEssentials: (state) => {
|
||||
@@ -66,13 +67,11 @@ export const useSoftwareStore = defineStore('software', {
|
||||
let targetVersion = recommendedVersion || availableVersion;
|
||||
|
||||
if (isInstalled) {
|
||||
// 逻辑:已安装 >= 推荐 -> 已安装(禁用)
|
||||
// 逻辑:已安装 < 推荐 -> 更新
|
||||
const comp = compareVersions(currentVersion, recommendedVersion);
|
||||
if (comp >= 0) {
|
||||
displayStatus = task ? task.status : 'installed';
|
||||
actionLabel = '已安装';
|
||||
targetVersion = undefined; // 禁用安装
|
||||
targetVersion = undefined;
|
||||
} else {
|
||||
actionLabel = '更新';
|
||||
targetVersion = recommendedVersion;
|
||||
@@ -82,6 +81,9 @@ export const useSoftwareStore = defineStore('software', {
|
||||
targetVersion = recommendedVersion || availableVersion;
|
||||
}
|
||||
|
||||
// 获取偏好,默认开启
|
||||
const enablePostInstall = state.postInstallPrefs[item.id] !== false;
|
||||
|
||||
return {
|
||||
...item,
|
||||
version: currentVersion,
|
||||
@@ -90,19 +92,22 @@ export const useSoftwareStore = defineStore('software', {
|
||||
status: displayStatus,
|
||||
progress: task ? task.progress : 0,
|
||||
actionLabel,
|
||||
targetVersion // 传递给视图,用于点击安装
|
||||
targetVersion,
|
||||
enablePostInstall
|
||||
};
|
||||
});
|
||||
},
|
||||
sortedUpdates: (state) => {
|
||||
return [...state.updates].map(item => {
|
||||
const task = state.activeTasks[item.id];
|
||||
const enablePostInstall = state.postInstallPrefs[item.id] !== false;
|
||||
return {
|
||||
...item,
|
||||
status: task ? task.status : 'idle',
|
||||
progress: task ? task.progress : 0,
|
||||
actionLabel: '更新',
|
||||
targetVersion: item.available_version // 更新页面永远追求最新版
|
||||
targetVersion: item.available_version,
|
||||
enablePostInstall
|
||||
};
|
||||
}).sort(sortByName);
|
||||
},
|
||||
@@ -113,7 +118,6 @@ export const useSoftwareStore = defineStore('software', {
|
||||
}
|
||||
},
|
||||
actions: {
|
||||
// ... (initializeApp, saveSettings, syncEssentials stay the same)
|
||||
async initializeApp() {
|
||||
if (this.isInitialized) return;
|
||||
this.initStatus = '正在加载应用配置...';
|
||||
@@ -230,6 +234,9 @@ export const useSoftwareStore = defineStore('software', {
|
||||
async install(id: string, targetVersion?: string) {
|
||||
const software = this.findSoftware(id)
|
||||
if (software) {
|
||||
// 根据偏好决定是否开启后安装配置
|
||||
const enablePostInstall = this.postInstallPrefs[id] !== false;
|
||||
|
||||
this.activeTasks[id] = { status: 'pending', progress: 0, targetVersion };
|
||||
try {
|
||||
await invoke('install_software', {
|
||||
@@ -237,7 +244,8 @@ export const useSoftwareStore = defineStore('software', {
|
||||
id,
|
||||
version: targetVersion,
|
||||
use_manifest: software.use_manifest || false,
|
||||
manifest_url: software.manifest_url || null
|
||||
manifest_url: software.manifest_url || null,
|
||||
enable_post_install: enablePostInstall
|
||||
}
|
||||
})
|
||||
} catch (err) {
|
||||
@@ -247,26 +255,26 @@ export const useSoftwareStore = defineStore('software', {
|
||||
}
|
||||
},
|
||||
|
||||
// 注册批量任务
|
||||
togglePostInstallPref(id: string) {
|
||||
const current = this.postInstallPrefs[id] !== false;
|
||||
this.postInstallPrefs[id] = !current;
|
||||
},
|
||||
|
||||
startBatch(ids: string[]) {
|
||||
this.batchQueue = [...ids];
|
||||
},
|
||||
|
||||
// 引入防抖刷新:仅在批量任务全部处理完后的 2 秒执行全量扫描
|
||||
scheduleDataRefresh() {
|
||||
if (this.refreshTimer) clearTimeout(this.refreshTimer);
|
||||
|
||||
this.refreshTimer = setTimeout(async () => {
|
||||
await this.fetchAllData();
|
||||
|
||||
// 刷新完成后清理所有已终结(成功或失败)的任务状态快照
|
||||
Object.keys(this.activeTasks).forEach(id => {
|
||||
const status = this.activeTasks[id].status;
|
||||
if (status === 'success' || status === 'error') {
|
||||
delete this.activeTasks[id];
|
||||
}
|
||||
});
|
||||
|
||||
this.refreshTimer = null;
|
||||
}, 2000);
|
||||
},
|
||||
@@ -284,13 +292,10 @@ export const useSoftwareStore = defineStore('software', {
|
||||
const { id, status, progress } = event.payload
|
||||
const task = this.activeTasks[id];
|
||||
|
||||
// 更新任务状态
|
||||
this.activeTasks[id] = { status, progress, targetVersion: task?.targetVersion };
|
||||
|
||||
// 当任务达到终态(成功或失败)时。注意:'configuring' 不是终态。
|
||||
if (status === 'success' || status === 'error') {
|
||||
if (status === 'success') {
|
||||
// 立即进行局部刷新
|
||||
try {
|
||||
const latestInfo = await invoke('get_software_info', { id }) as any;
|
||||
if (latestInfo) {
|
||||
@@ -305,11 +310,9 @@ export const useSoftwareStore = defineStore('software', {
|
||||
console.error('Partial refresh failed:', err);
|
||||
}
|
||||
|
||||
// 立即更新勾选状态
|
||||
this.selectedEssentialIds = this.selectedEssentialIds.filter(i => i !== id);
|
||||
this.selectedUpdateIds = this.selectedUpdateIds.filter(i => i !== id);
|
||||
|
||||
// 保持绿色“已完成”状态 3 秒,然后自动回归真实状态
|
||||
setTimeout(() => {
|
||||
if (this.activeTasks[id]?.status === 'success') {
|
||||
delete this.activeTasks[id];
|
||||
@@ -317,11 +320,9 @@ export const useSoftwareStore = defineStore('software', {
|
||||
}, 3000);
|
||||
}
|
||||
|
||||
// 检查是否属于正在进行的批量任务
|
||||
const index = this.batchQueue.indexOf(id);
|
||||
if (index !== -1) {
|
||||
this.batchQueue.splice(index, 1);
|
||||
// 只有批量任务全部结束后,才执行一次全量刷新作为保障
|
||||
if (this.batchQueue.length === 0) {
|
||||
this.scheduleDataRefresh();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user