Sharkey/packages/frontend/src/scripts/device-kind.ts

13 lines
493 B
TypeScript
Raw Normal View History

import { defaultStore } from '@/store';
await defaultStore.ready;
const ua = navigator.userAgent.toLowerCase();
const isTablet = /ipad/.test(ua) || (/mobile|iphone|android/.test(ua) && window.innerWidth > 700);
const isSmartphone = !isTablet && /mobile|iphone|android/.test(ua);
2023-01-27 04:16:22 +02:00
export const deviceKind: 'smartphone' | 'tablet' | 'desktop' = defaultStore.state.overridedDeviceKind ? defaultStore.state.overridedDeviceKind
: isSmartphone ? 'smartphone'
: isTablet ? 'tablet'
: 'desktop';