Skip to content

Commit

Permalink
PPTX export: force tmp dir removal after output file closed
Browse files Browse the repository at this point in the history
  • Loading branch information
aumouvantsillage committed Sep 21, 2022
1 parent 24f5322 commit a855c63
Showing 1 changed file with 21 additions and 23 deletions.
44 changes: 21 additions & 23 deletions src/js/exporter/index-electron.js
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ export async function exportToPPTX(presentation, htmlFileName) {
await w.loadURL(`file://${htmlFileName}`);

// Create a PPTX document object.
//officegen.setVerboseMode(true);
const pptxDoc = officegen("pptx");
pptxDoc.setSlideSize(g.width, g.height, presentation.exportToPPTXSlideSize);

Expand All @@ -320,28 +321,6 @@ export async function exportToPPTX(presentation, htmlFileName) {
const callerId = remote.getCurrentWindow().webContents.id;

return new Promise((resolve, reject) => {
pptxDoc.on("finalize", () => {
// Remove the temporary image folder, ignoring exceptions on failure.
try {
destDir.removeCallback();
}
catch (e) {
console.log(e);
}
resolve();
});

pptxDoc.on("error", () => {
// Remove the temporary image folder, ignoring exceptions on failure.
try {
destDir.removeCallback();
}
catch (e) {
console.log(e);
}
reject();
});

// On each jumpToFrame event in the player, save the current web contents.
ipcRenderer.on("jumpToFrame.done", async (evt, index) => {
// Capture the current web contents into a PNG image file.
Expand All @@ -363,9 +342,28 @@ export async function exportToPPTX(presentation, htmlFileName) {
ipcRenderer.removeAllListeners("jumpToFrame.done");
w.close();

function terminate() {
// Remove the temporary image folder, ignoring exceptions on failure.
try {
destDir.removeCallback();
}
catch (e) {
console.log(e);
}
}

const pptxFileName = htmlFileName.replace(/html$/, "pptx");
const pptxFile = fs.createWriteStream(pptxFileName);
pptxDoc.generate(pptxFile);
pptxFile.on("close", () => {
terminate();
resolve();
});
pptxDoc.generate(pptxFile, {
error() {
terminate();
reject();
}
});
}
});

Expand Down

0 comments on commit a855c63

Please sign in to comment.