Browse Source

init settings window

all-modes
pbca26 7 years ago
parent
commit
91e2168dfc
  1. 64
      gui/app-settings.html
  2. 88
      main.js
  3. 27
      routes/appConfig.js
  4. 68
      routes/shepherd.js

64
gui/app-settings.html

@ -0,0 +1,64 @@
<!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 agama-app-settings-window">
<div class="text-center">
<div
id="agamaMode"
class="app-settings">
<div
class="btn-close"
onClick="closeSettingsWindow()">
<img src="EasyDEX-GUI/assets/mainWindow/img/fa-close.png">
</div>
<img
src="EasyDEX-GUI/assets/mainWindow/img/agama-icon.svg"
class="agama-logo"
alt="Agama Wallet"
width="80"
height="100" />
<div id="agamaModeStatus">App configuration (selected options only)</div>
<div
id="agamaConfigBlock"
class="agama-config-block"></div>
<div class="settings-buttons-block">
<button
onClick="handleSaveSettings()"
class="btn btn-primary">Save</button>
<button
onClick="initSettingsForm()"
class="btn btn-primary">Reset changes</button>
<button
onClick="setDefaultAppSettings()"
class="btn btn-primary">Reset all settings</button>
</div>
<div
id="toast-container"
class="single-toast toast-bottom-right hide">
<div class="toast toast-success">
<button
class="toast-close-button"
onClick="hideToastImmediate()">×</button>
<div class="toast-title">Settings notification</div>
<div class="toast-message"></div>
</div>
</div>
<button onClick="reloadSettingsWindow()" class="btn btn-primary" style="margin-top: 20px">Reload</button>
</div>
<div id="debugOut"></div>
<script>initSettingsForm()</script>
</div>
</body>
</html>

88
main.js

@ -71,6 +71,11 @@ shepherd.writeLog(`os_release: ${os.release()}`);
shepherd.writeLog(`os_type: ${os.type()}`);
var appConfig = shepherd.loadLocalConfig(); // load app config
appConfig['daemonTest'] = false; // shadow setting
let __defaultAppSettings = require('./routes/appConfig.js').config;
__defaultAppSettings['daemonTest'] = false; // shadow setting
const _defaultAppSettings = __defaultAppSettings;
shepherd.writeLog(`app started in ${(appConfig.dev ? 'dev mode' : ' user mode')}`);
@ -131,7 +136,9 @@ let willQuitApp = false;
let mainWindow;
let loadingWindow;
let appCloseWindow;
let appSettingsWindow;
let closeAppAfterLoading = false;
let forceQuitApp = false;
const _zcashParamsExist = shepherd.zcashParamsExist();
module.exports = guiapp;
@ -151,7 +158,7 @@ function createLoadingWindow() {
try {
loadingWindow = new BrowserWindow({
width: 500,
height: 300,
height: 335,
frame: false,
icon: iguanaIcon,
show: false,
@ -193,7 +200,7 @@ function createLoadingWindow() {
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);
@ -202,6 +209,7 @@ function createLoadingWindow() {
loadingWindow.createWindow = createWindow; // expose createWindow to front-end scripts
loadingWindow.appConfig = appConfig;
loadingWindow.forseCloseApp = forseCloseApp;
loadingWindow.createAppSettingsWindow = createAppSettingsWindow;
// load our index.html (i.e. easyDEX GUI)
loadingWindow.loadURL(`http://${appConfig.host}:${appConfig.agamaPort}/gui/`);
@ -223,24 +231,34 @@ function createLoadingWindow() {
});
loadingWindow.on('close', (e) => {
if (willQuitApp) {
/* the user tried to quit the app */
loadingWindow = null;
} else {
/* the user only tried to close the window */
closeAppAfterLoading = true;
e.preventDefault();
}
if (!forseCloseApp) {
if (willQuitApp) {
/* the user tried to quit the app */
loadingWindow = null;
} else {
/* the user only tried to close the window */
closeAppAfterLoading = true;
e.preventDefault();
}
}
});
}
// close app
function forseCloseApp() {
loadingWindow = null;
mainWindow = null;
forceQuitApp = true;
app.quit();
}
function setDefaultAppSettings() {
shepherd.saveLocalAppConf(_defaultAppSettings);
}
function updateAppSettings(_settings) {
shepherd.saveLocalAppConf(_settings);
appConfig = _settings;
}
app.on('ready', createLoadingWindow);
function createAppCloseWindow() {
@ -262,7 +280,47 @@ function createAppCloseWindow() {
});
}
function reloadSettingsWindow() {
appSettingsWindow.loadURL(`http://${appConfig.host}:${appConfig.agamaPort}/gui/app-settings.html`);
}
function createAppSettingsWindow() {
// initialise window
appSettingsWindow = new BrowserWindow({ // dirty hack to prevent main window flash on quit
width: 750,
height: 800,
frame: false,
icon: iguanaIcon,
show: false,
});
appSettingsWindow.appConfig = appConfig;
appSettingsWindow.appConfigSchema = shepherd.appConfigSchema;
appSettingsWindow.defaultAppSettings = _defaultAppSettings;
appSettingsWindow.destroyAppSettingsWindow = destroyAppSettingsWindow;
appSettingsWindow.reloadSettingsWindow = reloadSettingsWindow;
appSettingsWindow.testLocation = shepherd.testLocation;
appSettingsWindow.setDefaultAppSettings = setDefaultAppSettings;
appSettingsWindow.updateAppSettings = updateAppSettings;
appSettingsWindow.loadURL(`http://${appConfig.host}:${appConfig.agamaPort}/gui/app-settings.html`);
appSettingsWindow.webContents.on('did-finish-load', function() {
setTimeout(function() {
appSettingsWindow.show();
}, 40);
});
}
function destroyAppSettingsWindow() {
appSettingsWindow.hide();
appSettingsWindow = null;
}
function createWindow(status) {
if (appSettingsWindow) {
destroyAppSettingsWindow();
}
if (status === 'open') {
require(path.join(__dirname, 'private/mainmenu'));
@ -468,7 +526,7 @@ app.on('window-all-closed', function() {
// Calling event.preventDefault() will prevent the default behaviour, which is terminating the application.
app.on('before-quit', function(event) {
console.log('before-quit');
if (mainWindow === null && loadingWindow != null) { // mainWindow not intitialised and loadingWindow not dereferenced
if (!forceQuitApp && mainWindow === null && loadingWindow != null) { // mainWindow not intitialised and loadingWindow not dereferenced
// loading window is still open
console.log('before-quit prevented');
shepherd.writeLog('quit app after loading is done');
@ -482,7 +540,7 @@ app.on('before-quit', function(event) {
// 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) {
if (!forceQuitApp && mainWindow === null && loadingWindow != null) {
// loading window is still open
console.log('will-quit while loading window active');
event.preventDefault();
@ -492,7 +550,7 @@ app.on('will-quit', function(event) {
// 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) {
if (!forceQuitApp && mainWindow === null && loadingWindow != null) {
console.log('quit while loading window active');
event.preventDefault();
}

27
routes/appConfig.js

@ -1,5 +1,5 @@
const appConfig = {
config: {
config: { // default config
edexGuiOnly: true,
iguanaGuiOnly: false,
manualIguanaStart: false,
@ -23,6 +23,7 @@ const appConfig = {
},
iguanaLessMode: true,
roundValues: false,
experimentalFeatures: false,
dataDir: '',
},
schema: {
@ -66,6 +67,7 @@ const appConfig = {
},
iguanaCorePort: {
display: true,
initDisplay: true,
type: 'number',
displayName: 'Iguana Core Port',
info: 'Default Iguana Core Port. Change it if you have conflicts with other applications.',
@ -92,8 +94,9 @@ const appConfig = {
},
dev: {
display: true,
initDisplay: true,
displayName: 'Developer mode',
info: 'Enable developer mode.',
info: 'Enable developer mode',
type: 'boolean',
},
v2: {
@ -102,12 +105,14 @@ const appConfig = {
},
useBasiliskInstance: {
display: true,
initDisplay: true,
displayName: 'Iguana Core Basilisk Instance',
info: 'Enable dedicated Iguana Core instance to handle all Basilisk network requests',
type: 'boolean',
},
debug: {
display: true,
initDisplay: true,
displayName: 'Debug',
info: 'Enable debug output',
type: 'boolean',
@ -137,15 +142,29 @@ const appConfig = {
roundValues: {
display: true,
displayName: 'Enable amount rounding',
info: 'Round \"dust\" amounts to save screen space.',
info: 'Round \"dust\" amounts to save screen space',
type: 'boolean',
},
experimentalFeatures: {
display: true,
initDisplay: true,
displayName: 'Enable experimental features',
type: 'boolean',
},
dataDir: {
display: true,
initDisplay: true,
displayName: 'Komodo data directory',
info: 'The data directory is the location where Komodo data files are stored, including the wallet data file.',
info: 'The data directory is the location where Komodo data files are stored, including the wallet data file',
type: 'folder',
},
daemonTest: {
display: false,
initDisplay: true,
displayName: 'Test daemons start (debug)',
info: 'Test daemons before launching. Use this option to get verbose output regarding possible daemon start issues.',
type: 'boolean',
},
},
};

68
routes/shepherd.js

@ -22,7 +22,7 @@ const electron = require('electron'),
remoteFileSize = require('remote-file-size'),
Promise = require('bluebird'),
{shell} = require('electron'),
{ execFile } = require('child_process');
{execFile} = require('child_process');
const fixPath = require('fix-path');
var ps = require('ps-node'),
@ -35,7 +35,8 @@ var ps = require('ps-node'),
syncOnlyIguanaInstanceInfo = {},
syncOnlyInstanceInterval = -1,
guiLog = {},
rpcConf = {};
rpcConf = {},
lockDownAddCoin = false;
shepherd.appConfig = _appConfig.config;
@ -97,13 +98,13 @@ shepherd.testLocation = function(path) {
return new Promise(function(resolve, reject) {
fs.lstat(path, (err, stats) => {
if (err) {
console.log('error testing path ' + path);
console.log(`error testing path ${path}`);
resolve(-1);
} else {
if (stats.isDirectory()) {
resolve(true);
} else {
console.log('error testing path ' + path + ' not a folder');
console.log(`error testing path ${path} not a folder`);
resolve(false);
}
}
@ -156,7 +157,7 @@ shepherd.killRogueProcess = function(processName) {
exec(processGrep, function(error, stdout, stderr) {
if (stdout.indexOf(processName) > -1) {
const pkillCmd = osPlatform === 'win32' ? 'taskkill /f /im ' + processName + '.exe' : 'pkill -15 ' + processName;
const pkillCmd = osPlatform === 'win32' ? `taskkill /f /im ${processName}.exe` : `pkill -15 ${processName}`;
console.log(`found another ${processName} process(es)`);
shepherd.writeLog(`found another ${processName} process(es)`);
@ -901,6 +902,7 @@ 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 = {};
lockDownAddCoin = true;
for (let key in coindInstanceRegistry) {
const chain = key !== 'komodod' ? key : null;
@ -1676,37 +1678,39 @@ shepherd.post('/herd', function(req, res) {
console.log(req.body);
function testCoindPort() {
const _port = assetChainPorts[req.body.options.ac_name];
portscanner.checkPortStatus(_port, '127.0.0.1', function(error, status) {
// Status is 'open' if currently in use or 'closed' if available
if (status === 'open') {
console.log(`komodod service start error at port ${_port}, reason: port is closed`);
shepherd.writeLog(`komodod service start error at port ${_port}, reason: port is closed`);
cache.io.emit('service', {
komodod: {
error: 'error starting ' + req.body.herd + ' ' + req.body.options.ac_name + ' daemon. Port ' + _port + ' is already taken!',
},
});
if (!lockDownAddCoin) {
const _port = assetChainPorts[req.body.options.ac_name];
const obj = {
msg: 'error',
result: 'error starting ' + req.body.herd + ' ' + req.body.options.ac_name + ' daemon. Port ' + _port + ' is already taken!',
};
portscanner.checkPortStatus(_port, '127.0.0.1', function(error, status) {
// Status is 'open' if currently in use or 'closed' if available
if (status === 'open') {
console.log(`komodod service start error at port ${_port}, reason: port is closed`);
shepherd.writeLog(`komodod service start error at port ${_port}, reason: port is closed`);
cache.io.emit('service', {
komodod: {
error: `error starting ${req.body.herd} ${req.body.options.ac_name} daemon. Port ${_port} is already taken!`,
},
});
res.status(500);
res.end(JSON.stringify(obj));
} else {
herder(req.body.herd, req.body.options);
const obj = {
msg: 'error',
result: `error starting ${req.body.herd} ${req.body.options.ac_name} daemon. Port ${_port} is already taken!`,
};
const obj = {
msg: 'success',
result: 'result',
};
res.status(500);
res.end(JSON.stringify(obj));
} else {
herder(req.body.herd, req.body.options);
res.end(JSON.stringify(obj));
}
});
const obj = {
msg: 'success',
result: 'result',
};
res.end(JSON.stringify(obj));
}
});
}
}
if (req.body.herd === 'komodod') {

Loading…
Cancel
Save