@@ -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,18 +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 ) console . log ( "err" , err )
84- processes . push ( ...pids )
85- } )
81+ function register_process ( proc ) {
82+ if ( ! processes . includes ( proc . pid ) ) {
83+ processes . push ( proc . pid )
84+ }
8685}
8786
8887async function run_script (
@@ -99,7 +98,7 @@ async function run_script(
9998 encoding : "utf8" ,
10099 shell : true ,
101100 } )
102- register_children_processes ( child )
101+ register_process ( child )
103102
104103 // You can also use a variable to save the output for when the script closes later
105104 child . stderr . setEncoding ( "utf8" )
@@ -115,7 +114,6 @@ async function run_script(
115114 //Here is the output
116115 data = data . toString ( )
117116 if ( data . includes ( expected_response ) ) {
118- register_children_processes ( child )
119117 resolve ( child )
120118 }
121119 console . log ( data )
@@ -173,7 +171,7 @@ export {
173171 executable_path ,
174172 get_available_port ,
175173 kill_processes ,
176- register_children_processes ,
174+ register_process ,
177175 run_script ,
178176 run_back ,
179177 run_viewer ,
0 commit comments