Refactor(Protocol): Optimize desktop and app protocol
This commit is contained in:
3
src/main/global.d.ts
vendored
3
src/main/global.d.ts
vendored
@@ -2,7 +2,8 @@ type Platform = 'WEB' | 'DESKTOP' | 'ANDROID'
|
||||
|
||||
interface ImportMetaEnv {
|
||||
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_API_URL: string
|
||||
readonly VITE_API_TOKEN_URL: string
|
||||
|
||||
@@ -18,11 +18,11 @@ if (!app.isPackaged) {
|
||||
args.push(path.resolve(process.argv[1]))
|
||||
}
|
||||
args.push('--')
|
||||
app.setAsDefaultProtocolClient(import.meta.env.VITE_PROTOCOL, process.execPath, args)
|
||||
// app.removeAsDefaultProtocolClient(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_DESKTOP_PROTOCOL, process.execPath, args)
|
||||
|
||||
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 url = argv.find((arg, index) => index >= offset && arg.startsWith(prefix))
|
||||
if (url) {
|
||||
|
||||
@@ -235,7 +235,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')
|
||||
|
||||
3
src/renderer/src/global.d.ts
vendored
3
src/renderer/src/global.d.ts
vendored
@@ -6,7 +6,8 @@ type Platform = 'WEB' | 'DESKTOP' | 'ANDROID'
|
||||
|
||||
interface ImportMetaEnv {
|
||||
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_API_URL: string
|
||||
readonly VITE_API_TOKEN_URL: string
|
||||
|
||||
@@ -153,4 +153,4 @@ export const getViewPath = (
|
||||
}
|
||||
|
||||
export const getAndroidUrl = (username: string, toolId: string) =>
|
||||
`oxygen://opentool/${username}/${toolId}`
|
||||
`${import.meta.env.VITE_APP_PROTOCOL}://opentool/${username}/${toolId}`
|
||||
|
||||
Reference in New Issue
Block a user