From d817888838fb2c12dae6654873e8914f3c84b1ba Mon Sep 17 00:00:00 2001
From: wukko <me@wukko.me>
Date: Sat, 29 Jun 2024 20:24:14 +0600
Subject: [PATCH] web/device: add global constant for device info

---
 .../components/save/buttons/DownloadButton.svelte   |  6 ++----
 web/src/lib/device.ts                               | 13 +++++++++++++
 2 files changed, 15 insertions(+), 4 deletions(-)
 create mode 100644 web/src/lib/device.ts

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;