Browse Source

Merge pull request #160 from SuperNETorg/master

master update
pkg_automation_electrum
ca333 7 years ago
committed by GitHub
parent
commit
441c4684e6
  1. 23
      buildscripts/AgamaApp-osx.xml
  2. 23
      buildscripts/AgamaApp-windows.xml
  3. 2
      gui/agama-instance-error.html
  4. 25
      gui/app-closing.html
  5. 167
      main.js
  6. 8
      routes/shepherd.js

23
buildscripts/AgamaApp-osx.xml

@ -116,6 +116,28 @@
</compareValues>
</ruleList>
</deleteFile>
<deleteFile>
<explanation>Deleting iguana config json</explanation>
<path>${user_home_directory}/Library/Application Support/Iguana/config.json</path>
<progressText>Deleting iguana config</progressText>
<ruleList>
<compareValues>
<logic>equals</logic>
<value1>${previous_installation_exists}</value1>
<value2>1</value2>
</compareValues>
<compareValues>
<logic>equals</logic>
<value1>${installation_type}</value1>
<value2>uninstall</value2>
</compareValues>
<compareValues>
<logic>equals</logic>
<value1>${delete_config_data}</value1>
<value2>1</value2>
</compareValues>
</ruleList>
</deleteFile>
<deleteFile>
<explanation>Deleting ZcashParams</explanation>
<path>${user_home_directory}/Library/Application Support/ZcashParams/</path>
@ -320,4 +342,3 @@
</choiceParameterGroup>
</parameterList>
</project>

23
buildscripts/AgamaApp-windows.xml

@ -214,6 +214,28 @@
</compareValues>
</ruleList>
</deleteFile>
<deleteFile>
<explanation>Deleting iguana config json</explanation>
<path>${windows_folder_appdata}/Iguana/config.json</path>
<progressText>Deleting iguana config</progressText>
<ruleList>
<compareValues>
<logic>equals</logic>
<value1>${previous_installation_exists}</value1>
<value2>1</value2>
</compareValues>
<compareValues>
<logic>equals</logic>
<value1>${installation_type}</value1>
<value2>uninstall</value2>
</compareValues>
<compareValues>
<logic>equals</logic>
<value1>${delete_config_data}</value1>
<value2>1</value2>
</compareValues>
</ruleList>
</deleteFile>
<deleteFile>
<explanation>Deleting zcash params</explanation>
<path>${windows_folder_appdata}/ZcashParams/</path>
@ -512,4 +534,3 @@
</platformOptions>
</platformOptionsList>
</project>

2
gui/agama-instance-error.html

@ -18,7 +18,7 @@
<div id="agamaMode">
<img src="EasyDEX-GUI/assets/mainWindow/img/agama-icon.svg" class="agama-logo" alt="Agama Wallet" width="80" height="100" />
<div id="agamaModeStatus">Another Agama instance is already running!</div>
<div>Please close all other instaces and restart the app.</div>
<div>Please close all other instances and restart the app.</div>
<br />
<button onClick="quitApp()" class="btn btn-primary btn-close-app">Quit</button>
</div>

25
gui/app-closing.html

@ -0,0 +1,25 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<link rel="stylesheet" href="EasyDEX-GUI/assets/global/css/bootstrap.min.css">
<link rel="stylesheet" href="EasyDEX-GUI/assets/mainWindow/css/jRoll.min.css">
<link rel="stylesheet" href="EasyDEX-GUI/assets/mainWindow/css/loading.css">
<script type="text/javascript" src="EasyDEX-GUI/assets/mainWindow/js/module-hack.js"></script>
<script type="text/javascript" src="EasyDEX-GUI/assets/global/vendor/jquery/jquery.min.js"></script>
<script type="text/javascript" src="EasyDEX-GUI/assets/scripts/config.js"></script>
<script type="text/javascript" src="EasyDEX-GUI/assets/mainWindow/js/bluebird.min.js"></script>
<script type="text/javascript" src="EasyDEX-GUI/assets/mainWindow/js/loading.js"></script>
<script type="text/javascript" src="EasyDEX-GUI/assets/mainWindow/js/jRoll.min.js"></script>
<script>if (window.module) module = window.module;</script>
</head>
<body class="agamaMode">
<div class="text-center">
<div id="agamaMode" class="app-closing">
<img src="EasyDEX-GUI/assets/mainWindow/img/agama-icon.svg" class="agama-logo" alt="Agama Wallet" width="80" height="100" />
<div id="agamaModeStatus">App is closing. Please wait...</div>
</div>
</div>
<!--script type="text/javascript" src="EasyDEX-GUI/assets/mainWindow/js/init.js"></script-->
</body>
</html>

167
main.js

@ -164,50 +164,13 @@ guiapp.use('/shepherd', shepherd);
const server = require('http').createServer(guiapp);
const io = require('socket.io').listen(server);
let willQuitApp = false;
// check if agama is already running
portscanner.checkPortStatus(appConfig.agamaPort, '127.0.0.1', function(error, status) {
// Status is 'open' if currently in use or 'closed' if available
if (status === 'closed') {
server.listen(appConfig.agamaPort, function() {
console.log(`guiapp and sockets.io are listening on port ${appConfig.agamaPort}`);
shepherd.writeLog(`guiapp and sockets.io are listening on port ${appConfig.agamaPort}`);
});
} else {
willQuitApp = true;
server.listen(appConfig.agamaPort + 1, function() {
console.log(`guiapp and sockets.io are listening on port ${appConfig.agamaPort + 1}`);
shepherd.writeLog(`guiapp and sockets.io are listening on port ${appConfig.agamaPort + 1}`);
});
loadingWindow.loadURL(`http://${appConfig.host}:${appConfig.agamaPort + 1}/gui/agama-instance-error.html`);
console.log('another agama app is already running');
}
});
io.set('origins', appConfig.dev ? 'http://127.0.0.1:3000' : `http://127.0.0.1:${appConfig.agamaPort}`); // set origin
io.on('connection', function(client) {
console.log('EDEX GUI is connected...');
shepherd.writeLog('EDEX GUI is connected...');
client.on('event', function(data) { // listen for client requests
console.log(data);
});
client.on('disconnect', function(data) {
console.log('EDEX GUI is disconnected');
});
client.on('join', function(data) {
console.log(data);
client.emit('messages', 'Sockets server is listening');
});
});
shepherd.setIO(io); // pass sockets object to shepherd router
shepherd.setVar('appBasicInfo', appBasicInfo);
shepherd.setVar('appSessionHash', appSessionHash);
let mainWindow;
let loadingWindow;
let appCloseWindow;
let closeAppAfterLoading = false;
module.exports = guiapp;
var iguanaIcon;
let iguanaIcon;
if (os.platform() === 'linux') {
iguanaIcon = path.join(__dirname, '/assets/icons/agama_icons/128x128.png');
@ -216,21 +179,60 @@ if (os.platform() === 'win32') {
iguanaIcon = path.join(__dirname, '/assets/icons/agama_icons/agama_app_icon.ico');
}
let mainWindow;
let loadingWindow;
let closeAppAfterLoading = false;
function createLoadingWindow() {
mainWindow = null;
// initialise window
loadingWindow = new BrowserWindow({
width: 500,
height: 300,
frame: false,
icon: iguanaIcon,
show: false,
});
try {
loadingWindow = new BrowserWindow({
width: 500,
height: 300,
frame: false,
icon: iguanaIcon,
show: false,
});
} catch(e) {}
// check if agama is already running
portscanner.checkPortStatus(appConfig.agamaPort, '127.0.0.1', function(error, status) {
// Status is 'open' if currently in use or 'closed' if available
if (status === 'closed') {
server.listen(appConfig.agamaPort, function() {
console.log(`guiapp and sockets.io are listening on port ${appConfig.agamaPort}`);
shepherd.writeLog(`guiapp and sockets.io are listening on port ${appConfig.agamaPort}`);
// start sockets.io
io.set('origins', appConfig.dev ? 'http://127.0.0.1:3000' : `http://127.0.0.1:${appConfig.agamaPort}`); // set origin
io.on('connection', function(client) {
console.log('EDEX GUI is connected...');
shepherd.writeLog('EDEX GUI is connected...');
client.on('event', function(data) { // listen for client requests
console.log(data);
});
client.on('disconnect', function(data) {
console.log('EDEX GUI is disconnected');
});
client.on('join', function(data) {
console.log(data);
client.emit('messages', 'Sockets server is listening');
});
});
});
} else {
willQuitApp = true;
server.listen(appConfig.agamaPort + 1, function() {
console.log(`guiapp and sockets.io are listening on port ${appConfig.agamaPort + 1}`);
shepherd.writeLog(`guiapp and sockets.io are listening on port ${appConfig.agamaPort + 1}`);
});
loadingWindow.loadURL(`http://${appConfig.host}:${appConfig.agamaPort + 1}/gui/agama-instance-error.html`);
console.log('another agama app is already running');
}
})
shepherd.setIO(io); // pass sockets object to shepherd router
shepherd.setVar('appBasicInfo', appBasicInfo);
shepherd.setVar('appSessionHash', appSessionHash);
loadingWindow.createWindow = createWindow; // expose createWindow to front-end scripts
loadingWindow.appConfig = appConfig;
@ -276,7 +278,26 @@ function forseCloseApp() {
app.on('ready', createLoadingWindow);
function createWindow (status) {
function createAppCloseWindow() {
// initialise window
appCloseWindow = new BrowserWindow({ // dirty hack to prevent main window flash on quit
width: 500,
height: 300,
frame: false,
icon: iguanaIcon,
show: false,
});
appCloseWindow.loadURL(`http://${appConfig.host}:${appConfig.agamaPort}/gui/app-closing.html`);
appCloseWindow.webContents.on('did-finish-load', function() {
setTimeout(function() {
appCloseWindow.show();
}, 40);
});
}
function createWindow(status) {
if (status === 'open') {
require(path.join(__dirname, 'private/mainmenu'));
@ -415,6 +436,13 @@ function createWindow (status) {
});
}
const HideAppClosingWindow = function() {
return new Promise(function(resolve, reject) {
appCloseWindow = null;
resolve(true);
});
}
const QuitApp = function() {
return new Promise(function(resolve, reject) {
KillPm2(); // required for normal app quit in iguana-less mode
@ -425,16 +453,33 @@ function createWindow (status) {
});
}
ConnectToPm2()
.then(function(result) {
return KillPm2();
})
.then(HideMainWindow)
.then(QuitApp);
const closeApp = function() {
ConnectToPm2()
.then(function(result) {
return KillPm2();
})
.then(HideMainWindow)
.then(HideAppClosingWindow)
.then(QuitApp);
}
let _appClosingInterval;
if (!Object.keys(shepherd.coindInstanceRegistry).length) {
closeApp();
} else {
shepherd.quitKomodod(1000);
_appClosingInterval = setInterval(function() {
if (!Object.keys(shepherd.coindInstanceRegistry).length) {
closeApp();
}
}, 1000);
createAppCloseWindow();
}
}
// if window closed we kill iguana proc
mainWindow.on('closed', function () {
mainWindow.on('closed', function() {
pm2Exit();
});
}

8
routes/shepherd.js

@ -79,6 +79,7 @@ if (os.platform() === 'win32') {
komodoDir = `${process.env.APPDATA}/Komodo`,
komodoDir = path.normalize(komodoDir);
zcashDir = `${process.env.APPDATA}/ZcashParams`;
zcashDir = path.normalize(zcashDir);
}
shepherd.appConfig = {
@ -109,6 +110,8 @@ shepherd.appConfig = {
shepherd.defaultAppConfig = Object.assign({}, shepherd.appConfig);
shepherd.coindInstanceRegistry = coindInstanceRegistry;
shepherd.zcashParamsExist = function() {
if (fs.existsSync(zcashDir) &&
fs.existsSync(`${zcashDir}/sprout-proving.key`) &&
@ -663,7 +666,7 @@ shepherd.post('/coinslist', function(req, res, next) {
});
// TODO: check if komodod is running
shepherd.quitKomodod = function() {
shepherd.quitKomodod = function(timeout = 100) {
// if komodod is under heavy load it may not respond to cli stop the first time
// exit komodod gracefully
let coindExitInterval = {};
@ -681,6 +684,7 @@ shepherd.quitKomodod = function() {
stderr.indexOf('EOF reached') > -1 ||
stdout.indexOf('connect to server: unknown (code -1)') > -1 ||
stderr.indexOf('connect to server: unknown (code -1)') > -1) {
delete coindInstanceRegistry[key];
clearInterval(coindExitInterval[key]);
}
@ -688,7 +692,7 @@ shepherd.quitKomodod = function() {
console.log(`exec error: ${error}`);
}
});
}, 100);
}, timeout);
}
}

Loading…
Cancel
Save