feat(pdf): error handling

This commit is contained in:
Elian Doran 2025-01-31 23:29:53 +02:00
parent d4965e8d41
commit 84532d42ec
No known key found for this signature in database
2 changed files with 17 additions and 5 deletions

View File

@ -71,11 +71,20 @@ ipcMain.on("export-as-pdf", async (e, opts: ExportAsPdfOpts) => {
return;
}
// TODO: Report if there is an error in generating the PDF.
const buffer = await browserWindow.webContents.printToPDF({});
let buffer: Buffer;
try {
buffer = await browserWindow.webContents.printToPDF({});
} catch (e) {
dialog.showErrorBox(t("pdf.unable-to-export-title"), t("pdf.unable-to-export-message"));
return;
}
// TODO: Report if there was an error in saving the PDF.
try {
fs.writeFileSync(filePath, buffer);
} catch (e) {
dialog.showErrorBox(t("pdf.unable-to-export-title"), t("pdf.unable-to-save-message"));
return;
}
shell.openPath(filePath);
});

View File

@ -255,6 +255,9 @@
"note-cannot-be-displayed": "This note type cannot be displayed."
},
"pdf": {
"export_filter": "PDF Document (*.pdf)"
"export_filter": "PDF Document (*.pdf)",
"unable-to-export-message": "The current note could not be exported as a PDF.",
"unable-to-export-title": "Unable to export as PDF",
"unable-to-save-message": "The selected file could not be written to. Try again or select another destination."
}
}