web/DownloadButton: open share sheet on ios

This commit is contained in:
wukko 2024-06-25 22:25:29 +06:00
parent 98b0a2f10a
commit d008bffc08
No known key found for this signature in database
GPG key ID: 3E30B3F26C7B4AA2

View file

@ -8,6 +8,9 @@
$: buttonText = '>>'; $: buttonText = '>>';
$: isDisabled = false; $: 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) => { export const changeDownloadButton = (state: string) => {
isDisabled = true; isDisabled = true;
switch(state) { switch(state) {
@ -33,6 +36,14 @@
}, 2500) }, 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 >_< // alerts are temporary, we don't have an error popup yet >_<
const download = async (link: string) => { const download = async (link: string) => {
changeDownloadButton("think"); changeDownloadButton("think");
@ -57,7 +68,7 @@
changeDownloadButton("done"); changeDownloadButton("done");
restoreDownloadButton(); restoreDownloadButton();
return window.open(response.url, '_blank'); return downloadFile(response.url);
} }
if (response.status === "stream") { if (response.status === "stream") {
@ -69,7 +80,7 @@
changeDownloadButton("done"); changeDownloadButton("done");
restoreDownloadButton(); restoreDownloadButton();
return window.open(response.url, '_blank'); return downloadFile(response.url);
} else { } else {
changeDownloadButton("error"); changeDownloadButton("error");
restoreDownloadButton(); restoreDownloadButton();