From 1c619669a645a0dd37402e80dfd08a347fb71f6f Mon Sep 17 00:00:00 2001 From: "web@ppanel" Date: Mon, 9 Dec 2024 14:08:38 +0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix(config):=20SubLink?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../user/app/(main)/(user)/dashboard/page.tsx | 35 +++++++++---------- apps/user/config/use-global.tsx | 14 +++++--- apps/user/utils/common.ts | 25 +++++++++++++ 3 files changed, 50 insertions(+), 24 deletions(-) diff --git a/apps/user/app/(main)/(user)/dashboard/page.tsx b/apps/user/app/(main)/(user)/dashboard/page.tsx index 7a8fc73..3e81c59 100644 --- a/apps/user/app/(main)/(user)/dashboard/page.tsx +++ b/apps/user/app/(main)/(user)/dashboard/page.tsx @@ -32,6 +32,7 @@ import { useState } from 'react'; import useGlobalStore from '@/config/use-global'; import { getStat } from '@/services/common/common'; +import { getPlatform } from '@/utils/common'; import CopyToClipboard from 'react-copy-to-clipboard'; import Renewal from '../order/renewal'; import ResetTraffic from '../order/reset-traffic'; @@ -58,16 +59,7 @@ export default function Page() { return data.data as API.ApplicationResponse; }, }); - const [platform, setPlatform] = useState('windows'); - - const handleCopy = async (text: string) => { - try { - await navigator.clipboard.writeText(text); - toast.success(t('copySuccess')); - } catch { - toast.error(t('copyFailure')); - } - }; + const [platform, setPlatform] = useState(getPlatform()); const { data } = useQuery({ queryKey: ['getStat'], @@ -235,21 +227,26 @@ export default function Page() { - + + ))} diff --git a/apps/user/config/use-global.tsx b/apps/user/config/use-global.tsx index fcd6f9d..f246602 100644 --- a/apps/user/config/use-global.tsx +++ b/apps/user/config/use-global.tsx @@ -95,12 +95,12 @@ export const useGlobalStore = create((set, get) => ({ getAppSubLink: (type: string, url: string) => { const name = get().common.site.site_name || ''; switch (type) { - // case 'Clash': - // return `clash://install-config?url=${url}&name=${name}`; + case 'Clash': + return `clash://install-config?url=${url}&name=${name}`; case 'Hiddify': return `hiddify://import/${url}#${name}`; case 'Loon': - return `loon://import?sub=${encodeURI(url)}${name}`; + return `loon://import?sub=${encodeURI(url)}`; case 'NekoBox': return `sn://subscription?url=${url}&name=${name}`; case 'NekoRay': @@ -108,7 +108,11 @@ export const useGlobalStore = create((set, get) => ({ // case 'Netch': // return ``; case 'Quantumult X': - return `quantumult-x://add-resource?remote-resource=${url}`; + return `quantumult-x://add-resource?remote-resource=${encodeURIComponent( + JSON.stringify({ + server_remote: [`${url}, tag=${name}`], + }), + )}`; case 'Shadowrocket': return `shadowrocket://add/sub://${window.btoa(url)}?remark=${encodeURI(name)}`; case 'Singbox': @@ -124,7 +128,7 @@ export const useGlobalStore = create((set, get) => ({ case 'V2rayNg': return `v2rayng://install-sub?url=${encodeURI(url)}&name=${name}`; default: - return `clash://install-config?url=${encodeURI(url)}&name=${name}`; + return ''; } }, })); diff --git a/apps/user/utils/common.ts b/apps/user/utils/common.ts index 488a056..b628919 100644 --- a/apps/user/utils/common.ts +++ b/apps/user/utils/common.ts @@ -49,3 +49,28 @@ export function Logout() { location.href = `/`; } } + +export function getPlatform(): 'windows' | 'mac' | 'linux' | 'android' | 'ios' { + if (typeof navigator === 'undefined') { + console.log('This function can only run in a browser environment.'); + return 'windows'; + } + + const userAgent = navigator.userAgent; + + const platformPatterns: Record = { + windows: /Windows NT/, + mac: /Mac OS X/, + linux: /Linux/, + android: /Android/, + ios: /iPhone OS|iPad; CPU OS/, + }; + + for (const [platform, regex] of Object.entries(platformPatterns)) { + if (regex.test(userAgent)) { + return platform as 'windows' | 'mac' | 'linux' | 'android' | 'ios'; + } + } + + return 'windows'; +}