From 3be72eee5c10a43f6fb9924ab1e9a33bb0f5216e Mon Sep 17 00:00:00 2001 From: Janosch Maier Date: Tue, 11 Jan 2022 22:15:43 +0100 Subject: [PATCH] Fix print to pdf functionality --- app/internal_packages/print/lib/print-window.ts | 1 + .../print/static/print-preload.js | 14 ++++---------- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/app/internal_packages/print/lib/print-window.ts b/app/internal_packages/print/lib/print-window.ts index 2182090b6..7ba3d70bb 100644 --- a/app/internal_packages/print/lib/print-window.ts +++ b/app/internal_packages/print/lib/print-window.ts @@ -80,6 +80,7 @@ export default class PrintWindow { contextIsolation: false, }, }); + require("@electron/remote").require("@electron/remote/main").enable(this.browserWin.webContents); this.browserWin.removeMenu(); fs.writeFileSync(tmpMessagesPath, `window.printMessages = ${printMessages}`); fs.writeFileSync(this.tmpFile, content); diff --git a/app/internal_packages/print/static/print-preload.js b/app/internal_packages/print/static/print-preload.js index da9f691c3..8cf6b959b 100644 --- a/app/internal_packages/print/static/print-preload.js +++ b/app/internal_packages/print/static/print-preload.js @@ -7,7 +7,7 @@ win.addListener('page-title-updated', event => { }); global.printToPDF = async () => { - const { filePath } = awaitrequire('@electron/remote').dialog.showSaveDialog({ + const { filePath } = await require('@electron/remote').dialog.showSaveDialog({ defaultPath: `${win.getTitle()}.pdf`, }); @@ -20,14 +20,8 @@ global.printToPDF = async () => { pageSize: 'Letter', printBackground: true, landscape: false, - }, - (error, data) => { - if (error) { - require('@electron/remote').dialog.showErrorBox('An Error Occurred', `${error}`); - return; - } - - fs.writeFileSync(filename, data); + }).then(data => { + fs.writeFileSync(filePath, data); } - ); + ); };