Skip to content
This repository has been archived by the owner on Oct 23, 2023. It is now read-only.

Commit

Permalink
fix: trigger a second png export if the first does not return a valid…
Browse files Browse the repository at this point in the history
… value (#497)
  • Loading branch information
lkuechler authored and marionebl committed May 31, 2018
1 parent d342b3c commit 000565e
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/export/png-exporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ export class PngExporter implements Types.Exporter {
webview.style.height = `${payload.height}px`;

config = payload;

webview.loadURL(
`data:text/html;charset=utf-8,${encodeURIComponent(payload.document)}`,
{
Expand All @@ -63,11 +62,14 @@ export class PngExporter implements Types.Exporter {
};

// (3) Wait for webview to be ready and capture the page
const createPng = () => {
const createPng = (isSecondTry?: boolean) => {
if (!config) {
return;
}

// because of a bug in electron the second capture will only be triggered if we set the focus on this webview
webview.focus();

webview.capturePage(
{
x: 0,
Expand All @@ -79,6 +81,13 @@ export class PngExporter implements Types.Exporter {
height: Math.round(config.height * scaleFactor)
},
capture => {
const captureSize = capture.getSize();
if (captureSize.width === 0 && captureSize.height === 0 && !isSecondTry) {
// If the captured image is of size 0 try the capture again
createPng(true);
return;
}

// resize the capture to the original screen size
const resizedCapture = capture.resize({
width: capture.getSize().width / scaleFactor
Expand All @@ -98,6 +107,7 @@ export class PngExporter implements Types.Exporter {
if (webview.src === initial) {
return;
}

createPng();
});

Expand Down

0 comments on commit 000565e

Please sign in to comment.