wip: kill all subprocesses on closing (not working)
This commit is contained in:
parent
05de7dc801
commit
dd62f81e35
2 changed files with 17 additions and 1 deletions
|
@ -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();
|
||||
});
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue