From 3ba1f3542077b8cbc00c3c6e76d56b242ab5c77d Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Tue, 21 May 2024 17:41:09 +0800 Subject: [PATCH] Refactor(Protocol): Optimize desktop and app prtocol --- .env.development | 2 ++ .env.production | 2 ++ .env.testing | 2 ++ src/components/tools/StoreCard.tsx | 2 +- src/global.d.ts | 2 ++ src/util/navigation.ts | 2 +- 6 files changed, 10 insertions(+), 2 deletions(-) diff --git a/.env.development b/.env.development index 0c1ca3c..8da6dd0 100644 --- a/.env.development +++ b/.env.development @@ -1,4 +1,6 @@ VITE_PLATFORM=WEB +VITE_DESKTOP_PROTOCOL=oxygen-desktop +VITE_APP_PROTOCOL=oxygen-app VITE_UI_URL=${DEV_UI_URL} VITE_API_URL=${DEV_API_URL} VITE_API_TOKEN_URL=${VITE_API_URL}/token diff --git a/.env.production b/.env.production index 528d73a..2153461 100644 --- a/.env.production +++ b/.env.production @@ -1,4 +1,6 @@ VITE_PLATFORM=WEB +VITE_DESKTOP_PROTOCOL=oxygen-desktop +VITE_APP_PROTOCOL=oxygen-app VITE_UI_URL=${PRODUCT_UI_URL} VITE_API_URL=${PRODUCT_API_URL} VITE_API_TOKEN_URL=${VITE_API_URL}/token diff --git a/.env.testing b/.env.testing index b5fb949..1980edc 100644 --- a/.env.testing +++ b/.env.testing @@ -1,5 +1,7 @@ NODE_ENV=development VITE_PLATFORM=WEB +VITE_DESKTOP_PROTOCOL=oxygen-desktop +VITE_APP_PROTOCOL=oxygen-app VITE_UI_URL=${TEST_UI_URL} VITE_API_URL=${TEST_API_URL} VITE_API_TOKEN_URL=${VITE_API_URL}/token diff --git a/src/components/tools/StoreCard.tsx b/src/components/tools/StoreCard.tsx index c16e3d4..3b5e112 100644 --- a/src/components/tools/StoreCard.tsx +++ b/src/components/tools/StoreCard.tsx @@ -166,7 +166,7 @@ const StoreCard = ({ if (!checkDesktop()) { void message.loading({ content: '启动桌面端中……', key: 'LOADING', duration: 0 }) protocolCheck( - `oxygen://openurl/view/${author.username}/${toolId}`, + `${import.meta.env.VITE_DESKTOP_PROTOCOL}://openurl/view/${author.username}/${toolId}`, () => { void message.warning('打开失败,此应用需要桌面端环境,请安装桌面端后重试') void message.destroy('LOADING') diff --git a/src/global.d.ts b/src/global.d.ts index 5bcfef7..7a2b303 100644 --- a/src/global.d.ts +++ b/src/global.d.ts @@ -5,6 +5,8 @@ type Platform = 'WEB' | 'DESKTOP' | 'ANDROID' interface ImportMetaEnv { readonly VITE_PLATFORM: Platform + readonly VITE_DESKTOP_PROTOCOL: string + readonly VITE_APP_PROTOCOL: string readonly VITE_UI_URL: string readonly VITE_API_URL: string readonly VITE_API_TOKEN_URL: string diff --git a/src/util/navigation.ts b/src/util/navigation.ts index 140215a..06737d0 100644 --- a/src/util/navigation.ts +++ b/src/util/navigation.ts @@ -145,4 +145,4 @@ export const getViewPath = ( } export const getAndroidUrl = (username: string, toolId: string) => - `oxygen://opentool/${username}/${toolId}` + `${import.meta.env.VITE_APP_PROTOCOL}://opentool/${username}/${toolId}`