|
@@ -2,17 +2,16 @@ import { useMemo } from 'react';
|
|
|
|
|
|
|
|
import { useSearchParams } from 'react-router-dom';
|
|
import { useSearchParams } from 'react-router-dom';
|
|
|
|
|
|
|
|
-const env = typeof import.meta !== 'undefined' ? (import.meta as any).env : undefined;
|
|
|
|
|
|
|
+const env: ImportMetaEnv =
|
|
|
|
|
+ typeof import.meta !== 'undefined' ? (import.meta as any).env : undefined;
|
|
|
|
|
|
|
|
const GOOGLE_STORE_URL = env?.VITE_APP_GOOGLE_STORE_URL ?? '';
|
|
const GOOGLE_STORE_URL = env?.VITE_APP_GOOGLE_STORE_URL ?? '';
|
|
|
-console.log('🚀 ~ useAppUrls.ts:8 ~ GOOGLE_STORE_URL:', GOOGLE_STORE_URL);
|
|
|
|
|
const APPLE_STORE_URL = env?.VITE_APP_APPLE_STORE_URL ?? '';
|
|
const APPLE_STORE_URL = env?.VITE_APP_APPLE_STORE_URL ?? '';
|
|
|
-console.log('🚀 ~ useAppUrls.ts:10 ~ APPLE_STORE_URL:', APPLE_STORE_URL);
|
|
|
|
|
const APK_URL = env?.VITE_APP_APK_URL ?? '';
|
|
const APK_URL = env?.VITE_APP_APK_URL ?? '';
|
|
|
-console.log('🚀 ~ useAppUrls.ts:12 ~ APK_URL:', APK_URL);
|
|
|
|
|
|
|
+const MACOS_URL = env?.VITE_APP_MACOS_URL ?? '';
|
|
|
|
|
+const WINDOWS_URL = env?.VITE_APP_WINDOWS_URL ?? '';
|
|
|
|
|
|
|
|
const DEEPLINK_URL = env?.VITE_APP_DEEPLINK_URL ?? '';
|
|
const DEEPLINK_URL = env?.VITE_APP_DEEPLINK_URL ?? '';
|
|
|
-console.log('🚀 ~ useAppUrls.ts:15 ~ DEEPLINK_URL:', DEEPLINK_URL);
|
|
|
|
|
|
|
|
|
|
const REFERRER_PARAM = 'referrer';
|
|
const REFERRER_PARAM = 'referrer';
|
|
|
|
|
|
|
@@ -20,17 +19,24 @@ function getDownloadUrlByPlatform(
|
|
|
google: string,
|
|
google: string,
|
|
|
apple: string,
|
|
apple: string,
|
|
|
apk: string,
|
|
apk: string,
|
|
|
|
|
+ macos: string,
|
|
|
|
|
+ windows: string,
|
|
|
fallback: string
|
|
fallback: string
|
|
|
): string {
|
|
): string {
|
|
|
if (typeof navigator === 'undefined' || !navigator.userAgent)
|
|
if (typeof navigator === 'undefined' || !navigator.userAgent)
|
|
|
- return fallback || apk || google || apple;
|
|
|
|
|
|
|
+ return fallback || windows || apk || google || apple || macos;
|
|
|
const ua = navigator.userAgent;
|
|
const ua = navigator.userAgent;
|
|
|
- const isIos = /iPad|iPhone|iPod/.test(ua);
|
|
|
|
|
|
|
+ const isIos =
|
|
|
|
|
+ /iPad|iPhone|iPod/.test(ua) ||
|
|
|
|
|
+ (navigator.platform === 'MacIntel' && navigator.maxTouchPoints > 1);
|
|
|
const isAndroid = /Android/.test(ua);
|
|
const isAndroid = /Android/.test(ua);
|
|
|
|
|
+ const isMac = !isIos && /Macintosh|Mac OS X/.test(ua);
|
|
|
|
|
+ const isWindows = /Windows/.test(ua);
|
|
|
if (isIos && apple) return apple;
|
|
if (isIos && apple) return apple;
|
|
|
- if (isAndroid && google) return google;
|
|
|
|
|
- if (isAndroid && apk) return apk;
|
|
|
|
|
- return fallback || apk || google || apple;
|
|
|
|
|
|
|
+ if (isAndroid) return google || apk;
|
|
|
|
|
+ if (isMac && macos) return macos;
|
|
|
|
|
+ if (isWindows && windows) return windows;
|
|
|
|
|
+ return fallback || windows || apk || google || apple || macos;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
export interface AppUrls {
|
|
export interface AppUrls {
|
|
@@ -42,7 +48,11 @@ export interface AppUrls {
|
|
|
appleStoreUrl: string;
|
|
appleStoreUrl: string;
|
|
|
/** APK 直链地址,未配置时为空 */
|
|
/** APK 直链地址,未配置时为空 */
|
|
|
apkUrl: string;
|
|
apkUrl: string;
|
|
|
- /** 根据当前用户平台自动选择的下载地址:iOS→Apple 商店,Android→Google 商店或 APK,其他→fallback/APK/Google/Apple */
|
|
|
|
|
|
|
+ /** macOS 客户端下载地址,未配置时为空 */
|
|
|
|
|
+ macosUrl: string;
|
|
|
|
|
+ /** Windows 客户端下载地址,未配置时为空 */
|
|
|
|
|
+ windowsUrl: string;
|
|
|
|
|
+ /** 根据当前用户平台自动选择的下载地址 */
|
|
|
downloadUrlByPlatform: string;
|
|
downloadUrlByPlatform: string;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -90,15 +100,41 @@ export function useAppUrls(): AppUrls {
|
|
|
}
|
|
}
|
|
|
})();
|
|
})();
|
|
|
|
|
|
|
|
|
|
+ const macosUrl = (() => {
|
|
|
|
|
+ if (!MACOS_URL) return '';
|
|
|
|
|
+ if (!referrerEnc) return MACOS_URL;
|
|
|
|
|
+ try {
|
|
|
|
|
+ const sep = MACOS_URL.includes('?') ? '&' : '?';
|
|
|
|
|
+ return `${MACOS_URL}${sep}${REFERRER_PARAM}=${referrerEnc}`;
|
|
|
|
|
+ } catch {
|
|
|
|
|
+ return MACOS_URL;
|
|
|
|
|
+ }
|
|
|
|
|
+ })();
|
|
|
|
|
+
|
|
|
|
|
+ const windowsUrl = (() => {
|
|
|
|
|
+ if (!WINDOWS_URL) return '';
|
|
|
|
|
+ if (!referrerEnc) return WINDOWS_URL;
|
|
|
|
|
+ try {
|
|
|
|
|
+ const sep = WINDOWS_URL.includes('?') ? '&' : '?';
|
|
|
|
|
+ return `${WINDOWS_URL}${sep}${REFERRER_PARAM}=${referrerEnc}`;
|
|
|
|
|
+ } catch {
|
|
|
|
|
+ return WINDOWS_URL;
|
|
|
|
|
+ }
|
|
|
|
|
+ })();
|
|
|
|
|
+
|
|
|
return {
|
|
return {
|
|
|
deeplinkUrl,
|
|
deeplinkUrl,
|
|
|
googleStoreUrl,
|
|
googleStoreUrl,
|
|
|
appleStoreUrl: APPLE_STORE_URL,
|
|
appleStoreUrl: APPLE_STORE_URL,
|
|
|
apkUrl,
|
|
apkUrl,
|
|
|
|
|
+ macosUrl,
|
|
|
|
|
+ windowsUrl,
|
|
|
downloadUrlByPlatform: getDownloadUrlByPlatform(
|
|
downloadUrlByPlatform: getDownloadUrlByPlatform(
|
|
|
googleStoreUrl,
|
|
googleStoreUrl,
|
|
|
APPLE_STORE_URL,
|
|
APPLE_STORE_URL,
|
|
|
apkUrl,
|
|
apkUrl,
|
|
|
|
|
+ macosUrl,
|
|
|
|
|
+ windowsUrl,
|
|
|
''
|
|
''
|
|
|
),
|
|
),
|
|
|
};
|
|
};
|