From 96e73fc6638e0fbf94341d21709be10210e08e6a Mon Sep 17 00:00:00 2001 From: Vladimir Voronkov Date: Fri, 8 Mar 2024 10:00:03 +0200 Subject: [PATCH 1/4] Turn off ipc log transport between render and main process --- src/error-manager/index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/error-manager/index.js b/src/error-manager/index.js index f8479831..0ab95ba3 100644 --- a/src/error-manager/index.js +++ b/src/error-manager/index.js @@ -169,6 +169,7 @@ const manageNewGithubIssue = async (params) => { } const initLogger = () => { + log.transports.ipc.level = false log.transports.console.level = isDevEnv ? 'debug' : 'warn' From 8cbfc2eedacf6745890ddd8110ce9a93884399d4 Mon Sep 17 00:00:00 2001 From: Vladimir Voronkov Date: Fri, 8 Mar 2024 10:08:40 +0200 Subject: [PATCH 2/4] Suppress err modal window if pdf gen failed --- src/error-manager/index.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/error-manager/index.js b/src/error-manager/index.js index 0ab95ba3..5a82a4bf 100644 --- a/src/error-manager/index.js +++ b/src/error-manager/index.js @@ -216,7 +216,9 @@ const initLogger = () => { if ( /Cannot download differentially/gi.test(error) || /ERR_CONNECTION_REFUSED/gi.test(error) || - /objects\.githubusercontent\.com/gi.test(error) + /objects\.githubusercontent\.com/gi.test(error) || + /Error: ERR_FAILED \(-2\) loading 'file:.*\.html'/gi.test(error) || + /Failed to generate PDF/gi.test(error) ) { return message } From b4ed6fe4737e604ae2cc91d9c1385b314c776206 Mon Sep 17 00:00:00 2001 From: Vladimir Voronkov Date: Fri, 8 Mar 2024 10:10:55 +0200 Subject: [PATCH 3/4] Improve pdf gen performance for big html templates --- src/print-to-pdf/index.js | 40 +++++++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/src/print-to-pdf/index.js b/src/print-to-pdf/index.js index 150b421a..460738e6 100644 --- a/src/print-to-pdf/index.js +++ b/src/print-to-pdf/index.js @@ -16,6 +16,8 @@ const PROCESS_STATES = require( module.exports = () => { ipcs.serverIpc.on('message', async (mess) => { + let templateFilePathForRm = null + try { if (mess?.state !== PROCESS_MESSAGES.REQUEST_PDF_CREATION) { return @@ -33,14 +35,9 @@ module.exports = () => { templateFilePath && typeof templateFilePath === 'string' ) - - const html = isTemplateFilePathUsed - ? await fs.readFile(templateFilePath, { encoding: 'utf8' }) - : template - - if (isTemplateFilePathUsed) { - await fs.rm(templateFilePath, { force: true, maxRetries: 3 }) - } + templateFilePathForRm = isTemplateFilePathUsed + ? templateFilePath + : null const win = new BrowserWindow({ show: false, @@ -49,14 +46,15 @@ module.exports = () => { nodeIntegration: true } }) - win.loadURL(`data:text/html;charset=utf-8,${encodeURIComponent(html)}`) + const closedEventPromise = new Promise((resolve) => ( + win.once('closed', resolve) + )) + const loadPromise = isTemplateFilePathUsed + ? win.loadFile(templateFilePath) + : win.loadURL(`data:text/html;charset=utf-8,${encodeURIComponent(template)}`) + + await loadPromise - await new Promise((resolve, reject) => { - win.webContents.on('did-finish-load', resolve) - win.webContents.on('did-fail-load', (e, code, err) => { - reject(err) - }) - }) const buffer = await win.webContents.printToPDF({ landscape: format !== 'portrait', pageSize: orientation, @@ -79,7 +77,12 @@ module.exports = () => { ` }) + win.close() + await closedEventPromise + if (isTemplateFilePathUsed) { + await fs.rm(templateFilePath, { force: true, maxRetries: 3 }) + const { dir, name } = path.parse(templateFilePath) const pdfFilePath = path.format({ dir, name, ext: '.pdf' }) @@ -98,9 +101,14 @@ module.exports = () => { data: { buffer, uid } }) } catch (err) { + if (templateFilePathForRm) { + fs.rm(templateFilePathForRm, { force: true, maxRetries: 3 }) + .then(() => {}, (err) => { console.debug(err) }) + } + ipcs.serverIpc.send({ state: PROCESS_STATES.RESPONSE_PDF_CREATION, - data: { err, uid: mess?.data?.uid ?? null } + data: { err: err.stack ?? err, uid: mess?.data?.uid ?? null } }) console.error(err) From 0c182673aebceddaa247c8c4afd16c22e7a8c0e4 Mon Sep 17 00:00:00 2001 From: Vladimir Voronkov Date: Fri, 8 Mar 2024 10:27:32 +0200 Subject: [PATCH 4/4] Bump up electron minor version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index c048db90..57a3adfa 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "app-builder-bin": "4.2.0", "cross-env": "7.0.3", "dotenv": "16.3.1", - "electron": "27.2.0", + "electron": "27.3.5", "electron-builder": "24.10.0", "mocha": "10.2.0", "standard": "17.1.0",