@@ -21,24 +21,40 @@ app.on('ready', function() {
2121 // call python?
2222 var subpy = require ( 'child_process' ) . spawn ( 'python' , [ './hello.py' ] ) ;
2323
24- // Create the browser window.
25- mainWindow = new BrowserWindow ( { width : 800 , height : 600 } ) ;
26-
27- // and load the index.html of the app.
28- mainWindow . loadUrl ( 'file://' + __dirname + '/index.html' ) ;
29- //mainWindow.loadUrl('http://localhost:5000');
30-
31- // Open the devtools.
32- mainWindow . openDevTools ( ) ;
33-
34- // Emitted when the window is closed.
35- mainWindow . on ( 'closed' , function ( ) {
36- // Dereference the window object, usually you would store windows
37- // in an array if your app supports multi windows, this is the time
38- // when you should delete the corresponding element.
39- mainWindow = null ;
40-
41- // kill python
42- subpy . kill ( 'SIGINT' ) ;
43- } ) ;
24+ var rq = require ( 'request-promise' ) ;
25+ var mainAddr = 'http://localhost:5000' ;
26+
27+ var openWindow = function ( ) {
28+ // Create the browser window.
29+ mainWindow = new BrowserWindow ( { width : 800 , height : 600 } ) ;
30+ // and load the index.html of the app.
31+ // mainWindow.loadURL('file://' + __dirname + '/index.html');
32+ mainWindow . loadURL ( 'http://localhost:5000' ) ;
33+ // Open the devtools.
34+ mainWindow . openDevTools ( ) ;
35+ // Emitted when the window is closed.
36+ mainWindow . on ( 'closed' , function ( ) {
37+ // Dereference the window object, usually you would store windows
38+ // in an array if your app supports multi windows, this is the time
39+ // when you should delete the corresponding element.
40+ mainWindow = null ;
41+ // kill python
42+ subpy . kill ( 'SIGINT' ) ;
43+ } ) ;
44+ } ;
45+
46+ var startUp = function ( ) {
47+ rq ( mainAddr )
48+ . then ( function ( htmlString ) {
49+ console . log ( 'server started!' ) ;
50+ openWindow ( ) ;
51+ } )
52+ . catch ( function ( err ) {
53+ //console.log('waiting for the server start...');
54+ startUp ( ) ;
55+ } ) ;
56+ } ;
57+
58+ // fire!
59+ startUp ( ) ;
4460} ) ;
0 commit comments