Files
goldenChart/frontend/src/utils/platform.ts
T
2026-06-14 19:20:48 +09:00

41 lines
1.3 KiB
TypeScript

/** 런타임 플랫폼 — web · desktop(Tauri) · mobile */
export type RuntimePlatform = 'web' | 'desktop' | 'mobile';
export function isDesktop(): boolean {
if (typeof window === 'undefined') return false;
if ('__TAURI__' in window || '__TAURI_INTERNALS__' in window) return true;
return document.documentElement.classList.contains('desktop-client');
}
export function isMobileCapacitor(): boolean {
if (typeof window === 'undefined') return false;
try {
const cap = (window as Window & { Capacitor?: { isNativePlatform?: () => boolean } }).Capacitor;
return cap?.isNativePlatform?.() === true;
} catch {
return false;
}
}
export function getRuntimePlatform(): RuntimePlatform {
if (isDesktop()) return 'desktop';
if (isMobileCapacitor()) return 'mobile';
return 'web';
}
export function isWeb(): boolean {
return getRuntimePlatform() === 'web';
}
/** Tauri 데스크톱 — Windows WebView2 */
export function isWindowsDesktop(): boolean {
if (!isDesktop()) return false;
return typeof navigator !== 'undefined' && /win/i.test(navigator.userAgent);
}
/** Tauri 데스크톱 — macOS */
export function isMacDesktop(): boolean {
if (!isDesktop()) return false;
return typeof navigator !== 'undefined' && /mac/i.test(navigator.userAgent);
}