Skip to content

Commit d488bc6

Browse files
committed
tree-kill
1 parent 0aab226 commit d488bc6

File tree

3 files changed

+19
-13
lines changed

3 files changed

+19
-13
lines changed

package-lock.json

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
"pinia": "3.0.3",
6161
"sass": "1.87.0",
6262
"semver": "7.7.1",
63+
"tree-kill": "^1.2.2",
6364
"uuid": "11.1.0",
6465
"vue-recaptcha": "2.0.3",
6566
"vue3-carousel": "0.3.4",

utils/local.js

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import child_process from "child_process"
77
import pkg from "electron"
88
const { app, dialog } = pkg
99
import { getPort } from "get-port-please"
10-
import pidtree from "pidtree"
10+
import kill from "tree-kill"
1111
import isElectron from "is-electron"
1212

1313
import { fileURLToPath } from "url"
@@ -71,21 +71,17 @@ async function kill_processes() {
7171
await processes.forEach(async function (proc) {
7272
console.log(`Process ${proc} will be killed!`)
7373
try {
74-
process.kill(proc)
74+
kill(proc)
7575
} catch (error) {
7676
console.log(`${error} Process ${proc} could not be killed!`)
7777
}
7878
})
7979
}
8080

81-
function register_children_processes(proc) {
82-
pidtree(proc.pid, { root: true }, function (err, pids) {
83-
if (err) {
84-
console.log("err", err)
85-
return
86-
}
87-
processes.push(...pids)
88-
})
81+
function register_process(proc) {
82+
if (!processes.includes(proc.pid)) {
83+
processes.push(proc.pid)
84+
}
8985
}
9086

9187
async function run_script(
@@ -102,7 +98,7 @@ async function run_script(
10298
encoding: "utf8",
10399
shell: true,
104100
})
105-
register_children_processes(child)
101+
register_process(child)
106102

107103
// You can also use a variable to save the output for when the script closes later
108104
child.stderr.setEncoding("utf8")
@@ -118,7 +114,6 @@ async function run_script(
118114
//Here is the output
119115
data = data.toString()
120116
if (data.includes(expected_response)) {
121-
register_children_processes(child)
122117
resolve(child)
123118
}
124119
console.log(data)
@@ -176,7 +171,7 @@ export {
176171
executable_path,
177172
get_available_port,
178173
kill_processes,
179-
register_children_processes,
174+
register_process as register_children_processes,
180175
run_script,
181176
run_back,
182177
run_viewer,

0 commit comments

Comments
 (0)