wip: kill all subprocesses on closing (not working)

This commit is contained in:
Mylloon 2024-01-13 02:02:34 +01:00
parent 05de7dc801
commit dd62f81e35
Signed by: Anri
GPG key ID: A82D63DFF8D1317F
2 changed files with 17 additions and 1 deletions

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