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

@@ -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

View File

@@ -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) {