From 2f9c312c7cbad2c95034874e3a613dae02a5e19f Mon Sep 17 00:00:00 2001 From: Petr Balashov Date: Wed, 15 Feb 2017 10:53:07 +0100 Subject: [PATCH] fixed window.hide when min notaries are connected --- gui/index.html | 4 ++ gui/init.js | 2 - gui/loading.js | 151 ++++++++++++++++++++++++++------------------- main.js | 41 ++++++------ routes/shepherd.js | 68 ++++++++++---------- 5 files changed, 146 insertions(+), 120 deletions(-) diff --git a/gui/index.html b/gui/index.html index 9630b28..4d1d9ab 100644 --- a/gui/index.html +++ b/gui/index.html @@ -10,6 +10,10 @@ + >
diff --git a/gui/init.js b/gui/init.js index 7a2571a..5c56b0a 100644 --- a/gui/init.js +++ b/gui/init.js @@ -5,8 +5,6 @@ $(document).ready(function() { }); var appConf = GetAppConf(); - const remote = require('electron').remote; - var window = remote.getCurrentWindow(); $('#loading_status_text').text('Starting Iguana daemon...'); diff --git a/gui/loading.js b/gui/loading.js index e8b5b48..fc80b82 100644 --- a/gui/loading.js +++ b/gui/loading.js @@ -11,10 +11,12 @@ function IguanaAJAX(url, ajax_data) { }); } - function Iguana_activehandle(callback) { 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) { //console.log(AjaxOutputData.responseText); AjaxOutputData = JSON.parse(AjaxOutputData.responseText) @@ -60,88 +62,107 @@ function StartIguana() { } function GetAppConf() { // get iguana app conf - var ajax_data = { 'herd': 'iguana' }; + var ajax_data = { 'herd': 'iguana' }, data = false; console.log(ajax_data); $.ajax({ - async: false, - type: 'GET', - url: 'http://127.0.0.1:17777/shepherd/appconf' + async: false, + type: 'GET', + url: 'http://127.0.0.1:17777/shepherd/appconf' }).done(function(_data) { - console.log('== App Conf Data OutPut =='); - console.log(_data); - data = _data; + console.log('== App Conf Data OutPut =='); + console.log(_data); + data = _data; }).fail(function(xhr, textStatus, error) { - // handle request failures - console.log(xhr.statusText); - if ( xhr.readyState == 0 ) { - } - console.log(textStatus); - console.log(error); + // handle request failures + console.log(xhr.statusText); + if ( xhr.readyState == 0 ) { + } + console.log(textStatus); + console.log(error); }); return data; } function EDEX_DEXnotarychains() { - return new Promise((resolve) =>{ - var ajax_data = {"agent":"dpow","method":"notarychains"} - var AjaxOutputData = IguanaAJAX('http://127.0.0.1:7778',ajax_data).done(function(data) { - //console.log(AjaxOutputData.responseText); - AjaxOutputData = JSON.parse(AjaxOutputData.responseText) - //console.log(AjaxOutputData); - resolve(AjaxOutputData); - }).fail(function(xhr, textStatus, error) { - // handle request failures - console.log(xhr.statusText); - if ( xhr.readyState == 0 ) { - } - console.log(textStatus); - console.log(error); - }) + return new Promise((resolve) => { + var ajax_data = { + 'agent': 'dpow', + 'method': 'notarychains' + }, + AjaxOutputData = IguanaAJAX('http://127.0.0.1:7778',ajax_data).done(function(data) { + //console.log(AjaxOutputData.responseText); + AjaxOutputData = JSON.parse(AjaxOutputData.responseText); + //console.log(AjaxOutputData); + resolve(AjaxOutputData); + }).fail(function(xhr, textStatus, error) { + // handle request failures + console.log(xhr.statusText); + if ( xhr.readyState == 0 ) { + } + console.log(textStatus); + console.log(error); }); + }); } - function EDEX_DEXgetinfoAll() { - var tmpIguanaRPCAuth = 'tmpIgRPCUser@'+sessionStorage.getItem('IguanaRPCAuth'); - var ajax_data = {'userpass':tmpIguanaRPCAuth,"agent":"dpow","method":"notarychains"} - var 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) + var tmpIguanaRPCAuth = 'tmpIgRPCUser@' + sessionStorage.getItem('IguanaRPCAuth'), + ajax_data = { + 'userpass': tmpIguanaRPCAuth, + 'agent': 'dpow', + 'method': '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); - var tmpIguanaRPCAuth = 'tmpIgRPCUser@'+sessionStorage.getItem('IguanaRPCAuth'); - var ajax_data = {'userpass':tmpIguanaRPCAuth,"agent":"dex","method":"getinfo","symbol":coin_value} + var tmpIguanaRPCAuth = 'tmpIgRPCUser@' + sessionStorage.getItem('IguanaRPCAuth'), + ajax_data = { + 'userpass': tmpIguanaRPCAuth, + 'agent': 'dex', + 'method': 'getinfo', + 'symbol': coin_value + }, + basiliskMinNotariesConnected = 10; + console.log(ajax_data); - if (coin_value !== 'MESH') { - 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) - 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) - if (getinfo_each_chain.error === 'less than required responses') { - $('#loading_sub_status_output_text').text('Output: ' + getinfo_each_chain.error) - } else { - $('#loading_sub_status_output_text').text('Output: Connected') - } - if ( tmp_index == 10 ) { - window.hide(); - } - }).fail(function(xhr, textStatus, error) { - // handle request failures - console.log(xhr.statusText); - if ( xhr.readyState == 0 ) { - } - console.log(textStatus); - console.log(error); - }) + if (coin_value !== 'MESH' || coin_value !== 'CEAL') { + 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); + console.log(getinfo_each_chain); + + tmp_index = parseInt(coin_index) + 1; + $('#loading_sub_status_text').text('Connection status... ' + tmp_index + '/' + get_dex_notarychains.length + ': ' + coin_value); + + if (getinfo_each_chain.error === 'less than required responses') { + $('#loading_sub_status_output_text').text('Output: ' + getinfo_each_chain.error); + } else { + $('#loading_sub_status_output_text').text('Output: Connected'); + } + + if ( tmp_index == 10 ) { + console.log('min notaries connected'); + const remote = require('electron').remote; + var window = remote.getCurrentWindow(); + window.hide(); + } + }).fail(function(xhr, textStatus, error) { + // handle request failures + console.log(xhr.statusText); + if ( xhr.readyState == 0 ) { + } + console.log(textStatus); + console.log(error); + }); } + }); }); - }); - -} +} \ No newline at end of file diff --git a/main.js b/main.js index 45d98f1..ac7c897 100644 --- a/main.js +++ b/main.js @@ -9,11 +9,11 @@ var express = require('express'), const path = require('path'), url = require('url'), os = require('os'), - spawn = require('child_process').spawn + spawn = require('child_process').spawn, exec = require('child_process').exec; var fs = require('fs'), fs = require('fs-extra'), - mkdirp = require('mkdirp') + mkdirp = require('mkdirp'), pm2 = require('pm2'); var iguanaAppPort = 17777; @@ -33,8 +33,8 @@ if (os.platform() === 'linux') { const _setImmediate = setImmediate, _clearImmediate = clearImmediate; process.once('loaded', () => { - global.setImmediate = _setImmediate - global.clearImmediate = _clearImmediate + global.setImmediate = _setImmediate; + global.clearImmediate = _clearImmediate; if (os.platform() === 'darwin') { process.setFdLimit(90000); @@ -42,7 +42,7 @@ process.once('loaded', () => { if (os.platform() === 'linux') { process.setFdLimit(1000000); } -}) +}); // GUI APP settings and starting gui on address http://120.0.0.1:17777 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.get('/', function (req, res) { - res.send('Iguana app server') + res.send('Iguana app server'); }) -var guipath = path.join(__dirname, '/gui') -guiapp.use('/gui', express.static(guipath)) +var guipath = path.join(__dirname, '/gui'); +guiapp.use('/gui', express.static(guipath)); guiapp.use('/shepherd', shepherd); var rungui = guiapp.listen(iguanaAppPort, function () { - console.log('guiapp listening on port ' + iguanaAppPort + '!') + console.log('guiapp listening on port ' + iguanaAppPort + '!'); }) module.exports = guiapp; @@ -96,10 +96,10 @@ if (os.platform() === 'win32') { */ 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') { - 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); @@ -123,8 +123,8 @@ fs.copy(iguanaConfsDirSrc, iguanaConfsDir, function (err) { }) */ -let mainWindow -let loadingWindow +let mainWindow; +let loadingWindow; function createLoadingWindow() { mainWindow = null; @@ -223,7 +223,8 @@ function createWindow (status) { pm2.killDaemon(function(err) { pm2.disconnect(); console.log('killed to pm2...'); - if (err) throw err; + if (err) + throw err; }); var result = 'Killing Pm2: done'; @@ -285,26 +286,26 @@ app.on('window-all-closed', function () { app.on('before-quit', function (event) { if (mainWindow === null && loadingWindow != null) { //mainWindow not intitialised and loadingWindow not dereferenced //loading window is still open - console.log("before-quit prevented"); + console.log('before-quit prevented'); event.preventDefault(); } -}) +}); //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. app.on('will-quit', function (event) { if (mainWindow === null && loadingWindow != null) { //loading window is still open - console.log("will-quit while loading window active"); + console.log('will-quit while loading window active'); event.preventDefault(); } -}) +}); //Emitted when the application is quitting. //Calling event.preventDefault() will prevent the default behaviour, which is terminating the application. app.on('quit', function (event) { if (mainWindow === null && loadingWindow != null) { - console.log("quit while loading window active"); + console.log('quit while loading window active'); event.preventDefault(); } }) @@ -313,4 +314,4 @@ app.on('activate', function () { if (mainWindow === null) { //createWindow('open'); } -}) +}); \ No newline at end of file diff --git a/routes/shepherd.js b/routes/shepherd.js index abd5aa2..87474e0 100644 --- a/routes/shepherd.js +++ b/routes/shepherd.js @@ -46,10 +46,13 @@ if (os.platform() === 'linux') { } if (os.platform() === 'win32') { - var iguanaBin = path.join(__dirname, '../assets/bin/win64/iguana.exe'); iguanaBin = path.normalize(iguanaBin), - iguanaDir = process.env.APPDATA + '/iguana'; iguanaDir = path.normalize(iguanaDir), - iguanaConfsDir = process.env.APPDATA + '/iguana/confs'; iguanaConfsDir = path.normalize(iguanaConfsDir), - iguanaIcon = path.join(__dirname, '/assets/icons/iguana_app_icon.ico'), + var iguanaBin = path.join(__dirname, '../assets/bin/win64/iguana.exe'); + iguanaBin = path.normalize(iguanaBin); + var iguanaDir = process.env.APPDATA + '/iguana'; + 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); } @@ -192,20 +195,20 @@ function herder(flock, data) { }); pm2.connect(true,function(err) { //start up pm2 god - if (err) { - console.error(err); - process.exit(2); - } + if (err) { + console.error(err); + process.exit(2); + } - pm2.start({ - script: iguanaBin, // path to binary - name: 'IGUANA', - exec_mode : 'fork', - cwd: iguanaDir, //set correct iguana directory - }, function(err, apps) { - pm2.disconnect(); // Disconnect from PM2 - if (err) - throw err + pm2.start({ + script: iguanaBin, // path to binary + name: 'IGUANA', + exec_mode : 'fork', + cwd: iguanaDir, //set correct iguana directory + }, function(err, apps) { + pm2.disconnect(); // Disconnect from PM2 + if (err) + throw err }); }); } @@ -215,22 +218,22 @@ function herder(flock, data) { console.log('selected data: ' + data); pm2.connect(true, function(err) { // start up pm2 god - if (err) { - console.error(err); - process.exit(2); - } + if (err) { + console.error(err); + process.exit(2); + } - pm2.start({ - script: komododBin, // path to binary - name: data.ac_name, // REVS, USD, EUR etc. - exec_mode : 'fork', - cwd: komodoDir, - args: data.ac_options, - //args: ["-server", "-ac_name=USD", "-addnode=78.47.196.146"], //separate the params with commas - }, function(err, apps) { - pm2.disconnect(); // Disconnect from PM2 - if (err) - throw err; + pm2.start({ + script: komododBin, // path to binary + name: data.ac_name, // REVS, USD, EUR etc. + exec_mode : 'fork', + cwd: komodoDir, + args: data.ac_options, + //args: ["-server", "-ac_name=USD", "-addnode=78.47.196.146"], //separate the params with commas + }, function(err, apps) { + pm2.disconnect(); // Disconnect from PM2 + if (err) + throw err; }); }); } @@ -483,7 +486,6 @@ function setConf(flock) { .then(MakeConfReadOnly); } - function getConf(flock) { console.log(flock);