2
0
mirror of https://github.com/frappe/books.git synced 2025-01-03 07:12:21 +00:00

fix: printing bug cause event not fired

This commit is contained in:
18alantom 2023-06-28 11:12:49 +05:30
parent eeb2eab3e5
commit 18fc0e1a5d

View File

@ -1,4 +1,3 @@
import { emitMainProcessError } from 'backend/helpers';
import { App, BrowserWindow } from 'electron'; import { App, BrowserWindow } from 'electron';
import fs from 'fs/promises'; import fs from 'fs/promises';
import path from 'path'; import path from 'path';
@ -31,29 +30,11 @@ export async function saveHtmlAsPdf(
printSelectionOnly: false, printSelectionOnly: false,
}; };
/** const data = await printWindow.webContents.printToPDF(printOptions);
* After the printWindow content is ready, save as pdf and await fs.writeFile(savePath, data);
* then close the window and delete the temp html file. printWindow.close();
*/ await fs.unlink(htmlPath);
return await new Promise((resolve) => { return true;
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));
});
});
} }
async function getInitializedPrintWindow( async function getInitializedPrintWindow(