web/device: add global constant for device info

This commit is contained in:
wukko 2024-06-29 20:24:14 +06:00
parent 10a9c955d9
commit d817888838
No known key found for this signature in database
GPG key ID: 3E30B3F26C7B4AA2
2 changed files with 15 additions and 4 deletions

View file

@ -2,15 +2,13 @@
import '@fontsource-variable/noto-sans-mono';
import API from "$lib/api";
import device from '$lib/device';
export let url: string;
$: buttonText = '>>';
$: isDisabled = false;
const ua = navigator.userAgent.toLowerCase();
const isIOS = ua.includes("iphone os") || (ua.includes("mac os") && navigator.maxTouchPoints > 0);
const changeDownloadButton = (state: string) => {
isDisabled = true;
switch(state) {
@ -37,7 +35,7 @@
}
const downloadFile = (url: string) => {
if (isIOS) {
if (device.isIOS) {
return navigator?.share({ url }).catch(() => {});
} else {
return window.open(url, '_blank');

13
web/src/lib/device.ts Normal file
View file

@ -0,0 +1,13 @@
const ua = navigator.userAgent.toLowerCase();
const isIOS = ua.includes("iphone os") || (ua.includes("mac os") && navigator.maxTouchPoints > 0);
const isAndroid = ua.includes("android") || ua.includes("diordna");
const isMobile = isIOS || isAndroid;
const deviceInfo = {
isIOS,
isAndroid,
isMobile,
}
export default deviceInfo;