Skip to content

Instantly share code, notes, and snippets.

@ca333

ca333/main.js Secret

Created January 8, 2017 05:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ca333/187a6d8603424b50ca518cccfc82bcf5 to your computer and use it in GitHub Desktop.
Save ca333/187a6d8603424b50ca518cccfc82bcf5 to your computer and use it in GitHub Desktop.
electron_pm2_app
const electron = require('electron')
const app = electron.app
const BrowserWindow = electron.BrowserWindow
const pm2 = require('pm2'); //pm2 node process manager https://github.com/Unitech/pm2
const path = require('path')
const url = require('url')
const fixPath = require('fix-path');
let mainWindow
function createWindow () {
pm2.connect(function(err) { //start up pm2 god
if (err) {
console.error(err);
process.exit(2);
}
var binpath = './path/to/my/binary';
pm2.start({
script : binpath,
exec_mode : 'fork',
cwd: './working_dir/'
}, function(err, apps) {
pm2.disconnect();
if (err) throw err
});
});
mainWindow = new BrowserWindow({width: 800, height: 600})
fixPath();
mainWindow.loadURL(url.format({
pathname: path.join(__dirname, 'index.html'),
protocol: 'file:',
slashes: true
}))
mainWindow.on('closed', function () {
mainWindow = null
})
}
app.on('ready', createWindow)
app.on('window-all-closed', function () {
/* pm2.killDaemon(function(err) { //start up pm2 god
if (err) {
console.error(err);
process.exit(2);
}
});
pm2.disconnect(); */
if (process.platform !== 'darwin') {
/* pm2.killDaemon(function(err) { //start up pm2 god
if (err) {
console.error(err);
process.exit(2);
}
});
pm2.disconnect(); */
app.quit()
}
})
app.on('activate', function () {
if (mainWindow === null) {
createWindow()
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment