diff --git a/src/components/downloadOptionsDialog/downloadOptionsDialog.js b/src/components/downloadOptionsDialog/downloadOptionsDialog.js index 4956eb1838..b13765d2fa 100644 --- a/src/components/downloadOptionsDialog/downloadOptionsDialog.js +++ b/src/components/downloadOptionsDialog/downloadOptionsDialog.js @@ -483,8 +483,8 @@ function onSubmit(e) { filename: filename }]); - toast(globalize.translate('DownloadStarted')); - dialogHelper.close(dlg); + toast('Download started'); + dialogHelper.close(e.target.closest('.dialog')); }); return false; diff --git a/src/scripts/fileDownloader.js b/src/scripts/fileDownloader.js index 24f1631017..dde5c18ae6 100644 --- a/src/scripts/fileDownloader.js +++ b/src/scripts/fileDownloader.js @@ -3,8 +3,7 @@ import shell from './shell'; export function download(items) { if (!shell.downloadFiles(items)) { - multiDownload(items.map(function (item) { - return item.url; - })); + // Pass full item objects (with url and filename) to multiDownload + multiDownload(items); } } diff --git a/src/scripts/multiDownload.js b/src/scripts/multiDownload.js index c9f40f56a4..20d5bad7a6 100644 --- a/src/scripts/multiDownload.js +++ b/src/scripts/multiDownload.js @@ -27,25 +27,31 @@ function fallback(urls) { })(); } -function download(url) { +function download(url, filename) { const a = document.createElement('a'); - a.download = ''; + a.download = filename || ''; a.href = url; a.click(); } -export default function (urls) { - if (!urls) { - throw new Error('`urls` required'); +export default function (items) { + if (!items) { + throw new Error('`items` required'); } + // Support both old format (array of URLs) and new format (array of objects with url+filename) + const isOldFormat = typeof items[0] === 'string'; + if (typeof document.createElement('a').download === 'undefined' || browser.iOS) { + const urls = isOldFormat ? items : items.map(item => item.url || item); return fallback(urls); } let delay = 0; - urls.forEach(function (url) { - setTimeout(download.bind(null, url), 100 * ++delay); + items.forEach(function (item) { + const url = isOldFormat ? item : (item.url || item); + const filename = isOldFormat ? '' : (item.filename || ''); + setTimeout(download.bind(null, url, filename), 100 * ++delay); }); }