Electron - Executing a program on button click


#1

Hey,

I am new to Electron and i want to build a small app for myself where i can execute programs/games etc on a button click.

If i open the electron app it automatically starts the program/game.

var child = require('child_process').execFile;
var executablePath = "D:\\Games\\GAMEFOLDER\\GAMENAME.exe";
child(executablePath, function(err, data) {
if(err){
console.error(err);
return;
 }
console.log(data.toString());
});

How do i code it so that it only starts the exe when i click a button?


#2

What file is this code from? Is it your main file?


#3

Yes, this is my main.js but i already found a way to do it using scripts in html with electron.shell


#4

I would suggest that you write your apps in a more conventional fashion for Electron: have all of the app code live in a folder with an index.html just like you would if you were making it available on the Internet, then use main.js to create a BrowserWindow that you can point at this HTML file. You can see this pattern exhibited in the Electron quick start.