normalize deeplink

This commit is contained in:
pompurin404 2024-08-18 19:29:56 +08:00
parent 2dead0f521
commit 87daeea90f
No known key found for this signature in database

View File

@ -80,27 +80,28 @@ app.whenReady().then(async () => {
async function handleDeepLink(url: string): Promise<void> { async function handleDeepLink(url: string): Promise<void> {
if (!url.startsWith('clash://') && !url.startsWith('mihomo://')) return if (!url.startsWith('clash://') && !url.startsWith('mihomo://')) return
const urlObj = new URL(url)
switch (urlObj.host) {
case 'install-config': {
try { try {
if (url.startsWith('clash://install-config')) { const profileUrl = urlObj.searchParams.get('url')
url = url const profileName = urlObj.searchParams.get('name')
.replace('clash://install-config/?url=', '') if (!profileUrl) {
.replace('clash://install-config?url=', '') throw new Error('缺少参数 url')
} }
if (url.startsWith('mihomo://install-config')) {
url = url
.replace('mihomo://install-config/?url=', '')
.replace('mihomo://install-config?url=', '')
}
url = decodeURIComponent(url.split('&')[0])
await addProfileItem({ await addProfileItem({
type: 'remote', type: 'remote',
name: 'Remote File', name: profileName ?? undefined,
url: decodeURIComponent(url) url: profileUrl
}) })
new Notification({ title: '订阅导入成功' }).show() new Notification({ title: '订阅导入成功' }).show()
break
} catch (e) { } catch (e) {
dialog.showErrorBox('订阅导入失败', `${url}\n${e}`) dialog.showErrorBox('订阅导入失败', `${url}\n${e}`)
} }
}
}
} }
export function createWindow(show = false): void { export function createWindow(show = false): void {