Skip to content

Instantly share code, notes, and snippets.

@automation-stack
Last active February 23, 2016 16:56
Show Gist options
  • Select an option

  • Save automation-stack/b61b0119172b49710d04 to your computer and use it in GitHub Desktop.

Select an option

Save automation-stack/b61b0119172b49710d04 to your computer and use it in GitHub Desktop.
Restart electron application

Step 1 :

var child = require('child_process').exec;
var path = require('path');

var applicationPath, endIndex = process.resourcesPath.indexOf('/Contents');
applicationPath = process.resourcesPath.substring(0, endIndex); // Entire app path. param 1
var appToKill = 'Electron'; // assuming appName for testing purpose, param 2

console.log('Application Path to START : ' + applicationPath);
//we are passing process id for future reference
var daemon = child('sh restart.sh ' + applicationPath + ' ' + appToKill, function(err, stdout, stderr) {
    if (err) {
        console.log(err);
    }
    console.debug("STDOUT :", stdout);
    console.warn("STDERR : ", stderr);
});

Step 2 , restart.sh :

appToOpen=$1; # app to open, simulating  restart ( entire path of app )
killall -9 $2; #app Name, will come here ex : "Electron"
open -nF $appToOpen;

Windows: Yes, you can take the params dynmically, just for example i have hardcoded.

taskkill /f /fi "imagename eq Electron.exe"
start "TEST" /high "Electron.exe"

App will restart, In case of windows, similar code but some tools quiet.exe will help to start .bat process in hidden mode.

require('child_process').spawn, and using "detached:true" in options will make the process, independent from parent process which started it. It act's as like a daemon thread

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment