diff --git a/src/main.ts b/src/main.ts index 3ca565e..de3d4a4 100644 --- a/src/main.ts +++ b/src/main.ts @@ -7,6 +7,7 @@ import { getNewFilename, getVideoDuration, printAndDevTool, + processes, } from "./utils/misc"; import path = require("path"); import ffmpegPath = require("ffmpeg-static"); @@ -226,3 +227,11 @@ app.whenReady().then(() => { ipcMain.handle("exit", () => (error ? {} : app.quit())); ipcMain.handle("confirmation", (_, text: string) => confirmation(text)); }); + +app.on("window-all-closed", () => { + processes.forEach((proc) => { + proc.kill(); + }); + + app.quit(); +}); diff --git a/src/utils/misc.ts b/src/utils/misc.ts index 95d66d2..af72c6e 100644 --- a/src/utils/misc.ts +++ b/src/utils/misc.ts @@ -4,6 +4,8 @@ import path = require("path"); import { BrowserWindow } from "electron"; import { existsSync, unlink } from "fs"; +export const processes: child_process.ChildProcess[] = []; + /** Create a new filename from the OG one */ export const getNewFilename = (ogFile: string, part: string) => { const oldFile = path.parse(ogFile); @@ -28,13 +30,18 @@ export const execute = ( command: string ): Promise<{ stdout: string; stderr: string }> => { return new Promise((resolve, reject) => { - child_process.exec(command, (error, stdout, stderr) => { + const process = child_process.exec(command, (error, stdout, stderr) => { if (error) { reject(error); } else { resolve({ stdout, stderr }); } }); + + processes.push(process); + process.on("exit", () => { + processes.splice(processes.indexOf(process), 1); + }); }); };