// TODO: merge into react app
let _ configCopy ;
function toggleMainWindowHelp ( ) {
const _ help = $ ( '.agama-modes-help' ) ;
if ( _ help . is ( ':visible' ) ) {
_ help . hide ( ) ;
} else {
_ help . show ( ) ;
}
}
function toggleDropdown ( type ) {
const _ dropdown = $ ( '.dropdown-menu.' + ( type === 'lite' ? 'lite' : 'native' ) ) ;
if ( _ dropdown . hasClass ( 'hide' ) ) {
_ dropdown . removeClass ( 'hide' ) ;
} else {
_ dropdown . addClass ( 'hide' ) ;
}
$ ( '.dropdown-menu.' + ( type === 'lite' ? 'native' : 'lite' ) ) . addClass ( 'hide' ) ;
}
function initSettingsForm ( ) {
const remote = require ( 'electron' ) . remote ;
let appConf = remote . getCurrentWindow ( ) . appConfig ;
let appConfSchema = remote . getCurrentWindow ( ) . appConfigSchema ;
_ configCopy = Object . assign ( { } , appConf ) ;
let _ htmlOut = '<table class="settings-table">' ;
for ( let key in appConf ) {
if ( appConfSchema [ key ] &&
appConfSchema [ key ] . initDisplay ) {
_ htmlOut = `
$ { _ htmlOut }
< tr >
< td class = "left" >
$ { appConfSchema [ key ] . displayName } ` ;
if ( appConfSchema [ key ] . info ) {
_ htmlOut = `
$ { _ htmlOut }
< div
class = "settings-help"
title = "${appConfSchema[key].info}" >
< img src = "../EasyDEX-GUI/assets/mainWindow/img/fa-question.png" / >
< / d i v > ` ;
}
if ( appConfSchema [ key ] . type === 'number' ) {
_ htmlOut = `
$ { _ htmlOut }
< / t d >
< td class = "right" >
< input
type = "number"
id = "${key}"
pattern = "[0-9]*"
onKeyup = "handleInput('${key}')"
value = "${_configCopy[key]}" / >
< / t d >
< / t r > ` ;
} else if ( appConfSchema [ key ] . type === 'string' || appConfSchema [ key ] . type === 'folder' ) {
_ htmlOut = `
$ { _ htmlOut }
< / t d >
< td class = "right" >
< input
type = "text"
id = "${key}"
onKeyup = "handleInput('${key}')"
value = "${_configCopy[key]}" / >
< / t d >
< / t r > ` ;
} else if ( appConfSchema [ key ] . type === 'boolean' ) {
_ htmlOut = ` ${ _ htmlOut }
< / t d >
< td class = "right" >
< label
class = "switch"
id = "${key}"
onClick = "settingsToggle(\'${key}\')" >
$ { ( appConf [ key ] ? '<input type="checkbox" class="cb" checked />' : '<input type="checkbox" class="cb" />' ) }
< div class = "slider" > < / d i v >
< / l a b e l >
< / t d >
< / t r > ` ;
}
}
}
_ htmlOut = `
$ { _ htmlOut }
< / t a b l e > ` ;
$ ( '#agamaConfigBlock' ) . html ( _ htmlOut ) ;
}
function hideToastImmediate ( ) {
$ ( '#toast-container' ) . addClass ( 'hide' ) ;
}
function hideToast ( ) {
setTimeout ( function ( ) {
$ ( '#toast-container' ) . addClass ( 'hide' ) ;
} , 5000 ) ;
}
function showToast ( type , message ) {
$ ( '#toast-container .toast' ) . removeClass ( 'toast-success' ) . removeClass ( 'toast-error' ) ;
$ ( '#toast-container .toast' ) . addClass ( ` toast- ${ type } ` ) ;
$ ( '#toast-container .toast-message' ) . html ( message ) ;
$ ( '#toast-container' ) . removeClass ( 'hide' ) ;
hideToast ( ) ;
}
function setDefaultAppSettings ( ) {
const remote = require ( 'electron' ) . remote ;
remote . getCurrentWindow ( ) . setDefaultAppSettings ( ) ;
remote . getCurrentWindow ( ) . appConfig = remote . getCurrentWindow ( ) . defaultAppSettings ;
initSettingsForm ( ) ;
showToast ( 'success' , 'App settings are reset to default' ) ;
}
function testBins ( binName ) {
const remote = require ( 'electron' ) . remote ;
remote . getCurrentWindow ( ) . testBins ( binName ) .
then ( function ( res ) {
$ ( '#debugOut' ) . html ( JSON . stringify ( res , null , '\t' ) ) ;
} ) ;
}
function handleSaveSettings ( ) {
if ( _ configCopy . dataDir &&
_ configCopy . dataDir . length ) {
const remote = require ( 'electron' ) . remote ;
remote . getCurrentWindow ( ) . testLocation ( _ configCopy . dataDir )
. then ( function ( res ) {
if ( res === - 1 ) {
showToast ( 'error' , 'Komodo datadir path is invalid.<br>It must be an absolute path to an existing folder that doesn\'t contain spaces and/or any special characters.' ) ;
} else if ( res === false ) {
showToast ( 'error' , 'Komodo datadir path is not a directory.<br>It must be an absolute path to an existing folder that doesn\'t contain spaces and/or any special characters.' ) ;
} else {
// save settings
remote . getCurrentWindow ( ) . updateAppSettings ( _ configCopy ) ;
remote . getCurrentWindow ( ) . appConfig = _ configCopy ;
showToast ( 'success' , 'Settings saved' ) ;
}
} ) ;
} else {
// save settings
const remote = require ( 'electron' ) . remote ;
remote . getCurrentWindow ( ) . updateAppSettings ( _ configCopy ) ;
remote . getCurrentWindow ( ) . appConfig = _ configCopy ;
showToast ( 'success' , 'Settings saved' ) ;
}
}
function handleInput ( key ) {
const _ value = $ ( ` # ${ key } ` ) . val ( ) ;
_ configCopy [ key ] = _ value ;
}
function settingsToggle ( key ) {
const _ value = $ ( ` # ${ key } .cb ` ) . prop ( 'checked' ) ;
_ configCopy [ key ] = _ value ;
}
function closeSettingsWindow ( ) {
const remote = require ( 'electron' ) . remote ;
const window = remote . getCurrentWindow ( ) ;
toggleDropdown ( ) ;
window . destroyAppSettingsWindow ( ) ;
}
function reloadSettingsWindow ( ) {
const remote = require ( 'electron' ) . remote ;
const window = remote . getCurrentWindow ( ) ;
window . reloadSettingsWindow ( ) ;
}
function openSettingsWindow ( ) {
const remote = require ( 'electron' ) . remote ;
const window = remote . getCurrentWindow ( ) ;
$ ( '.dropdown-menu.lite' ) . addClass ( 'hide' ) ;
$ ( '.dropdown-menu.native' ) . addClass ( 'hide' ) ;
window . createAppSettingsWindow ( ) ;
}
function startKMDPassive ( ) {
const remote = require ( 'electron' ) . remote ;
const window = remote . getCurrentWindow ( ) ;
$ ( '.dropdown-menu.lite' ) . addClass ( 'hide' ) ;
$ ( '.dropdown-menu.native' ) . addClass ( 'hide' ) ;
disableModeButtons ( ) ;
window . startKMDNative ( 'KMD' , true ) ;
window . createWindow ( 'open' ) ;
window . hide ( ) ;
}
function startKMDPassive ( ) {
const remote = require ( 'electron' ) . remote ;
const window = remote . getCurrentWindow ( ) ;
$ ( '.dropdown-menu.lite' ) . addClass ( 'hide' ) ;
$ ( '.dropdown-menu.native' ) . addClass ( 'hide' ) ;
disableModeButtons ( ) ;
window . startKMDNative ( 'KMD' , true ) ;
window . createWindow ( 'open' ) ;
window . hide ( ) ;
}
function startSPV ( coin ) {
const remote = require ( 'electron' ) . remote ;
const window = remote . getCurrentWindow ( ) ;
$ ( '.dropdown-menu.lite' ) . addClass ( 'hide' ) ;
$ ( '.dropdown-menu.native' ) . addClass ( 'hide' ) ;
disableModeButtons ( ) ;
window . startSPV ( coin ) ;
window . createWindow ( 'open' ) ;
window . hide ( ) ;
}
function closeMainWindow ( isKmdOnly , isCustom ) {
const remote = require ( 'electron' ) . remote ;
const window = remote . getCurrentWindow ( ) ;
$ ( '.dropdown-menu.lite' ) . addClass ( 'hide' ) ;
$ ( '.dropdown-menu.native' ) . addClass ( 'hide' ) ;
disableModeButtons ( ) ;
if ( ! isCustom ) {
window . startKMDNative ( isKmdOnly ? 'KMD' : null ) ;
setTimeout ( function ( ) {
window . createWindow ( 'open' ) ;
window . hide ( ) ;
} , 3000 ) ;
} else {
window . createWindow ( 'open' ) ;
window . hide ( ) ;
}
}
function quitApp ( ) {
const remote = require ( 'electron' ) . remote ;
const window = remote . getCurrentWindow ( ) ;
window . forseCloseApp ( ) ;
}
function disableModeButtons ( ) {
$ ( '#nativeOnlyBtn' ) . attr ( 'disabled' , true ) ;
$ ( '#normalStartBtn' ) . attr ( 'disabled' , true ) ;
$ ( '#settingsBtn' ) . attr ( 'disabled' , true ) ;
$ ( '#nativeOnlyBtnCarret' ) . attr ( 'disabled' , true ) ;
$ ( '#spvBtn' ) . attr ( 'disabled' , true ) ;
$ ( '#spvBtnCarret' ) . attr ( 'disabled' , true ) ;
}
function normalStart ( ) {
const remote = require ( 'electron' ) . remote ;
let appConf = remote . getCurrentWindow ( ) . appConfig ;
appConf . iguanaLessMode = false ;
$ ( '.dropdown-menu.lite' ) . addClass ( 'hide' ) ;
$ ( '.dropdown-menu.native' ) . addClass ( 'hide' ) ;
disableModeButtons ( ) ;
}
function init ( ) {
const remote = require ( 'electron' ) . remote ;
var window = remote . getCurrentWindow ( ) ;
var appConf = remote . getCurrentWindow ( ) . appConfig ;
if ( ! appConf . experimentalFeatures ) {
$ ( '#spvBtn' ) . hide ( ) ;
$ ( '#spvBtnCarret' ) . hide ( ) ;
$ ( '.dropdown-menu.native' ) . css ( 'right' , '165px' ) ;
$ ( '#nativeOnlyBtnCarret' ) . css ( 'margin-right' , '0' ) ;
$ ( '#settingsBtn' ) . css ( 'margin' , '0' ) ;
}
}