Refactor file download handling to improve error management and user notifications

This commit is contained in:
MikeHughes-BIN
2026-01-18 17:32:29 +01:00
parent 18e791d56e
commit 013c9b5f2c
+27 -5
View File
@@ -225,20 +225,42 @@ electron.ipcMain.on("file_submit", async (event, args) => {
}
})
ipcMain.handle("file_download", async () => {
electron.ipcMain.on("file_download", async (event) => {
try {
const format = globalArgs.document.outputType.replace('.', '').toLowerCase();
if (!globalFinalHtmlPath) {
throw new Error("No document generated yet");
}
return await mapFunctions
const format = String(globalArgs?.document?.outputType || "")
.replace('.', '')
.toLowerCase();
if (!format) {
throw new Error("No output format selected");
}
const outputPath = await mapFunctions
.get("htmlDocumentConverter")
.convert({
inputPath: globalFinalHtmlPath,
format,
showDialog: true
});
event.sender.send("download_success", {
path: outputPath,
format
});
new Notification({
title: "Erfolgreich gespeichert",
body: `Dokument gespeichert als .${format}`
}).show();
} catch (err) {
console.error("Download failed:", err);
throw err;
console.error("file_download failed:", err);
event.sender.send("error", err.message || String(err));
}
});