Skip to content

Commit

Permalink
feat(pdf): error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
eliandoran committed Jan 31, 2025
1 parent d4965e8 commit 84532d4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
17 changes: 13 additions & 4 deletions src/services/window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
fs.writeFileSync(filePath, buffer);
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);
});
Expand Down
5 changes: 4 additions & 1 deletion translations/en/server.json
Original file line number Diff line number Diff line change
Expand Up @@ -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."
}
}

0 comments on commit 84532d4

Please sign in to comment.