Merge pull request 'kill all subprocesses on closing' (#6) from fix-4 into main

Reviewed-on: #6
This commit is contained in:
Mylloon 2024-05-17 21:24:03 +02:00
commit eb84c48b3c
Signed by: Forgejo
GPG key ID: E72245C752A07631
4 changed files with 119 additions and 1 deletions

99
package-lock.json generated
View file

@ -12,6 +12,7 @@
"@electron-forge/maker-zip": "^7.4",
"ffmpeg-static": "^5.2",
"ffprobe-static": "^3.1",
"terminate": "^2.6.1",
"typescript": "^5.4"
},
"devDependencies": {
@ -1591,6 +1592,12 @@
"p-limit": "^3.1.0 "
}
},
"node_modules/duplexer": {
"version": "0.1.2",
"resolved": "https://registry.npmjs.org/duplexer/-/duplexer-0.1.2.tgz",
"integrity": "sha512-jtD6YG370ZCIi/9GTaJKQxWTZD045+4R4hTk/x1UyoqadyJ9x9CgSi1RlVDQF8U2sxLLSnFkCaMihqljHIWgMg==",
"license": "MIT"
},
"node_modules/eastasianwidth": {
"version": "0.2.0",
"resolved": "https://registry.npmjs.org/eastasianwidth/-/eastasianwidth-0.2.0.tgz",
@ -1784,6 +1791,21 @@
"url": "https://github.com/sponsors/sindresorhus"
}
},
"node_modules/event-stream": {
"version": "3.3.4",
"resolved": "https://registry.npmjs.org/event-stream/-/event-stream-3.3.4.tgz",
"integrity": "sha512-QHpkERcGsR0T7Qm3HNJSyXKEEj8AHNxkY3PK8TS2KJvQ7NiSHe3DDpwVKKtoYprL/AreyzFBeIkBIWChAqn60g==",
"license": "MIT",
"dependencies": {
"duplexer": "~0.1.1",
"from": "~0",
"map-stream": "~0.1.0",
"pause-stream": "0.0.11",
"split": "0.3",
"stream-combiner": "~0.0.4",
"through": "~2.3.1"
}
},
"node_modules/eventemitter3": {
"version": "5.0.1",
"resolved": "https://registry.npmjs.org/eventemitter3/-/eventemitter3-5.0.1.tgz",
@ -2061,6 +2083,12 @@
"node": ">= 12"
}
},
"node_modules/from": {
"version": "0.1.7",
"resolved": "https://registry.npmjs.org/from/-/from-0.1.7.tgz",
"integrity": "sha512-twe20eF1OxVxp/ML/kq2p1uc6KvFK/+vs8WjEbeKmV2He22MKm7YF2ANIt+EOqhJ5L3K/SuuPhk0hWQDjOM23g==",
"license": "MIT"
},
"node_modules/fs-extra": {
"version": "10.1.0",
"resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-10.1.0.tgz",
@ -3015,6 +3043,11 @@
"node": ">=6"
}
},
"node_modules/map-stream": {
"version": "0.1.0",
"resolved": "https://registry.npmjs.org/map-stream/-/map-stream-0.1.0.tgz",
"integrity": "sha512-CkYQrPYZfWnu/DAmVCpTSX/xHpKZ80eKh2lAkyA6AJTef6bW+6JpbQZN5rofum7da+SyN1bi5ctTm+lTfcCW3g=="
},
"node_modules/matcher": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/matcher/-/matcher-3.0.0.tgz",
@ -3666,6 +3699,18 @@
"node": ">=4"
}
},
"node_modules/pause-stream": {
"version": "0.0.11",
"resolved": "https://registry.npmjs.org/pause-stream/-/pause-stream-0.0.11.tgz",
"integrity": "sha512-e3FBlXLmN/D1S+zHzanP4E/4Z60oFAa3O051qt1pxa7DEJWKAyil6upYVXCWadEnuoqa4Pkc9oUx9zsxYeRv8A==",
"license": [
"MIT",
"Apache2"
],
"dependencies": {
"through": "~2.3"
}
},
"node_modules/pe-library": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/pe-library/-/pe-library-1.0.1.tgz",
@ -3843,6 +3888,21 @@
"node": ">=10"
}
},
"node_modules/ps-tree": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/ps-tree/-/ps-tree-1.2.0.tgz",
"integrity": "sha512-0VnamPPYHl4uaU/nSFeZZpR21QAWRz+sRv4iW9+v/GS/J5U5iZB5BNN6J0RMoOvdx2gWM2+ZFMIm58q24e4UYA==",
"license": "MIT",
"dependencies": {
"event-stream": "=3.3.4"
},
"bin": {
"ps-tree": "bin/ps-tree.js"
},
"engines": {
"node": ">= 0.10"
}
},
"node_modules/pump": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/pump/-/pump-3.0.0.tgz",
@ -4434,6 +4494,18 @@
"integrity": "sha512-sh8PWc/ftMqAAdFiBu6Fy6JUOYjqDJBJvIhpfDMyHrr0Rbp5liZqd4TjtQ/RgfLjKFZb+LMx5hpml5qOWy0qvg==",
"license": "CC0-1.0"
},
"node_modules/split": {
"version": "0.3.3",
"resolved": "https://registry.npmjs.org/split/-/split-0.3.3.tgz",
"integrity": "sha512-wD2AeVmxXRBoX44wAycgjVpMhvbwdI2aZjCkvfNcH1YqHQvJVa1duWc73OyVGJUc05fhFaTZeQ/PYsrmyH0JVA==",
"license": "MIT",
"dependencies": {
"through": "2"
},
"engines": {
"node": "*"
}
},
"node_modules/sprintf-js": {
"version": "1.1.3",
"resolved": "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.1.3.tgz",
@ -4452,6 +4524,15 @@
"node": "^12.13.0 || ^14.15.0 || >=16.0.0"
}
},
"node_modules/stream-combiner": {
"version": "0.0.4",
"resolved": "https://registry.npmjs.org/stream-combiner/-/stream-combiner-0.0.4.tgz",
"integrity": "sha512-rT00SPnTVyRsaSz5zgSPma/aHSOic5U1prhYdRy5HS2kTZviFpmDgzilbtsJsxiroqACmayynDN/9VzIbX5DOw==",
"license": "MIT",
"dependencies": {
"duplexer": "~0.1.1"
}
},
"node_modules/string_decoder": {
"version": "1.3.0",
"resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.3.0.tgz",
@ -4602,6 +4683,24 @@
"node": ">=8"
}
},
"node_modules/terminate": {
"version": "2.6.1",
"resolved": "https://registry.npmjs.org/terminate/-/terminate-2.6.1.tgz",
"integrity": "sha512-0kdr49oam98yvjkVY+gfUaT3SMaJI6Sc+yijJjU+qhat+0NQKQn60OsIZZeKyVgTO0/33nRa3HowRbpw3A7u9A==",
"license": "GPL-2.0",
"dependencies": {
"ps-tree": "^1.2.0"
},
"engines": {
"node": ">=12"
}
},
"node_modules/through": {
"version": "2.3.8",
"resolved": "https://registry.npmjs.org/through/-/through-2.3.8.tgz",
"integrity": "sha512-w89qg7PI8wAdvX60bMDP+bFoD5Dvhm9oLheFp5O4a2QF0cSBGsBX4qZmadPMvVqlLJBBci+WqGGOAPvcDeNSVg==",
"license": "MIT"
},
"node_modules/to-regex-range": {
"version": "5.0.1",
"resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz",

View file

@ -21,6 +21,7 @@
"@electron-forge/maker-zip": "^7.4",
"ffmpeg-static": "^5.2",
"ffprobe-static": "^3.1",
"terminate": "^2.6",
"typescript": "^5.4"
},
"devDependencies": {

View file

@ -7,10 +7,13 @@ import {
getNewFilename,
getVideoDuration,
printAndDevTool,
processes,
} from "./utils/misc";
import path = require("path");
import ffmpegPath = require("ffmpeg-static");
const kill = require("terminate");
let error = false;
const moviesFilter = {
@ -226,3 +229,11 @@ app.whenReady().then(() => {
ipcMain.handle("exit", () => (error ? {} : app.quit()));
ipcMain.handle("confirmation", (_, text: string) => confirmation(text));
});
app.on("window-all-closed", () => {
processes.forEach((process) => {
kill(process.pid);
});
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);
});
});
};