From fbe8ccfc2a2fbb0c71c0206706f318dda8c9907a Mon Sep 17 00:00:00 2001 From: wukko Date: Mon, 9 Sep 2024 12:53:22 +0600 Subject: [PATCH] web/download: show an explanation when user activation expires --- web/i18n/en/dialog.json | 1 + web/src/lib/download.ts | 15 +++++++++++---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/web/i18n/en/dialog.json b/web/i18n/en/dialog.json index 12b3652d..a2688f6d 100644 --- a/web/i18n/en/dialog.json +++ b/web/i18n/en/dialog.json @@ -9,6 +9,7 @@ "saving.title": "choose how to save", "saving.blocked": "cobalt tried opening the file in a new tab, but your browser blocked it. you can allow pop-ups for cobalt to prevent this from happening next time.", + "saving.timeout": "cobalt tried saving the file automatically, but your browser stopped it. you have to select a preferred method manually.", "safety.title": "important safety notice", diff --git a/web/src/lib/download.ts b/web/src/lib/download.ts index 9ed1042e..785d520d 100644 --- a/web/src/lib/download.ts +++ b/web/src/lib/download.ts @@ -65,18 +65,25 @@ export const downloadFile = ({ url, file }: { url?: string, file?: File }) => { const pref = get(settings).save.savingMethod; + if (pref === "ask") { + return openSavingDialog({ url, file }); + } + /* user actions (such as invoke share, open new tab) have expiration. in webkit, for example, that timeout is 5 seconds. - https://github.com/WebKit/WebKit/blob/b838f8bb3573bd5906bc5f02fcc8cb274b3c9b8a/Source/WebCore/page/LocalDOMWindow.cpp#L167 + https://github.com/WebKit/WebKit/blob/b838f8bb/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 (pref === "ask" || !navigator.userActivation.isActive) { - return openSavingDialog({ url, file }); + if (!navigator.userActivation.isActive) { + return openSavingDialog({ + url, + file, + body: get(t)("dialog.saving.timeout"), + }); } try {