@@ -93,12 +93,6 @@ var App = (function(App, undefined) {
9393
9494 App . findServerDirectory ( ) ;
9595
96- /*
97- if (!settings.hasOwnProperty("dbDeletion") || settings.dbDeletion != "1.0.-1") {
98- App.deleteDbIfExists();
99- settings.dbDeletion = "1.0.-1";
100- }*/
101-
10296 if ( ! electron . app . isDefaultProtocolClient ( "iota" ) ) {
10397 console . log ( "Register iota as a default protocol" ) ;
10498 electron . app . setAsDefaultProtocolClient ( "iota" ) ; //not linux
@@ -140,6 +134,12 @@ var App = (function(App, undefined) {
140134 if ( ! settings . hasOwnProperty ( "isFirstRun" ) ) {
141135 settings . isFirstRun = 1 ;
142136 }
137+ if ( ! settings . hasOwnProperty ( "port" ) ) {
138+ settings . port = 14265 ;
139+ }
140+ if ( ! settings . hasOwnProperty ( "nodes" ) || typeof settings . nodes != "object" ) {
141+ settings . nodes = [ ] ;
142+ }
143143 console . log ( settings ) ;
144144 } catch ( err ) {
145145 console . log ( "Error reading settings." ) ;
@@ -479,7 +479,7 @@ var App = (function(App, undefined) {
479479 }
480480 } ,
481481 {
482- label : "View Peers " ,
482+ label : "View Neighbors " ,
483483 //accelerator: "CmdOrCtrl+N",
484484 click ( item ) {
485485 App . showPeers ( ) ;
@@ -514,6 +514,13 @@ var App = (function(App, undefined) {
514514 App . openDatabaseFolder ( ) ;
515515 }
516516 } ,
517+ {
518+ label : "Edit Server Configuration" ,
519+ //accelerator: "CmdOrCtrl+E",
520+ click ( item ) {
521+ App . editServerConfiguration ( ) ;
522+ }
523+ } ,
517524 {
518525 type : "separator"
519526 } ,
@@ -648,7 +655,7 @@ var App = (function(App, undefined) {
648655 }*/
649656
650657 // Remove preferences (other location on mac)
651- template [ 3 ] . submenu . splice ( 7 , 2 ) ;
658+ template [ 3 ] . submenu . splice ( 8 , 2 ) ;
652659 } else if ( process . platform == "win32" ) {
653660 if ( ! isDevelopment ) {
654661 /*
@@ -677,48 +684,9 @@ var App = (function(App, undefined) {
677684 console . log ( "Server directory is: " + serverDirectory ) ;
678685 console . log ( "Jar directory is: " + jarDirectory ) ;
679686
680- var defaultNodes = "+udp://188.138.57.93:14265\r\n+udp://104.238.171.31:14265\r\n+udp://46.101.118.240:14265\r\n+udp://178.62.203.156:14265\r\n+udp://139.59.134.213:14265\r\n+udp://104.238.181.100:14265\r\n+udp://66.11.119.73:14265\r\n+udp://167.114.182.68:14265\r\n+udp://104.198.4.96:14265\r\n+udp://46.101.147.184:14265\r\n+udp://107.170.52.140:14265\r\n+udp://104.198.15.213:14265" ;
681-
682- if ( fs . existsSync ( serverDirectory ) ) {
683- var uiFolder = path . join ( serverDirectory , "ui" ) ;
684- var srcFolder = path . join ( serverDirectory , "src" ) ;
685-
686- if ( fs . existsSync ( uiFolder ) ) {
687- console . log ( "Delete obsolete files." ) ;
688-
689- deleteFiles ( [ "console.html" , "IRI.jar" , "IRI-prev.jar" , "nostalgia.html" , "VERSION" , ".DS_Store" ] ) ;
690-
691- var fsExtra = require ( "fs-extra" ) ;
692-
693- if ( fs . existsSync ( srcFolder ) ) {
694- console . log ( "Delete " + srcFolder ) ;
695- fsExtra . removeSync ( srcFolder ) ;
696- }
697- if ( fs . existsSync ( uiFolder ) ) {
698- console . log ( "Delete " + uiFolder ) ;
699- fsExtra . removeSync ( uiFolder ) ;
700- }
701- }
702-
703- if ( ! settings . hasDefaultNodes ) {
704- console . log ( "Append default nodes" ) ;
705- fs . appendFileSync ( path . join ( serverDirectory , "IRI.cfg" ) , "\r\n" + defaultNodes ) ;
706- settings . hasDefaultNodes = 1 ;
707- }
708- } else {
687+ if ( ! fs . existsSync ( serverDirectory ) ) {
709688 console . log ( "Creating server directory." ) ;
710689 fs . mkdirSync ( serverDirectory ) ;
711-
712- var defaultConfigPath = path . join ( jarDirectory , "IRI.cfg" ) ;
713-
714- if ( fs . existsSync ( defaultConfigPath ) ) {
715- console . log ( "Copying default IRI.cfg." ) ;
716- var fsExtra = require ( "fs-extra" ) ;
717- fsExtra . copySync ( defaultConfigPath , path . join ( serverDirectory , "IRI.cfg" ) ) ;
718- } else {
719- console . log ( "Creating default IRI.cfg." ) ;
720- fs . writeFileSync ( path . join ( serverDirectory , "IRI.cfg" ) , defaultNodes ) ;
721- }
722690 }
723691 } catch ( err ) {
724692 console . log ( "err:" ) ;
@@ -953,6 +921,12 @@ var App = (function(App, undefined) {
953921
954922 params . push ( path . join ( jarDirectory , "IRI.jar" ) ) ;
955923
924+ params . push ( settings . port ) ;
925+
926+ if ( settings . nodes ) {
927+ params = params . concat ( settings . nodes ) ;
928+ }
929+
956930 console . log ( params ) ;
957931
958932 serverOutput = [ ] ;
@@ -1248,9 +1222,14 @@ var App = (function(App, undefined) {
12481222
12491223 App . checkServerOutput = function ( data ) {
12501224 if ( ! isStarted && ! didKillServer ) {
1251- if ( data . match ( / T r a n s a c t i o n s t o r e q u e s t | F o l l o w i n g c o o r d i n a t o r / i) ) {
1225+ // This can result in errors.. Need to have a real response from the console instead of just this.
1226+ if ( data . match ( / I R I [ 0 - 9 ] / i) ) {
12521227 App . serverStarted ( ) ;
12531228 }
1229+ /*
1230+ if (data.match(/Transactions to request|Following coordinator/i)) {
1231+ App.serverStarted();
1232+ }*/
12541233 }
12551234 if ( settings . showStatusBar ) {
12561235 var transactions = data . match ( / T r a n s a c t i o n s t o r e q u e s t = ( [ 0 - 9 ] + ) \/ ( [ 0 - 9 ] + ) / i) ;
@@ -1403,14 +1382,6 @@ var App = (function(App, undefined) {
14031382 msg = "A server initialization error occurred." ;
14041383 }
14051384
1406- var serverConfig = "" ;
1407-
1408- if ( serverDirectory ) {
1409- try {
1410- var serverConfig = fs . readFileSync ( path . join ( serverDirectory , "IRI.cfg" ) , "utf8" ) ;
1411- } catch ( err ) { }
1412- }
1413-
14141385 if ( ! selectedJavaLocation ) {
14151386 selectedJavaLocation = "java" ;
14161387 }
@@ -1445,14 +1416,13 @@ var App = (function(App, undefined) {
14451416 child . on ( "exit" , function ( ) {
14461417 App . showOtherWindow ( "init_error.html" , title , msg , { "javaArgs" : args ,
14471418 "serverOutput" : serverOutput ,
1448- "serverConfig" : serverConfig ,
14491419 "javaVersionOK" : javaVersionOK ,
14501420 "java64BitsOK" : java64BitsOK ,
14511421 "is64BitOS" : is64BitOS } ) ;
14521422 } ) ;
14531423 } else {
14541424 console . log ( "32-bit" ) ;
1455- App . showOtherWindow ( "init_error.html" , title , msg , { "javaArgs" : args , "serverOutput" : serverOutput , "serverConfig" : serverConfig } ) ;
1425+ App . showOtherWindow ( "init_error.html" , title , msg , { "javaArgs" : args , "serverOutput" : serverOutput } ) ;
14561426 }
14571427
14581428 selectedJavaLocation = "" ;
@@ -1578,6 +1548,51 @@ var App = (function(App, undefined) {
15781548 }
15791549 }
15801550
1551+ App . editServerConfiguration = function ( ) {
1552+ console . log ( "Edit server configuration." ) ;
1553+
1554+ if ( win && win . webContents ) {
1555+ App . showWindowIfNotVisible ( ) ;
1556+ win . webContents . send ( "editServerConfiguration" , { "port" : settings . port , "nodes" : settings . nodes . join ( "\r\n" ) } ) ;
1557+ }
1558+ }
1559+
1560+ App . updateServerConfiguration = function ( configuration ) {
1561+ console . log ( "Update server configuration." ) ;
1562+
1563+ try {
1564+ settings . nodes = configuration . nodes . match ( / [ ^ \r \n ] + / g) . unique ( ) ;
1565+ settings . port = configuration . port ;
1566+
1567+ App . saveSettings ( ) ;
1568+ } catch ( err ) {
1569+ console . log ( "Error" ) ;
1570+ console . log ( err ) ;
1571+ }
1572+ }
1573+
1574+ App . addNeighborNode = function ( node ) {
1575+ console . log ( "Add neighbor node: " + node ) ;
1576+
1577+ try {
1578+ if ( ! node ) {
1579+ return ;
1580+ }
1581+
1582+ node = String ( node ) ;
1583+
1584+ if ( ! node . match ( / ^ u d p : \/ \/ / i) ) {
1585+ return ;
1586+ }
1587+
1588+ settings . nodes . push ( node ) ;
1589+ App . saveSettings ( ) ;
1590+ } catch ( err ) {
1591+ console . log ( "Error" ) ;
1592+ console . log ( err ) ;
1593+ }
1594+ }
1595+
15811596 App . showServerLog = function ( ) {
15821597 if ( win && win . webContents ) {
15831598 App . showWindowIfNotVisible ( ) ;
@@ -1872,6 +1887,10 @@ electron.ipcMain.on("updatePreferences", function(event, checkForUpdatesOption)
18721887 App . updatePreferences ( checkForUpdatesOption ) ;
18731888} ) ;
18741889
1890+ electron . ipcMain . on ( "updateServerConfiguration" , function ( event , configuration ) {
1891+ App . updateServerConfiguration ( configuration ) ;
1892+ } ) ;
1893+
18751894electron . ipcMain . on ( "installUpdate" , function ( ) {
18761895 App . installUpdate ( ) ;
18771896} ) ;
@@ -1896,6 +1915,12 @@ electron.ipcMain.on("showNoJavaInstalledWindow", function(event, params) {
18961915 App . showNoJavaInstalledWindow ( true , params ) ;
18971916} ) ;
18981917
1918+ electron . ipcMain . on ( "editServerConfiguration" , App . editServerConfiguration ) ;
1919+
1920+ electron . ipcMain . on ( "addNeighborNode" , function ( event , node ) {
1921+ App . addNeighborNode ( node ) ;
1922+ } ) ;
1923+
18991924electron . ipcMain . on ( "upgradeIRI" , function ( event , sourceFile ) {
19001925 App . upgradeIRI ( sourceFile ) ;
19011926} ) ;
0 commit comments