I am working on launching a windows application.exe from an electron application with a button click. The first button click will launch the application.exe and when the button is again clicked for the second time, the program checks from the running process of the application.exe. If the windows application is not running, exe will be executed, but if the application is already running and minimized. The electron app window should restore the minimized windows application focus the application on the screen.
I have achieved till launching and checking whether the application is already running or not using child process and task list. Just need help to restore the minimized window and set focus.
let executablePath = "";
let currentWindow = window.require("electron").remote.getCurrentWindow();
child('tasklist', function(error, stdout, stderr) {
var lines = stdout.trim().split("\n");
var processes = lines.slice(2);
var parsed = processes.map(function(process) {
return process.match(/(.+?)[\s]+?(\d+)/);
});
var filtered = parsed.filter(function(process) {
return /^AppName/.test(process[1]);
});
if(filtered.length > 0){
currentWindow.minimize();
}
else{
child(executablePath, function(err, data) {
if(err){
console.error(err.message);
return;
}
});
}
});