Skip to content

Commit fbab15a

Browse files
committed
fix PDF viewer downloads
#2369
1 parent 2a2c559 commit fbab15a

File tree

3 files changed

+11
-16
lines changed

3 files changed

+11
-16
lines changed

js/preload/default.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,8 @@ window.addEventListener('message', function (e) {
5757
if (e.data?.message === 'showUserscriptDirectory') {
5858
ipc.send('showUserscriptDirectory')
5959
}
60+
61+
if (e.data?.message === 'downloadFile') {
62+
ipc.send('downloadFile', e.data.url)
63+
}
6064
})

js/webviews.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,12 @@ webviews.bindIPC('scroll-position-change', function (tabId, args) {
481481
})
482482
})
483483

484+
webviews.bindIPC('downloadFile', function (tabId, args) {
485+
if (tabs.get(tabId).url.startsWith('min://')) {
486+
webviews.callAsync(tabId, 'downloadURL', [args[0]])
487+
}
488+
})
489+
484490
ipc.on('view-event', function (e, args) {
485491
webviews.emitEvent(args.event, args.tabId, args.args)
486492
})

pages/pdfViewer/viewer.js

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -509,22 +509,7 @@ function throttle (fn, threshhold, scope) {
509509
}
510510

511511
function downloadPDF () {
512-
function startDownload (title) {
513-
var a = document.createElement('a')
514-
a.download = title || ''
515-
a.href = url
516-
a.click()
517-
}
518-
if (pdf) {
519-
pdf.getMetadata().then(function (data) {
520-
startDownload(data.info.Title)
521-
})
522-
} else {
523-
// there is no PDF data available
524-
// this can happen if the download is happening because the file isn't a PDF and we can't show a preview
525-
// or if the file hasn't loaded yet
526-
startDownload('')
527-
}
512+
window.postMessage({ message: 'downloadFile', url })
528513
}
529514

530515
/* printing */

0 commit comments

Comments
 (0)