From 3f9447d2cc91e9c78965daf864d90258fb42db10 Mon Sep 17 00:00:00 2001 From: shenmo Date: Sun, 29 Mar 2026 13:58:52 +0800 Subject: [PATCH] =?UTF-8?q?feat(deep-link):=20=E6=94=AF=E6=8C=81=E9=80=9A?= =?UTF-8?q?=E8=BF=87=20store=20=E5=8D=8F=E8=AE=AE=E7=9B=B4=E6=8E=A5?= =?UTF-8?q?=E6=89=93=E5=BC=80=E5=BA=94=E7=94=A8=E8=AF=A6=E6=83=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 添加对 legacy store 协议格式的支持,当收到 spk://store/category/pkgname 格式的 deep link 时,忽略 category 直接使用 pkgname 查找并打开应用详情。如果应用未找到,则回退到搜索模式。 --- electron/main/deeplink.ts | 19 +++++++++++++++++++ src/App.vue | 23 ++++++++++++++++++++++- 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/electron/main/deeplink.ts b/electron/main/deeplink.ts index fc20cb2c..d34aa9fe 100644 --- a/electron/main/deeplink.ts +++ b/electron/main/deeplink.ts @@ -99,6 +99,25 @@ export function handleCommandLine(commandLine: string[]) { `Deep link: invalid search format, expected /pkgname, got ${url.pathname}`, ); } + } else if (action === "store") { + // Format: spk://store/category/pkgname (legacy format) + // url.pathname will be '/category/pkgname' + const pathParts = url.pathname.split("/").filter(Boolean); + // 老协议格式: spk://store/category/pkgname + // 现在忽略 category,直接使用 pkgname 查找应用 + const pkgname = pathParts.length >= 2 ? pathParts[1] : pathParts[0]; + if (pkgname) { + query.pkgname = pkgname; + logger.info( + `Deep link: store legacy format query found: ${JSON.stringify(query)}`, + ); + // 使用 search 事件来处理,前端会根据 pkgname 直接打开应用详情 + listeners.emit("search", query); + } else { + logger.warn( + `Deep link: invalid store format, expected /category/pkgname, got ${url.pathname}`, + ); + } } else { logger.warn(`Deep link: unknown action ${action}`); } diff --git a/src/App.vue b/src/App.vue index 66656155..71235a53 100644 --- a/src/App.vue +++ b/src/App.vue @@ -1146,7 +1146,28 @@ onMounted(async () => { window.ipcRenderer.on( "deep-link-search", (_event: IpcRendererEvent, data: { pkgname: string }) => { - searchQuery.value = data.pkgname; + // 根据包名直接打开应用详情 + const tryOpen = () => { + const target = apps.value.find((a) => a.pkgname === data.pkgname); + if (target) { + openDetail(target); + } else { + // 如果找不到应用,回退到搜索模式 + searchQuery.value = data.pkgname; + logger.warn(`Deep link: app ${data.pkgname} not found, fallback to search`); + } + }; + + if (loading.value) { + const stop = watch(loading, (val) => { + if (!val) { + tryOpen(); + stop(); + } + }); + } else { + tryOpen(); + } }, );