Skip to content

best way to save what you love

web/device: add global constant for device info

wukkod817888838fb
diff --git a/web/src/components/save/buttons/DownloadButton.svelte b/web/src/components/save/buttons/DownloadButton.svelte
index 171a2f82..96dea5a5 100644
--- a/web/src/components/save/buttons/DownloadButton.svelte
+++ b/web/src/components/save/buttons/DownloadButton.svelte
@@ -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');
diff --git a/web/src/lib/device.ts b/web/src/lib/device.ts
new file mode 100644
index 00000000..e3a67feb
--- /dev/null
+++ b/web/src/lib/device.ts
@@ -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;