mirror of
https://github.com/wukko/cobalt.git
synced 2024-11-15 12:50:01 +00:00
web/DownloadButton: open share sheet on ios
This commit is contained in:
parent
98b0a2f10a
commit
d008bffc08
1 changed files with 13 additions and 2 deletions
|
@ -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();
|
||||
|
|
Loading…
Reference in a new issue