kill all subprocesses on closing #6

Merged
Anri merged 4 commits from fix-4 into main 2024-05-17 21:24:04 +02:00
2 changed files with 17 additions and 1 deletions
Showing only changes of commit dd62f81e35 - Show all commits

View file

@ -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();
});

View file

@ -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);
});
});
};