mirror of
https://github.com/imputnet/cobalt.git
synced 2025-01-16 03:45:14 +00:00
web/download: open saving dialog if user action expired
This commit is contained in:
parent
4210b17d89
commit
82091db154
|
@ -5,6 +5,13 @@ import settings from "$lib/state/settings";
|
||||||
|
|
||||||
import { createDialog } from "$lib/dialogs";
|
import { createDialog } from "$lib/dialogs";
|
||||||
|
|
||||||
|
export const openSavingDialog = (url: string) =>
|
||||||
|
createDialog({
|
||||||
|
type: "saving",
|
||||||
|
id: "saving",
|
||||||
|
url
|
||||||
|
})
|
||||||
|
|
||||||
export const openURL = (url: string) => {
|
export const openURL = (url: string) => {
|
||||||
return window.open(url, "_blank");
|
return window.open(url, "_blank");
|
||||||
}
|
}
|
||||||
|
@ -27,12 +34,18 @@ export const copyURL = async (url: string) => {
|
||||||
|
|
||||||
export const downloadFile = (url: string) => {
|
export const downloadFile = (url: string) => {
|
||||||
const savingPreference = get(settings).save.downloadPopup;
|
const savingPreference = get(settings).save.downloadPopup;
|
||||||
if (savingPreference) {
|
|
||||||
createDialog({
|
/*
|
||||||
type: "saving",
|
user actions (such as invoke share, open new tab) have expiration.
|
||||||
id: "saving",
|
in webkit, for example, that timeout is 5 seconds.
|
||||||
url
|
https://github.com/WebKit/WebKit/blob/b838f8bb3573bd5906bc5f02fcc8cb274b3c9b8a/Source/WebCore/page/LocalDOMWindow.cpp#L167
|
||||||
})
|
|
||||||
|
navigator.userActivation.isActive makes sure that we're still able to
|
||||||
|
invoke an action without the user agent interrupting it.
|
||||||
|
if not, we show a saving dialog for user to re-invoke that action.
|
||||||
|
*/
|
||||||
|
if (savingPreference || !navigator.userActivation.isActive) {
|
||||||
|
openSavingDialog(url);
|
||||||
} else if (device.is.iOS && app.is.installed) {
|
} else if (device.is.iOS && app.is.installed) {
|
||||||
return shareURL(url);
|
return shareURL(url);
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in a new issue