Skip to content

Commit

Permalink
fix: printing bug cause event not fired
Browse files Browse the repository at this point in the history
  • Loading branch information
18alantom committed Jun 28, 2023
1 parent eeb2eab commit 18fc0e1
Showing 1 changed file with 5 additions and 24 deletions.
29 changes: 5 additions & 24 deletions main/saveHtmlAsPdf.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { emitMainProcessError } from 'backend/helpers';
import { App, BrowserWindow } from 'electron';
import fs from 'fs/promises';
import path from 'path';
Expand Down Expand Up @@ -31,29 +30,11 @@ export async function saveHtmlAsPdf(
printSelectionOnly: false,
};

/**
* After the printWindow content is ready, save as pdf and
* then close the window and delete the temp html file.
*/
return await new Promise((resolve) => {
printWindow.webContents.once('did-finish-load', () => {
printWindow.webContents
.printToPDF(printOptions)
.then((data) => {
fs.writeFile(savePath, data)
.then(() => {
printWindow.close();
fs.unlink(htmlPath)
.then(() => {
resolve(true);
})
.catch((err) => emitMainProcessError(err));
})
.catch((err) => emitMainProcessError(err));
})
.catch((err) => emitMainProcessError(err));
});
});
const data = await printWindow.webContents.printToPDF(printOptions);
await fs.writeFile(savePath, data);
printWindow.close();
await fs.unlink(htmlPath);
return true;
}

async function getInitializedPrintWindow(
Expand Down

0 comments on commit 18fc0e1

Please sign in to comment.