* refactor(frontend): フルスクリーン周りの調整 (cherry picked from commit 783032caec5853d78d5af3391e29cf364f2282e8) * refactor(frontend): deviceKindの循環参照を除去 (cherry picked from commit 1ca471f57e968a1a6e2259bde4a7c6da1fe0c54e) * fix --------- Co-authored-by: taiyme <53635909+taiyme@users.noreply.github.com>
25 lines
670 B
TypeScript
25 lines
670 B
TypeScript
/*
|
|
* 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;
|
|
}
|