Browse Source

Merge pull request #24 from pbca26/master

fixed window.hide when min notaries are connected
all-modes
Satinder Grewal 8 years ago
committed by GitHub
parent
commit
1f19b95c08
  1. 4
      gui/index.html
  2. 2
      gui/init.js
  3. 151
      gui/loading.js
  4. 41
      main.js
  5. 68
      routes/shepherd.js

4
gui/index.html

@ -10,6 +10,10 @@
<script type="text/javascript" src="loading.js"></script> <script type="text/javascript" src="loading.js"></script>
<script type="text/javascript" src="jRoll.min.js"></script> <script type="text/javascript" src="jRoll.min.js"></script>
<script>if (window.module) module = window.module;</script> <script>if (window.module) module = window.module;</script>
<script type="text/javascript">
const remote = require('electron').remote;
var window = remote.getCurrentWindow();
</script>>
</head> </head>
<body style="overflow:hidden;"> <body style="overflow:hidden;">
<div style="text-align: center;"> <div style="text-align: center;">

2
gui/init.js

@ -5,8 +5,6 @@ $(document).ready(function() {
}); });
var appConf = GetAppConf(); var appConf = GetAppConf();
const remote = require('electron').remote;
var window = remote.getCurrentWindow();
$('#loading_status_text').text('Starting Iguana daemon...'); $('#loading_status_text').text('Starting Iguana daemon...');

151
gui/loading.js

@ -11,10 +11,12 @@ function IguanaAJAX(url, ajax_data) {
}); });
} }
function Iguana_activehandle(callback) { function Iguana_activehandle(callback) {
return new Promise((resolve) => { return new Promise((resolve) => {
var ajax_data = { 'agent': 'SuperNET', 'method': 'activehandle' }, var ajax_data = {
'agent': 'SuperNET',
'method': 'activehandle'
},
AjaxOutputData = IguanaAJAX('http://127.0.0.1:7778', ajax_data).done(function(data) { AjaxOutputData = IguanaAJAX('http://127.0.0.1:7778', ajax_data).done(function(data) {
//console.log(AjaxOutputData.responseText); //console.log(AjaxOutputData.responseText);
AjaxOutputData = JSON.parse(AjaxOutputData.responseText) AjaxOutputData = JSON.parse(AjaxOutputData.responseText)
@ -60,88 +62,107 @@ function StartIguana() {
} }
function GetAppConf() { // get iguana app conf function GetAppConf() { // get iguana app conf
var ajax_data = { 'herd': 'iguana' }; var ajax_data = { 'herd': 'iguana' },
data = false; data = false;
console.log(ajax_data); console.log(ajax_data);
$.ajax({ $.ajax({
async: false, async: false,
type: 'GET', type: 'GET',
url: 'http://127.0.0.1:17777/shepherd/appconf' url: 'http://127.0.0.1:17777/shepherd/appconf'
}).done(function(_data) { }).done(function(_data) {
console.log('== App Conf Data OutPut =='); console.log('== App Conf Data OutPut ==');
console.log(_data); console.log(_data);
data = _data; data = _data;
}).fail(function(xhr, textStatus, error) { }).fail(function(xhr, textStatus, error) {
// handle request failures // handle request failures
console.log(xhr.statusText); console.log(xhr.statusText);
if ( xhr.readyState == 0 ) { if ( xhr.readyState == 0 ) {
} }
console.log(textStatus); console.log(textStatus);
console.log(error); console.log(error);
}); });
return data; return data;
} }
function EDEX_DEXnotarychains() { function EDEX_DEXnotarychains() {
return new Promise((resolve) =>{ return new Promise((resolve) => {
var ajax_data = {"agent":"dpow","method":"notarychains"} var ajax_data = {
var AjaxOutputData = IguanaAJAX('http://127.0.0.1:7778',ajax_data).done(function(data) { 'agent': 'dpow',
//console.log(AjaxOutputData.responseText); 'method': 'notarychains'
AjaxOutputData = JSON.parse(AjaxOutputData.responseText) },
//console.log(AjaxOutputData); AjaxOutputData = IguanaAJAX('http://127.0.0.1:7778',ajax_data).done(function(data) {
resolve(AjaxOutputData); //console.log(AjaxOutputData.responseText);
}).fail(function(xhr, textStatus, error) { AjaxOutputData = JSON.parse(AjaxOutputData.responseText);
// handle request failures //console.log(AjaxOutputData);
console.log(xhr.statusText); resolve(AjaxOutputData);
if ( xhr.readyState == 0 ) { }).fail(function(xhr, textStatus, error) {
} // handle request failures
console.log(textStatus); console.log(xhr.statusText);
console.log(error); if ( xhr.readyState == 0 ) {
}) }
console.log(textStatus);
console.log(error);
}); });
});
} }
function EDEX_DEXgetinfoAll() { function EDEX_DEXgetinfoAll() {
var tmpIguanaRPCAuth = 'tmpIgRPCUser@'+sessionStorage.getItem('IguanaRPCAuth'); var tmpIguanaRPCAuth = 'tmpIgRPCUser@' + sessionStorage.getItem('IguanaRPCAuth'),
var ajax_data = {'userpass':tmpIguanaRPCAuth,"agent":"dpow","method":"notarychains"} ajax_data = {
var get_dex_notarychains = IguanaAJAX('http://127.0.0.1:7778',ajax_data).done(function(data) { 'userpass': tmpIguanaRPCAuth,
//console.log(get_dex_notarychains.responseText); 'agent': 'dpow',
get_dex_notarychains = JSON.parse(get_dex_notarychains.responseText) 'method': 'notarychains'
//console.log(get_dex_notarychains) },
tmp_index = 0,
get_dex_notarychains = IguanaAJAX('http://127.0.0.1:7778', ajax_data).done(function(data) {
//console.log(get_dex_notarychains.responseText);
get_dex_notarychains = JSON.parse(get_dex_notarychains.responseText);
//console.log(get_dex_notarychains)
$.each(get_dex_notarychains, function( coin_index, coin_value ) { $.each(get_dex_notarychains, function( coin_index, coin_value ) {
console.log(coin_index + ': ' + coin_value); console.log(coin_index + ': ' + coin_value);
var tmpIguanaRPCAuth = 'tmpIgRPCUser@'+sessionStorage.getItem('IguanaRPCAuth'); var tmpIguanaRPCAuth = 'tmpIgRPCUser@' + sessionStorage.getItem('IguanaRPCAuth'),
var ajax_data = {'userpass':tmpIguanaRPCAuth,"agent":"dex","method":"getinfo","symbol":coin_value} ajax_data = {
'userpass': tmpIguanaRPCAuth,
'agent': 'dex',
'method': 'getinfo',
'symbol': coin_value
},
basiliskMinNotariesConnected = 10;
console.log(ajax_data); console.log(ajax_data);
if (coin_value !== 'MESH') { if (coin_value !== 'MESH' || coin_value !== 'CEAL') {
var getinfo_each_chain = IguanaAJAX('http://127.0.0.1:7778',ajax_data).done(function(data) { var getinfo_each_chain = IguanaAJAX('http://127.0.0.1:7778', ajax_data).done(function(data) {
getinfo_each_chain = JSON.parse(getinfo_each_chain.responseText) getinfo_each_chain = JSON.parse(getinfo_each_chain.responseText);
console.log(getinfo_each_chain) console.log(getinfo_each_chain);
var tmp_index = parseInt(coin_index) + 1
$('#loading_sub_status_text').text('Connection status... ' + tmp_index + '/' + get_dex_notarychains.length + ': ' + coin_value) tmp_index = parseInt(coin_index) + 1;
if (getinfo_each_chain.error === 'less than required responses') { $('#loading_sub_status_text').text('Connection status... ' + tmp_index + '/' + get_dex_notarychains.length + ': ' + coin_value);
$('#loading_sub_status_output_text').text('Output: ' + getinfo_each_chain.error)
} else { if (getinfo_each_chain.error === 'less than required responses') {
$('#loading_sub_status_output_text').text('Output: Connected') $('#loading_sub_status_output_text').text('Output: ' + getinfo_each_chain.error);
} } else {
if ( tmp_index == 10 ) { $('#loading_sub_status_output_text').text('Output: Connected');
window.hide(); }
}
}).fail(function(xhr, textStatus, error) { if ( tmp_index == 10 ) {
// handle request failures console.log('min notaries connected');
console.log(xhr.statusText); const remote = require('electron').remote;
if ( xhr.readyState == 0 ) { var window = remote.getCurrentWindow();
} window.hide();
console.log(textStatus); }
console.log(error); }).fail(function(xhr, textStatus, error) {
}) // handle request failures
console.log(xhr.statusText);
if ( xhr.readyState == 0 ) {
}
console.log(textStatus);
console.log(error);
});
} }
});
}); });
}); }
}

41
main.js

@ -9,11 +9,11 @@ var express = require('express'),
const path = require('path'), 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'), var fs = 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; var iguanaAppPort = 17777;
@ -33,8 +33,8 @@ if (os.platform() === 'linux') {
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(90000);
@ -42,7 +42,7 @@ process.once('loaded', () => {
if (os.platform() === 'linux') { if (os.platform() === 'linux') {
process.setFdLimit(1000000); process.setFdLimit(1000000);
} }
}) });
// GUI APP settings and starting gui on address http://120.0.0.1:17777 // GUI APP settings and starting gui on address http://120.0.0.1:17777
var shepherd = require('./routes/shepherd'), var shepherd = require('./routes/shepherd'),
@ -52,16 +52,16 @@ 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(iguanaAppPort, function () {
console.log('guiapp listening on port ' + iguanaAppPort + '!') console.log('guiapp listening on port ' + iguanaAppPort + '!');
}) })
module.exports = guiapp; module.exports = guiapp;
@ -96,10 +96,10 @@ if (os.platform() === 'win32') {
*/ */
if (os.platform() === 'linux') { if (os.platform() === 'linux') {
var iguanaIcon = path.join(__dirname, '/assets/icons/iguana_app_icon_png/128x128.png') var iguanaIcon = path.join(__dirname, '/assets/icons/iguana_app_icon_png/128x128.png');
} }
if (os.platform() === 'win32') { if (os.platform() === 'win32') {
var iguanaIcon = path.join(__dirname, '/assets/icons/iguana_app_icon.ico') var iguanaIcon = path.join(__dirname, '/assets/icons/iguana_app_icon.ico');
} }
//console.log(iguanaDir); //console.log(iguanaDir);
@ -123,8 +123,8 @@ fs.copy(iguanaConfsDirSrc, iguanaConfsDir, function (err) {
}) })
*/ */
let mainWindow let mainWindow;
let loadingWindow let loadingWindow;
function createLoadingWindow() { function createLoadingWindow() {
mainWindow = null; mainWindow = null;
@ -223,7 +223,8 @@ 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) throw err; if (err)
throw err;
}); });
var result = 'Killing Pm2: done'; var result = 'Killing Pm2: done';
@ -285,26 +286,26 @@ app.on('window-all-closed', function () {
app.on('before-quit', function (event) { app.on('before-quit', function (event) {
if (mainWindow === null && loadingWindow != null) { //mainWindow not intitialised and loadingWindow not dereferenced if (mainWindow === null && loadingWindow != null) { //mainWindow not intitialised and loadingWindow not dereferenced
//loading window is still open //loading window is still open
console.log("before-quit prevented"); console.log('before-quit prevented');
event.preventDefault(); event.preventDefault();
} }
}) });
//Emitted when all windows have been closed and the application will quit. //Emitted when all windows have been closed and the application will quit.
//Calling event.preventDefault() will prevent the default behaviour, which is terminating the application. //Calling event.preventDefault() will prevent the default behaviour, which is terminating the application.
app.on('will-quit', function (event) { app.on('will-quit', function (event) {
if (mainWindow === null && loadingWindow != null) { if (mainWindow === null && loadingWindow != null) {
//loading window is still open //loading window is still open
console.log("will-quit while loading window active"); console.log('will-quit while loading window active');
event.preventDefault(); event.preventDefault();
} }
}) });
//Emitted when the application is quitting. //Emitted when the application is quitting.
//Calling event.preventDefault() will prevent the default behaviour, which is terminating the application. //Calling event.preventDefault() will prevent the default behaviour, which is terminating the application.
app.on('quit', function (event) { app.on('quit', function (event) {
if (mainWindow === null && loadingWindow != null) { if (mainWindow === null && loadingWindow != null) {
console.log("quit while loading window active"); console.log('quit while loading window active');
event.preventDefault(); event.preventDefault();
} }
}) })
@ -313,4 +314,4 @@ app.on('activate', function () {
if (mainWindow === null) { if (mainWindow === null) {
//createWindow('open'); //createWindow('open');
} }
}) });

68
routes/shepherd.js

@ -46,10 +46,13 @@ if (os.platform() === 'linux') {
} }
if (os.platform() === 'win32') { if (os.platform() === 'win32') {
var iguanaBin = path.join(__dirname, '../assets/bin/win64/iguana.exe'); iguanaBin = path.normalize(iguanaBin), var iguanaBin = path.join(__dirname, '../assets/bin/win64/iguana.exe');
iguanaDir = process.env.APPDATA + '/iguana'; iguanaDir = path.normalize(iguanaDir), iguanaBin = path.normalize(iguanaBin);
iguanaConfsDir = process.env.APPDATA + '/iguana/confs'; iguanaConfsDir = path.normalize(iguanaConfsDir), var iguanaDir = process.env.APPDATA + '/iguana';
iguanaIcon = path.join(__dirname, '/assets/icons/iguana_app_icon.ico'), iguanaDir = path.normalize(iguanaDir);
var iguanaConfsDir = process.env.APPDATA + '/iguana/confs';
iguanaConfsDir = path.normalize(iguanaConfsDir);
var iguanaIcon = path.join(__dirname, '/assets/icons/iguana_app_icon.ico'),
iguanaConfsDirSrc = path.normalize(iguanaConfsDirSrc); iguanaConfsDirSrc = path.normalize(iguanaConfsDirSrc);
} }
@ -192,20 +195,20 @@ function herder(flock, data) {
}); });
pm2.connect(true,function(err) { //start up pm2 god pm2.connect(true,function(err) { //start up pm2 god
if (err) { if (err) {
console.error(err); console.error(err);
process.exit(2); process.exit(2);
} }
pm2.start({ pm2.start({
script: iguanaBin, // path to binary script: iguanaBin, // path to binary
name: 'IGUANA', name: 'IGUANA',
exec_mode : 'fork', exec_mode : 'fork',
cwd: iguanaDir, //set correct iguana directory cwd: iguanaDir, //set correct iguana directory
}, function(err, apps) { }, function(err, apps) {
pm2.disconnect(); // Disconnect from PM2 pm2.disconnect(); // Disconnect from PM2
if (err) if (err)
throw err throw err
}); });
}); });
} }
@ -215,22 +218,22 @@ function herder(flock, data) {
console.log('selected data: ' + data); console.log('selected data: ' + data);
pm2.connect(true, function(err) { // start up pm2 god pm2.connect(true, function(err) { // start up pm2 god
if (err) { if (err) {
console.error(err); console.error(err);
process.exit(2); process.exit(2);
} }
pm2.start({ pm2.start({
script: komododBin, // path to binary script: komododBin, // path to binary
name: data.ac_name, // REVS, USD, EUR etc. name: data.ac_name, // REVS, USD, EUR etc.
exec_mode : 'fork', exec_mode : 'fork',
cwd: komodoDir, cwd: komodoDir,
args: data.ac_options, args: data.ac_options,
//args: ["-server", "-ac_name=USD", "-addnode=78.47.196.146"], //separate the params with commas //args: ["-server", "-ac_name=USD", "-addnode=78.47.196.146"], //separate the params with commas
}, function(err, apps) { }, function(err, apps) {
pm2.disconnect(); // Disconnect from PM2 pm2.disconnect(); // Disconnect from PM2
if (err) if (err)
throw err; throw err;
}); });
}); });
} }
@ -483,7 +486,6 @@ function setConf(flock) {
.then(MakeConfReadOnly); .then(MakeConfReadOnly);
} }
function getConf(flock) { function getConf(flock) {
console.log(flock); console.log(flock);

Loading…
Cancel
Save