Browse Source

code cleanup #3

all-modes
Petr Balashov 8 years ago
parent
commit
0026f50759
  1. 60
      main.js
  2. 20
      routes/shepherd.js

60
main.js

@ -142,12 +142,12 @@ guiapp.get('/', function (req, res) {
res.send('Agama app server');
});
var guipath = path.join(__dirname, '/gui');
const guipath = path.join(__dirname, '/gui');
guiapp.use('/gui', express.static(guipath));
guiapp.use('/shepherd', shepherd);
var server = require('http').createServer(guiapp),
io = require('socket.io').listen(server);
const server = require('http').createServer(guiapp);
const io = require('socket.io').listen(server);
server.listen(appConfig.agamaPort, function() {
console.log(`guiapp and sockets.io are listening on port ${appConfig.agamaPort}`);
@ -177,12 +177,13 @@ shepherd.setVar('appBasicInfo', appBasicInfo);
shepherd.setVar('appSessionHash', appSessionHash);
module.exports = guiapp;
var iguanaIcon;
if (os.platform() === 'linux') {
var iguanaIcon = path.join(__dirname, '/assets/icons/agama_icons/128x128.png');
iguanaIcon = path.join(__dirname, '/assets/icons/agama_icons/128x128.png');
}
if (os.platform() === 'win32') {
var iguanaIcon = path.join(__dirname, '/assets/icons/agama_icons/agama_app_icon.ico');
iguanaIcon = path.join(__dirname, '/assets/icons/agama_icons/agama_app_icon.ico');
}
let mainWindow;
@ -227,35 +228,6 @@ function createLoadingWindow() {
e.preventDefault();
}
});
/*
* var ipc = require('electron').ipcRenderer;
* ipc.once('coincliReply', function(event, response){
* console.log(response);
* });
* ipc.send('InvokeCoinCliAction', '{"cli":"kmd","command":"getinfo"}');
*/
ipc.on('InvokeCoinCliAction', function(event, data){
console.log(JSON.stringify(data));
console.log(data.cli)
console.log(data.command)
if (data.cli == 'kmd') {
coincli.kmdcommand(data.command, function(err, command) {
//console.log(command);
var result = command;
event.sender.send('coincliReply', result);
});
}
if (data.cli == 'zec') {
coincli.zeccommand(data.command, function(err, command) {
//console.log(command);
var result = command;
event.sender.send('coincliReply', result);
});
}
});
}
app.on('ready', createLoadingWindow);
@ -328,7 +300,7 @@ function createWindow (status) {
// mainWindow.webContents.openDevTools()
function pm2Exit() {
var ConnectToPm2 = function() {
const ConnectToPm2 = function() {
return new Promise(function(resolve, reject) {
console.log('Closing Main Window...');
shepherd.writeLog('exiting app...');
@ -349,7 +321,7 @@ function createWindow (status) {
}
});
var result = 'Connecting To Pm2: done';
const result = 'Connecting To Pm2: done';
console.log(result);
shepherd.writeLog(result);
@ -357,7 +329,7 @@ function createWindow (status) {
})
}
var KillPm2 = function() {
const KillPm2 = function() {
return new Promise(function(resolve, reject) {
console.log('killing to pm2...');
shepherd.writeLog('killing to pm2...');
@ -371,7 +343,7 @@ function createWindow (status) {
throw err;
});
var result = 'Killing Pm2: done';
const result = 'Killing Pm2: done';
setTimeout(function() {
console.log(result);
@ -382,21 +354,21 @@ function createWindow (status) {
})
}
var HideMainWindow = function() {
const HideMainWindow = function() {
return new Promise(function(resolve, reject) {
console.log('Exiting App...');
mainWindow = null;
var result = 'Hiding Main Window: done';
const result = 'Hiding Main Window: done';
console.log(result);
resolve(result);
});
}
var QuitApp = function() {
const QuitApp = function() {
return new Promise(function(resolve, reject) {
app.quit();
var result = 'Quiting App: done';
const result = 'Quiting App: done';
console.log(result);
resolve(result);
});
@ -471,7 +443,7 @@ function formatBytes(bytes, decimals) {
if (bytes === 0)
return '0 Bytes';
var k = 1000,
const k = 1000,
dm = decimals + 1 || 3,
sizes = [
'Bytes',
@ -486,5 +458,5 @@ function formatBytes(bytes, decimals) {
],
i = Math.floor(Math.log(bytes) / Math.log(k));
return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i];
return `${parseFloat((bytes / Math.pow(k, i)).toFixed(dm))} ${sizes[i]}`;
}

20
routes/shepherd.js

@ -342,7 +342,7 @@ shepherd.post('/cli', function(req, res, next) {
const _mode = req.body.payload.mode === 'passthru' ? 'passthru' : 'default';
const _chain = req.body.payload.chain === 'KMD' ? null : req.body.payload.chain;
const _cmd = req.body.payload.cmd;
const _params = req.body.payload.params ? ' ' + req.body.payload.params : '';
const _params = req.body.payload.params ? ` ${req.body.payload.params}` : '';
if (!rpcConf[_chain]) {
shepherd.getConf(req.body.payload.chain === 'KMD' ? 'komodod' : req.body.payload.chain);
@ -442,7 +442,7 @@ shepherd.saveLocalAppConf = function(appSettings) {
_fs.access(iguanaDir, fs.constants.R_OK, function(err) {
if (!err) {
var FixFilePermissions = function() {
const FixFilePermissions = function() {
return new Promise(function(resolve, reject) {
const result = 'config.json file permissions updated to Read/Write';
@ -762,9 +762,9 @@ shepherd.post('/forks', function(req, res, next) {
pm2.start({
script: iguanaBin, // path to binary
name: 'IGUANA ' + _port + ' ' + mode + ' / ' + coin,
name: `IGUANA ${_port} ${mode} / ${coin}`,
exec_mode : 'fork',
args: ['-port=' + _port],
args: [`-port=${_port}`],
cwd: iguanaDir //set correct iguana directory
}, function(err, apps) {
iguanaInstanceRegistry[_port] = {
@ -1296,7 +1296,7 @@ function herder(flock, data) {
}
// get komodod instance port
var _port = assetChainPorts[data.ac_name];
const _port = assetChainPorts[data.ac_name];
try {
// check if komodod instance is already running
@ -1314,9 +1314,9 @@ function herder(flock, data) {
if (data.ac_custom_param === 'silent' ||
data.ac_custom_param === 'reindex') {
_customParam = ' ' + _customParamDict[data.ac_custom_param];
_customParam = ` ${_customParamDict[data.ac_custom_param]}`;
} else if (data.ac_custom_param === 'change' && data.ac_custom_param_value) {
_customParam = ' ' + _customParamDict[data.ac_custom_param] + data.ac_custom_param_value;
_customParam = ` ${_customParamDict[data.ac_custom_param]}${data.ac_custom_param_value}`;
}
console.log(`exec ${komododBin} ${data.ac_options.join(' ')}${_customParam}`);
@ -1576,7 +1576,7 @@ function setConf(flock) {
});
}
var CheckConf = function() {
const CheckConf = function() {
return new Promise(function(resolve, reject) {
const result = 'CheckConf is done';
@ -1654,7 +1654,7 @@ function setConf(flock) {
});
}
var addnode = function() {
const addnode = function() {
return new Promise(function(resolve, reject) {
const result = 'checking addnode...';
@ -1699,7 +1699,7 @@ function setConf(flock) {
});
}
var MakeConfReadOnly = function() {
const MakeConfReadOnly = function() {
return new Promise(function(resolve, reject) {
const result = 'Conf file permissions updated to Read Only';

Loading…
Cancel
Save