-
-
Save ca333/187a6d8603424b50ca518cccfc82bcf5 to your computer and use it in GitHub Desktop.
electron_pm2_app
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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