My electron app consists of '2 hello' buttons and 2 'cancel' buttons. Each 'hello' button will triggered a child process which carry out same function and cancel button will kill the child process.
My problem is the function that triggered by the second "hello" button can be terminated by the first cancel button.
All I want is the first 'cancel' button will kill the first 'hello' button's child process only and so on.
Any suggestions and help will be appreciated. Thank you
My code on electron:
let process = null
ipcMain.on("runScript", (event, data) => {
process = spawn('node helloworld.js', [], { shell:
true })
});
ipcMain.on("killScript", (event, data) => {
console.log(process)
kill(process.pid, 'SIGKILL')
});
on my client side:
<div>
<button onClick={() => ipcRenderer.send('runScript')}>hello</button>
<button onClick={() => ipcRenderer.send('killScript')}>cancel</button>
</div>
