From d008bffc082d9e8eea55d969c3355d0ff0896ad3 Mon Sep 17 00:00:00 2001 From: wukko Date: Tue, 25 Jun 2024 22:25:29 +0600 Subject: [PATCH] web/DownloadButton: open share sheet on ios --- .../components/save/buttons/DownloadButton.svelte | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/web/src/components/save/buttons/DownloadButton.svelte b/web/src/components/save/buttons/DownloadButton.svelte index 655ea4b1..aaa9768f 100644 --- a/web/src/components/save/buttons/DownloadButton.svelte +++ b/web/src/components/save/buttons/DownloadButton.svelte @@ -8,6 +8,9 @@ $: buttonText = '>>'; $: isDisabled = false; + const ua = navigator.userAgent.toLowerCase(); + const isIOS = ua.includes("iphone os") || (ua.includes("mac os") && navigator.maxTouchPoints > 0); + export const changeDownloadButton = (state: string) => { isDisabled = true; switch(state) { @@ -33,6 +36,14 @@ }, 2500) } + const downloadFile = (url: string) => { + if (isIOS) { + return navigator?.share({ url }).catch(() => {}); + } else { + return window.open(url, '_blank'); + } + } + // alerts are temporary, we don't have an error popup yet >_< const download = async (link: string) => { changeDownloadButton("think"); @@ -57,7 +68,7 @@ changeDownloadButton("done"); restoreDownloadButton(); - return window.open(response.url, '_blank'); + return downloadFile(response.url); } if (response.status === "stream") { @@ -69,7 +80,7 @@ changeDownloadButton("done"); restoreDownloadButton(); - return window.open(response.url, '_blank'); + return downloadFile(response.url); } else { changeDownloadButton("error"); restoreDownloadButton();