Skip to content

Commit

Permalink
fix for dash-preview to handle pages with iframes
Browse files Browse the repository at this point in the history
  • Loading branch information
antoinerg committed May 20, 2020
1 parent 612fb80 commit 1472579
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .circleci/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ set +e
set +o pipefail

EXIT_STATE=0
MAX_AUTO_RETRY=5
MAX_AUTO_RETRY=2

# inspired by https://unix.stackexchange.com/a/82602
retry () {
Expand Down
4 changes: 3 additions & 1 deletion src/component/plotly-dash-preview/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const micronsInInch = 25400
module.exports = {
minInterval: 500,
maxRenderingTries: 100,
maxPrintPDFTime: 50,
pixelsInMicron: pixelsInInch / micronsInInch,
sizeMapping: {
'A3': { 'width': 11.7 * pixelsInInch, 'height': 16.5 * pixelsInInch },
Expand All @@ -15,6 +16,7 @@ module.exports = {
},
statusMsg: {
525: 'dash preview generation failed',
526: 'dash preview generation timed out'
526: 'dash preview generation timed out',
527: 'dash preview pdf generation timed out'
}
}
8 changes: 8 additions & 0 deletions src/component/plotly-dash-preview/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,18 @@ function render (info, opts, sendToMain) {
loaded().then(() => {
// Move mouse outside the page to prevent hovering on figures
contents.sendInputEvent({ type: 'mouseMove', x: -1, y: -1 })

// Close window if timeout is exceeded
// This is necessary because `printToPDF` sometimes never end
// https://github.com/electron/electron/issues/20634
var timer = setTimeout(() => done(527), (info.timeOut || cst.maxPrintPDFTime) * 1000)

contents.printToPDF(info.pdfOptions, (err, pdfData) => {
if (err) {
clearTimeout(timer)
done(525)
} else {
clearTimeout(timer)
result.imgData = pdfData
done()
}
Expand Down
4 changes: 2 additions & 2 deletions test/unit/plotly-dash-preview_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,8 @@ tap.test('render:', t => {
}, {}, (errorCode, result) => {
t.ok(win.webContents.printToPDF.calledOnce)
t.ok(win.close.calledOnce)
t.equal(errorCode, 525, 'code')
t.equal(result.msg, 'dash preview generation failed', 'error msg')
t.equal(errorCode, 527, 'code')
t.equal(result.msg, 'dash preview pdf generation timed out', 'error msg')
t.end()
})
})
Expand Down

0 comments on commit 1472579

Please sign in to comment.