Browse Source

code cleanup #3

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

92
main.js

@ -142,12 +142,12 @@ guiapp.get('/', function (req, res) {
res.send('Agama app server'); 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('/gui', express.static(guipath));
guiapp.use('/shepherd', shepherd); guiapp.use('/shepherd', shepherd);
var server = require('http').createServer(guiapp), const server = require('http').createServer(guiapp);
io = require('socket.io').listen(server); const io = require('socket.io').listen(server);
server.listen(appConfig.agamaPort, function() { server.listen(appConfig.agamaPort, function() {
console.log(`guiapp and sockets.io are listening on port ${appConfig.agamaPort}`); console.log(`guiapp and sockets.io are listening on port ${appConfig.agamaPort}`);
@ -177,12 +177,13 @@ shepherd.setVar('appBasicInfo', appBasicInfo);
shepherd.setVar('appSessionHash', appSessionHash); shepherd.setVar('appSessionHash', appSessionHash);
module.exports = guiapp; module.exports = guiapp;
var iguanaIcon;
if (os.platform() === 'linux') { 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') { 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; let mainWindow;
@ -227,35 +228,6 @@ function createLoadingWindow() {
e.preventDefault(); 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); app.on('ready', createLoadingWindow);
@ -314,8 +286,8 @@ function createWindow (status) {
mainWindow.loadURL(`http://${appConfig.host}:${appConfig.agamaPort}/gui/main.html`); mainWindow.loadURL(`http://${appConfig.host}:${appConfig.agamaPort}/gui/main.html`);
} }
mainWindow.webContents.on('context-menu', (e, params) => { //context-menu returns params mainWindow.webContents.on('context-menu', (e, params) => { // context-menu returns params
const { selectionText, isEditable } = params; //params obj const { selectionText, isEditable } = params; // params obj
if (isEditable) { if (isEditable) {
editMenu.popup(mainWindow); editMenu.popup(mainWindow);
@ -328,7 +300,7 @@ function createWindow (status) {
// mainWindow.webContents.openDevTools() // mainWindow.webContents.openDevTools()
function pm2Exit() { function pm2Exit() {
var ConnectToPm2 = function() { const ConnectToPm2 = function() {
return new Promise(function(resolve, reject) { return new Promise(function(resolve, reject) {
console.log('Closing Main Window...'); console.log('Closing Main Window...');
shepherd.writeLog('exiting app...'); 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); console.log(result);
shepherd.writeLog(result); shepherd.writeLog(result);
@ -357,7 +329,7 @@ function createWindow (status) {
}) })
} }
var KillPm2 = function() { const KillPm2 = function() {
return new Promise(function(resolve, reject) { return new Promise(function(resolve, reject) {
console.log('killing to pm2...'); console.log('killing to pm2...');
shepherd.writeLog('killing to pm2...'); shepherd.writeLog('killing to pm2...');
@ -371,7 +343,7 @@ function createWindow (status) {
throw err; throw err;
}); });
var result = 'Killing Pm2: done'; const result = 'Killing Pm2: done';
setTimeout(function() { setTimeout(function() {
console.log(result); console.log(result);
@ -382,21 +354,21 @@ function createWindow (status) {
}) })
} }
var HideMainWindow = function() { const HideMainWindow = function() {
return new Promise(function(resolve, reject) { return new Promise(function(resolve, reject) {
console.log('Exiting App...'); console.log('Exiting App...');
mainWindow = null; mainWindow = null;
var result = 'Hiding Main Window: done'; const result = 'Hiding Main Window: done';
console.log(result); console.log(result);
resolve(result); resolve(result);
}); });
} }
var QuitApp = function() { const QuitApp = function() {
return new Promise(function(resolve, reject) { return new Promise(function(resolve, reject) {
app.quit(); app.quit();
var result = 'Quiting App: done'; const result = 'Quiting App: done';
console.log(result); console.log(result);
resolve(result); resolve(result);
}); });
@ -471,20 +443,20 @@ function formatBytes(bytes, decimals) {
if (bytes === 0) if (bytes === 0)
return '0 Bytes'; return '0 Bytes';
var k = 1000, const k = 1000,
dm = decimals + 1 || 3, dm = decimals + 1 || 3,
sizes = [ sizes = [
'Bytes', 'Bytes',
'KB', 'KB',
'MB', 'MB',
'GB', 'GB',
'TB', 'TB',
'PB', 'PB',
'EB', 'EB',
'ZB', 'ZB',
'YB' 'YB'
], ],
i = Math.floor(Math.log(bytes) / Math.log(k)); 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 _mode = req.body.payload.mode === 'passthru' ? 'passthru' : 'default';
const _chain = req.body.payload.chain === 'KMD' ? null : req.body.payload.chain; const _chain = req.body.payload.chain === 'KMD' ? null : req.body.payload.chain;
const _cmd = req.body.payload.cmd; 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]) { if (!rpcConf[_chain]) {
shepherd.getConf(req.body.payload.chain === 'KMD' ? 'komodod' : req.body.payload.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) { _fs.access(iguanaDir, fs.constants.R_OK, function(err) {
if (!err) { if (!err) {
var FixFilePermissions = function() { const FixFilePermissions = function() {
return new Promise(function(resolve, reject) { return new Promise(function(resolve, reject) {
const result = 'config.json file permissions updated to Read/Write'; const result = 'config.json file permissions updated to Read/Write';
@ -762,9 +762,9 @@ shepherd.post('/forks', function(req, res, next) {
pm2.start({ pm2.start({
script: iguanaBin, // path to binary script: iguanaBin, // path to binary
name: 'IGUANA ' + _port + ' ' + mode + ' / ' + coin, name: `IGUANA ${_port} ${mode} / ${coin}`,
exec_mode : 'fork', exec_mode : 'fork',
args: ['-port=' + _port], args: [`-port=${_port}`],
cwd: iguanaDir //set correct iguana directory cwd: iguanaDir //set correct iguana directory
}, function(err, apps) { }, function(err, apps) {
iguanaInstanceRegistry[_port] = { iguanaInstanceRegistry[_port] = {
@ -1296,7 +1296,7 @@ function herder(flock, data) {
} }
// get komodod instance port // get komodod instance port
var _port = assetChainPorts[data.ac_name]; const _port = assetChainPorts[data.ac_name];
try { try {
// check if komodod instance is already running // check if komodod instance is already running
@ -1314,9 +1314,9 @@ function herder(flock, data) {
if (data.ac_custom_param === 'silent' || if (data.ac_custom_param === 'silent' ||
data.ac_custom_param === 'reindex') { 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) { } 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}`); 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) { return new Promise(function(resolve, reject) {
const result = 'CheckConf is done'; const result = 'CheckConf is done';
@ -1654,7 +1654,7 @@ function setConf(flock) {
}); });
} }
var addnode = function() { const addnode = function() {
return new Promise(function(resolve, reject) { return new Promise(function(resolve, reject) {
const result = 'checking addnode...'; const result = 'checking addnode...';
@ -1699,7 +1699,7 @@ function setConf(flock) {
}); });
} }
var MakeConfReadOnly = function() { const MakeConfReadOnly = function() {
return new Promise(function(resolve, reject) { return new Promise(function(resolve, reject) {
const result = 'Conf file permissions updated to Read Only'; const result = 'Conf file permissions updated to Read Only';

Loading…
Cancel
Save