mirror of
https://github.com/wukko/cobalt.git
synced 2024-11-15 12:50:01 +00:00
web/device: add global constant for device info
This commit is contained in:
parent
10a9c955d9
commit
d817888838
2 changed files with 15 additions and 4 deletions
|
@ -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
13
web/src/lib/device.ts
Normal 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;
|
Loading…
Reference in a new issue