mirror of
https://github.com/imputnet/cobalt.git
synced 2024-12-29 11:06:10 +00:00
web/DownloadButton: open share sheet on ios
This commit is contained in:
parent
98b0a2f10a
commit
d008bffc08
|
@ -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();
|
||||||
|
|
Loading…
Reference in a new issue