-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
71 lines (54 loc) · 1.68 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
const electron = require('electron');
const app = electron.app;
const BrowserWindow = electron.BrowserWindow;
const path = require('path');
electron.crashReporter.start({
productName: 'YourName',
companyName: 'YourCompany',
submitURL: 'https://your-domain.com/url-to-submit',
uploadToServer: true
});
var mainWindow = null;
app.on('window-all-closed', function() {
//if (process.platform != 'darwin') {
app.quit();
//}
});
app.on('ready', function() {
var PY_DIST_FOLDER = 'dist';
var PY_MODULE = 'hello' // without .py suffix
var scriptPath = path.join(__dirname, PY_MODULE, PY_MODULE);
var subpy = require('child_process').execFile(scriptPath, [5000])
if (subpy != null) {
//console.log(pyProc)
console.log('child process success on port ' + 5000)
}
// call python?
//var subpy = require('child_process').spawn('python', ['./hello.py']);
//var subpy = require('child_process').spawn('./dist/hello.exe');
var rq = require('request-promise');
var mainAddr = 'http://localhost:5000';
var openWindow = function(){
mainWindow = new BrowserWindow({width: 800, height: 600});
// mainWindow.loadURL('file://' + __dirname + '/index.html');
mainWindow.loadURL('http://localhost:5000');
mainWindow.webContents.openDevTools();
mainWindow.on('closed', function() {
mainWindow = null;
subpy.kill('SIGINT');
});
};
var startUp = function(){
rq(mainAddr)
.then(function(htmlString){
console.log('server started!');
openWindow();
})
.catch(function(err){
//console.log('waiting for the server start...');
startUp();
});
};
// fire!
startUp();
});