mirror of
https://github.com/misskey-dev/misskey.git
synced 2026-05-23 01:44:10 +02:00
refactor(frontend): scripts -> utility
This commit is contained in:
24
packages/frontend/src/utility/device-kind.ts
Normal file
24
packages/frontend/src/utility/device-kind.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: syuilo and misskey-project
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
export type DeviceKind = 'smartphone' | 'tablet' | 'desktop';
|
||||
|
||||
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);
|
||||
|
||||
export const DEFAULT_DEVICE_KIND: DeviceKind = (
|
||||
isSmartphone
|
||||
? 'smartphone'
|
||||
: isTablet
|
||||
? 'tablet'
|
||||
: 'desktop'
|
||||
);
|
||||
|
||||
export let deviceKind: DeviceKind = DEFAULT_DEVICE_KIND;
|
||||
|
||||
export function updateDeviceKind(kind: DeviceKind | null) {
|
||||
deviceKind = kind ?? DEFAULT_DEVICE_KIND;
|
||||
}
|
||||
Reference in New Issue
Block a user