|
@ -3,25 +3,23 @@ |
|
|
|
|
|
|
|
|
const electron = require('electron'), |
|
|
const electron = require('electron'), |
|
|
app = electron.app, |
|
|
app = electron.app, |
|
|
BrowserWindow = electron.BrowserWindow; |
|
|
BrowserWindow = electron.BrowserWindow, |
|
|
var express = require('express'), |
|
|
path = require('path'), |
|
|
bodyParser = require('body-parser'); |
|
|
|
|
|
const path = require('path'), |
|
|
|
|
|
url = require('url'), |
|
|
url = require('url'), |
|
|
os = require('os'), |
|
|
os = require('os'), |
|
|
spawn = require('child_process').spawn, |
|
|
spawn = require('child_process').spawn, |
|
|
exec = require('child_process').exec; |
|
|
exec = require('child_process').exec, |
|
|
var fs = require('fs'), |
|
|
fixPath = require('fix-path'); |
|
|
|
|
|
var express = require('express'), |
|
|
|
|
|
bodyParser = require('body-parser'), |
|
|
|
|
|
fs = require('fs'), |
|
|
|
|
|
fsnode = require('fs'), |
|
|
fs = require('fs-extra'), |
|
|
fs = require('fs-extra'), |
|
|
mkdirp = require('mkdirp'), |
|
|
mkdirp = require('mkdirp'), |
|
|
pm2 = require('pm2'); |
|
|
pm2 = require('pm2'); |
|
|
|
|
|
|
|
|
var iguanaAppPort = 17777; |
|
|
|
|
|
|
|
|
|
|
|
Promise = require('bluebird'); |
|
|
Promise = require('bluebird'); |
|
|
|
|
|
|
|
|
var appConfig = JSON.parse(fs.readFileSync('config.json', 'utf8')); |
|
|
|
|
|
|
|
|
|
|
|
app.setName('Iguana'); |
|
|
app.setName('Iguana'); |
|
|
|
|
|
|
|
|
if (os.platform() === 'linux') { |
|
|
if (os.platform() === 'linux') { |
|
@ -29,45 +27,47 @@ if (os.platform() === 'linux') { |
|
|
console.log(process.env); |
|
|
console.log(process.env); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// GUI APP settings and starting gui on address http://120.0.0.1:17777
|
|
|
|
|
|
var shepherd = require('./routes/shepherd'), |
|
|
|
|
|
guiapp = express(); |
|
|
|
|
|
|
|
|
|
|
|
var appConfig = shepherd.loadLocalConfig(); // load app config
|
|
|
|
|
|
|
|
|
// preload.js
|
|
|
// preload.js
|
|
|
const _setImmediate = setImmediate, |
|
|
const _setImmediate = setImmediate, |
|
|
_clearImmediate = clearImmediate; |
|
|
_clearImmediate = clearImmediate; |
|
|
|
|
|
|
|
|
process.once('loaded', () => { |
|
|
process.once('loaded', () => { |
|
|
global.setImmediate = _setImmediate; |
|
|
global.setImmediate = _setImmediate; |
|
|
global.clearImmediate = _clearImmediate; |
|
|
global.clearImmediate = _clearImmediate; |
|
|
|
|
|
|
|
|
if (os.platform() === 'darwin') { |
|
|
if (os.platform() === 'darwin') { |
|
|
process.setFdLimit(90000); |
|
|
process.setFdLimit(appConfig.maxDescriptors.darwin); |
|
|
} |
|
|
} |
|
|
if (os.platform() === 'linux') { |
|
|
if (os.platform() === 'linux') { |
|
|
process.setFdLimit(1000000); |
|
|
process.setFdLimit(appConfig.maxDescriptors.linux); |
|
|
} |
|
|
} |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
// GUI APP settings and starting gui on address http://120.0.0.1:17777
|
|
|
|
|
|
var shepherd = require('./routes/shepherd'), |
|
|
|
|
|
guiapp = express(); |
|
|
|
|
|
|
|
|
|
|
|
guiapp.use(bodyParser.json()); // support json encoded bodies
|
|
|
guiapp.use(bodyParser.json()); // support json encoded bodies
|
|
|
guiapp.use(bodyParser.urlencoded({ extended: false })); // support encoded bodies
|
|
|
guiapp.use(bodyParser.urlencoded({ extended: false })); // support encoded bodies
|
|
|
|
|
|
|
|
|
guiapp.get('/', function (req, res) { |
|
|
guiapp.get('/', function (req, res) { |
|
|
res.send('Iguana app server'); |
|
|
res.send('Iguana app server'); |
|
|
}) |
|
|
}); |
|
|
|
|
|
|
|
|
var guipath = path.join(__dirname, '/gui'); |
|
|
var guipath = path.join(__dirname, '/gui'); |
|
|
guiapp.use('/gui', express.static(guipath)); |
|
|
guiapp.use('/gui', express.static(guipath)); |
|
|
|
|
|
|
|
|
guiapp.use('/shepherd', shepherd); |
|
|
guiapp.use('/shepherd', shepherd); |
|
|
|
|
|
|
|
|
var rungui = guiapp.listen(iguanaAppPort, function () { |
|
|
var rungui = guiapp.listen(appConfig.iguanaAppPort, function () { |
|
|
console.log('guiapp listening on port ' + iguanaAppPort + '!'); |
|
|
console.log('guiapp listening on port ' + appConfig.iguanaAppPort + '!'); |
|
|
}) |
|
|
}) |
|
|
|
|
|
|
|
|
module.exports = guiapp; |
|
|
module.exports = guiapp; |
|
|
// END GUI App Settings
|
|
|
// END GUI App Settings
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//require('./assets/js/iguana.js'); //below code shall be separated into asset js for public version
|
|
|
//require('./assets/js/iguana.js'); //below code shall be separated into asset js for public version
|
|
|
/* |
|
|
/* |
|
|
// SELECTING IGUANA BUILD TO RUN AS PER OS DETECTED BY DESKTOP APP
|
|
|
// SELECTING IGUANA BUILD TO RUN AS PER OS DETECTED BY DESKTOP APP
|
|
@ -138,7 +138,7 @@ function createLoadingWindow() { |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
// load our index.html (i.e. easyDEX GUI)
|
|
|
// load our index.html (i.e. easyDEX GUI)
|
|
|
loadingWindow.loadURL('http://127.0.0.1:17777/gui/'); |
|
|
loadingWindow.loadURL('http://' + appConfig.host + ':' + appConfig.iguanaAppPort + '/gui/'); |
|
|
|
|
|
|
|
|
// DEVTOOLS - only for dev purposes - ca333
|
|
|
// DEVTOOLS - only for dev purposes - ca333
|
|
|
//loadingWindow.webContents.openDevTools()
|
|
|
//loadingWindow.webContents.openDevTools()
|
|
@ -171,7 +171,7 @@ function createLoadingWindow() { |
|
|
//if (os.platform() !== 'win32') { ig.stderr.on( 'error: ', data => { console.log( `stderr: ${data}` ); }); }
|
|
|
//if (os.platform() !== 'win32') { ig.stderr.on( 'error: ', data => { console.log( `stderr: ${data}` ); }); }
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
app.on('ready', createLoadingWindow) |
|
|
app.on('ready', createLoadingWindow); |
|
|
|
|
|
|
|
|
function createWindow (status) { |
|
|
function createWindow (status) { |
|
|
if ( status === 'open') { |
|
|
if ( status === 'open') { |
|
@ -187,9 +187,9 @@ function createWindow (status) { |
|
|
|
|
|
|
|
|
// load our index.html (i.e. easyDEX GUI)
|
|
|
// load our index.html (i.e. easyDEX GUI)
|
|
|
if (appConfig.edexGuiOnly) { |
|
|
if (appConfig.edexGuiOnly) { |
|
|
mainWindow.loadURL('http://127.0.0.1:' + iguanaAppPort + '/gui/EasyDEX-GUI/'); |
|
|
mainWindow.loadURL('http://' + appConfig.host + ':' + appConfig.iguanaAppPort + '/gui/EasyDEX-GUI/'); |
|
|
} else { |
|
|
} else { |
|
|
mainWindow.loadURL('http://127.0.0.1:' + iguanaAppPort + '/gui/main.html'); |
|
|
mainWindow.loadURL('http://' + appConfig.host + ':' + appConfig.iguanaAppPort + '/gui/main.html'); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// DEVTOOLS - only for dev purposes - ca333
|
|
|
// DEVTOOLS - only for dev purposes - ca333
|
|
@ -201,7 +201,7 @@ function createWindow (status) { |
|
|
return new Promise(function(resolve, reject) { |
|
|
return new Promise(function(resolve, reject) { |
|
|
console.log('Closing Main Window...'); |
|
|
console.log('Closing Main Window...'); |
|
|
|
|
|
|
|
|
pm2.connect(true,function(err) { |
|
|
pm2.connect(true, function(err) { |
|
|
console.log('connecting to pm2...'); |
|
|
console.log('connecting to pm2...'); |
|
|
|
|
|
|
|
|
if (err) { |
|
|
if (err) { |
|
@ -223,6 +223,7 @@ function createWindow (status) { |
|
|
pm2.killDaemon(function(err) { |
|
|
pm2.killDaemon(function(err) { |
|
|
pm2.disconnect(); |
|
|
pm2.disconnect(); |
|
|
console.log('killed to pm2...'); |
|
|
console.log('killed to pm2...'); |
|
|
|
|
|
|
|
|
if (err) |
|
|
if (err) |
|
|
throw err; |
|
|
throw err; |
|
|
}); |
|
|
}); |
|
|