From 4ecea4a8b81dfd8c232438f4ea1d77ed293e3ee2 Mon Sep 17 00:00:00 2001 From: shenmo Date: Sun, 15 Mar 2026 10:54:33 +0800 Subject: [PATCH] feat: enhance app detail modal to prioritize installed version based on installation status - Updated `openDetail` function to check installation status for both Spark and APM versions, setting `viewingOrigin` accordingly. - Modified logic to determine which app version to display in screenshots based on installation status. - Improved handling of `viewingOrigin` in `AppDetailModal.vue` to default to Spark if no specific version is installed. --- src/App.vue | 46 +++++++++++++++++++++++-------- src/components/AppDetailModal.vue | 4 ++- 2 files changed, 38 insertions(+), 12 deletions(-) diff --git a/src/App.vue b/src/App.vue index 7ff753f8..c75efa20 100644 --- a/src/App.vue +++ b/src/App.vue @@ -350,7 +350,7 @@ const selectCategory = (category: string) => { } }; -const openDetail = (app: App | Record) => { +const openDetail = async (app: App | Record) => { // 提取 pkgname(必须存在) const pkgname = (app as Record).pkgname as string; if (!pkgname) { @@ -389,10 +389,40 @@ const openDetail = (app: App | Record) => { } as App; } - // 后续逻辑使用 fullApp + // 合并应用:先检查 Spark/APM 安装状态,已安装的版本优先展示 + if (fullApp.isMerged && (fullApp.sparkApp || fullApp.apmApp)) { + const [sparkInstalled, apmInstalled] = await Promise.all([ + fullApp.sparkApp + ? window.ipcRenderer.invoke("check-installed", { + pkgname: fullApp.sparkApp.pkgname, + origin: "spark", + }) as Promise + : Promise.resolve(false), + fullApp.apmApp + ? window.ipcRenderer.invoke("check-installed", { + pkgname: fullApp.apmApp.pkgname, + origin: "apm", + }) as Promise + : Promise.resolve(false), + ]); + if (sparkInstalled && !apmInstalled) { + fullApp.viewingOrigin = "spark"; + } else if (apmInstalled && !sparkInstalled) { + fullApp.viewingOrigin = "apm"; + } + // 若都安装或都未安装,不设置 viewingOrigin,由模态框默认展示 spark + } + + const displayAppForScreenshots = + fullApp.viewingOrigin !== undefined && fullApp.isMerged + ? (fullApp.viewingOrigin === "spark" + ? fullApp.sparkApp + : fullApp.apmApp) ?? fullApp + : fullApp; + currentApp.value = fullApp; currentScreenIndex.value = 0; - loadScreenshots(fullApp); + loadScreenshots(displayAppForScreenshots); showModal.value = true; currentAppSparkInstalled.value = false; @@ -891,10 +921,7 @@ const loadCategories = async () => { for (const mode of modes) { const finalArch = mode === "spark" ? `${arch}-store` : `${arch}-apm`; - const path = - mode === "spark" - ? "/store/categories.json" - : `/${finalArch}/categories.json`; + const path = `/${finalArch}/categories.json`; try { const response = await axiosInstance.get(cacheBuster(path)); @@ -943,10 +970,7 @@ const loadApps = async (onFirstBatch?: () => void) => { const finalArch = mode === "spark" ? `${arch}-store` : `${arch}-apm`; - const path = - mode === "spark" - ? `/store/${category}/applist.json` - : `/${finalArch}/${category}/applist.json`; + const path = `/${finalArch}/${category}/applist.json`; logger.info(`加载分类: ${category} (来源: ${mode})`); const categoryApps = await fetchWithRetry( diff --git a/src/components/AppDetailModal.vue b/src/components/AppDetailModal.vue index cc9445a5..c0f690e5 100644 --- a/src/components/AppDetailModal.vue +++ b/src/components/AppDetailModal.vue @@ -298,7 +298,9 @@ watch( isIconLoaded.value = false; if (newApp) { if (newApp.isMerged) { - viewingOrigin.value = newApp.sparkApp ? "spark" : "apm"; + // 若父组件已根据安装状态设置了优先展示的版本,则使用;否则默认 Spark + viewingOrigin.value = + newApp.viewingOrigin ?? (newApp.sparkApp ? "spark" : "apm"); } else { viewingOrigin.value = newApp.origin; }