-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
100 lines (83 loc) · 2.53 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
const electron = require('electron');
const app = electron.app;
const BrowserWindow = electron.BrowserWindow;
const Tray = electron.Tray;
// Keep a global reference of the window object
var mainWindow = null;
// Quit when all windows are closed.
app.on('window-all-closed', function() {
// if (process.platform != 'darwin') {
app.quit();
// }
});
app.on('ready', function() {
// call python?
var subpy = require('child_process').spawn('python', [__dirname + '/main.py']);
var rq = require('request-promise');
var mainAddr = 'http://localhost:8000';
const appIcon = new Tray(__dirname + '/app/static/imgs/ArtificialFictionBrain.png');
var openWindow = function(){
// Create the browser window.
mainWindow = new BrowserWindow({width: 800, height: 600, title:'GooeyBrain', icon:__dirname + '/app/static/imgs/ArtificialFictionBrain.png' });
mainWindow.loadURL('http://localhost:8000');
// Open the devtools.
mainWindow.webContents.openDevTools();
mainWindow.on('closed', function() {
mainWindow = null;
// kill python
subpy.kill('SIGINT');
});
app.on('exit', function () {
subpy.kill();
});
};
var sendStdOut = function() {
subpy.stdout.on('data', function(data) {
console.log('stdout: ' + data);
mainWindow.webContents.send('info-log' , {msg:String(data)});
});
subpy.stderr.on('data', function(data) {
console.log('stderr: ' + data);
mainWindow.webContents.send('info-log' , {msg:String(data)});
});
subpy.on('close', function(code) {
console.log('closing code: ' + code);
});
}
var startUp = function(){
rq(mainAddr)
.then(function(htmlString){
console.log('server started!');
openWindow();
sendStdOut();
})
.catch(function(err){
//console.log('waiting for the server start...');
startUp();
});
};
// fire!
startUp();
});
const ipc = require('electron').ipcMain;
const dialog = require('electron').dialog;
ipc.on('open-dir-dialog', function (event) {
dialog.showOpenDialog({
properties: ['openFile', 'openDirectory']
}, function (files) {
if (files) {
console.log(files);
event.sender.send('selected-directory', files);
}
})
});
ipc.on('open-file-dialog', function (event) {
dialog.showOpenDialog({
properties: ['openFile']
}, function (files) {
if (files) {
console.log(files);
event.sender.send('selected-file', files);
}
})
});