Refactor(Protocol): Optimize desktop and app protocol

This commit is contained in:
2024-05-21 17:41:57 +08:00
parent 3dc434a6ac
commit a7577373ef
8 changed files with 15 additions and 10 deletions

View File

@@ -1,5 +1,6 @@
VITE_PLATFORM=DESKTOP VITE_PLATFORM=DESKTOP
VITE_PROTOCOL=oxygen-desktop VITE_DESKTOP_PROTOCOL=oxygen-desktop
VITE_APP_PROTOCOL=oxygen-app
VITE_UI_URL=${DEV_UI_URL} VITE_UI_URL=${DEV_UI_URL}
VITE_API_URL=${DEV_API_URL} VITE_API_URL=${DEV_API_URL}
VITE_API_TOKEN_URL=${VITE_API_URL}/token VITE_API_TOKEN_URL=${VITE_API_URL}/token

View File

@@ -1,5 +1,6 @@
VITE_PLATFORM=DESKTOP VITE_PLATFORM=DESKTOP
VITE_PROTOCOL=oxygen-desktop VITE_DESKTOP_PROTOCOL=oxygen-desktop
VITE_APP_PROTOCOL=oxygen-app
VITE_UI_URL=${PRODUCT_UI_URL} VITE_UI_URL=${PRODUCT_UI_URL}
VITE_API_URL=${PRODUCT_API_URL} VITE_API_URL=${PRODUCT_API_URL}
VITE_API_TOKEN_URL=${VITE_API_URL}/token VITE_API_TOKEN_URL=${VITE_API_URL}/token

View File

@@ -1,6 +1,7 @@
NODE_ENV=development NODE_ENV=development
VITE_PLATFORM=DESKTOP VITE_PLATFORM=DESKTOP
VITE_PROTOCOL=oxygen-desktop VITE_DESKTOP_PROTOCOL=oxygen-desktop
VITE_APP_PROTOCOL=oxygen-app
VITE_UI_URL=${TEST_UI_URL} VITE_UI_URL=${TEST_UI_URL}
VITE_API_URL=${TEST_API_URL} VITE_API_URL=${TEST_API_URL}
VITE_API_TOKEN_URL=${VITE_API_URL}/token VITE_API_TOKEN_URL=${VITE_API_URL}/token

View File

@@ -2,7 +2,8 @@ type Platform = 'WEB' | 'DESKTOP' | 'ANDROID'
interface ImportMetaEnv { interface ImportMetaEnv {
readonly VITE_PLATFORM: Platform readonly VITE_PLATFORM: Platform
readonly VITE_PROTOCOL: string readonly VITE_DESKTOP_PROTOCOL: string
readonly VITE_APP_PROTOCOL: string
readonly VITE_UI_URL: string readonly VITE_UI_URL: string
readonly VITE_API_URL: string readonly VITE_API_URL: string
readonly VITE_API_TOKEN_URL: string readonly VITE_API_TOKEN_URL: string

View File

@@ -18,11 +18,11 @@ if (!app.isPackaged) {
args.push(path.resolve(process.argv[1])) args.push(path.resolve(process.argv[1]))
} }
args.push('--') args.push('--')
app.setAsDefaultProtocolClient(import.meta.env.VITE_PROTOCOL, process.execPath, args) app.setAsDefaultProtocolClient(import.meta.env.VITE_DESKTOP_PROTOCOL, process.execPath, args)
// app.removeAsDefaultProtocolClient(import.meta.env.VITE_PROTOCOL, process.execPath, args) // app.removeAsDefaultProtocolClient(import.meta.env.VITE_DESKTOP_PROTOCOL, process.execPath, args)
const handleArgv = (argv: string[]) => { const handleArgv = (argv: string[]) => {
const prefix = `${import.meta.env.VITE_PROTOCOL}:` const prefix = `${import.meta.env.VITE_DESKTOP_PROTOCOL}:`
const offset = app.isPackaged ? 1 : 2 const offset = app.isPackaged ? 1 : 2
const url = argv.find((arg, index) => index >= offset && arg.startsWith(prefix)) const url = argv.find((arg, index) => index >= offset && arg.startsWith(prefix))
if (url) { if (url) {

View File

@@ -235,7 +235,7 @@ const StoreCard = ({
if (!checkDesktop()) { if (!checkDesktop()) {
void message.loading({ content: '启动桌面端中……', key: 'LOADING', duration: 0 }) void message.loading({ content: '启动桌面端中……', key: 'LOADING', duration: 0 })
protocolCheck( protocolCheck(
`oxygen://openurl/view/${author.username}/${toolId}`, `${import.meta.env.VITE_DESKTOP_PROTOCOL}://openurl/view/${author.username}/${toolId}`,
() => { () => {
void message.warning('打开失败,此应用需要桌面端环境,请安装桌面端后重试') void message.warning('打开失败,此应用需要桌面端环境,请安装桌面端后重试')
void message.destroy('LOADING') void message.destroy('LOADING')

View File

@@ -6,7 +6,8 @@ type Platform = 'WEB' | 'DESKTOP' | 'ANDROID'
interface ImportMetaEnv { interface ImportMetaEnv {
readonly VITE_PLATFORM: Platform readonly VITE_PLATFORM: Platform
readonly VITE_PROTOCOL: string readonly VITE_DESKTOP_PROTOCOL: string
readonly VITE_APP_PROTOCOL: string
readonly VITE_UI_URL: string readonly VITE_UI_URL: string
readonly VITE_API_URL: string readonly VITE_API_URL: string
readonly VITE_API_TOKEN_URL: string readonly VITE_API_TOKEN_URL: string

View File

@@ -153,4 +153,4 @@ export const getViewPath = (
} }
export const getAndroidUrl = (username: string, toolId: string) => export const getAndroidUrl = (username: string, toolId: string) =>
`oxygen://opentool/${username}/${toolId}` `${import.meta.env.VITE_APP_PROTOCOL}://opentool/${username}/${toolId}`