Skip to content

Commit ecf58cd

Browse files
committed
code updated!
1 parent b32d430 commit ecf58cd

5 files changed

Lines changed: 44 additions & 58 deletions

File tree

hello.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77

88
@app.route("/")
99
def hello():
10-
#sleep(5)
1110
return "Hello World!"
1211

1312
if __name__ == "__main__":
1413
print('oh hello')
14+
#sleep(10)
1515
sys.stdout.flush()
1616
app.run()

index.html

Lines changed: 0 additions & 30 deletions
This file was deleted.

jquery-2.1.4.min.js

Lines changed: 0 additions & 4 deletions
This file was deleted.

main.js

Lines changed: 36 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -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
});

package.json

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
{
2-
"name" : "your-app",
3-
"version" : "0.1.0",
4-
"main" : "main.js"
2+
"name": "your-app",
3+
"version": "0.2.0",
4+
"main": "main.js",
5+
"dependencies": {
6+
"request-promise": "*",
7+
"electron-prebuilt": "*"
8+
}
59
}

0 commit comments

Comments
 (0)