@@ -7,7 +7,7 @@ import child_process from "child_process"
77import pkg from "electron"
88const { app, dialog } = pkg
99import { getPort } from "get-port-please"
10- import pidtree from "pidtree "
10+ import kill from "tree-kill "
1111import isElectron from "is-electron"
1212
1313import { 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
9187async 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