-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
51 lines (43 loc) · 1.79 KB
/
index.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
const {app, process, ipcMain, BrowserWindow} = require('electron')
require('electron-reload')(__dirname);
var Chart = require('chart.js');
let mainWindow;
let backgroundWindow;
// Create the main browser window. This handles all UI and most application logic.
function createMainWindow () {
mainWindow = new BrowserWindow({width: 1024, height: 768, minWidth: 1024, minHeight: 700})
mainWindow.loadFile('index.html')
mainWindow.on('closed', () => {
mainWindow = null;
app.quit();
})
}
// Create the background browser window. This is used to run mesh floatation simulations.
function createBackgroundWindow () {
backgroundWindow = new BrowserWindow({width: 640, height: 480, show: true})
backgroundWindow.loadFile('background.html')
backgroundWindow.on('closed', () => {
backgroundWindow = null
})
}
app.on('ready', () => {
createMainWindow();
createBackgroundWindow();
});
app.on('window-all-closed', () => { app.quit(); })
app.on('activate-with-no-open-windows', () => {
if (win === null) {
createWindow();
}
});
app.on('before-quit', function(){
console.log("Quitting...");
});
ipcMain.on('simulation-start', (event, payload) => backgroundWindow.webContents.send('simulation-start', payload));
ipcMain.on('simulation-cancel', (event, payload) => {
// When we receive a simulation cancel event, clear the simulation by reloading the background page.
backgroundWindow.reload();
});
ipcMain.on('simulation-update-progress', (event, payload) => mainWindow.webContents.send('simulation-update-progress', payload));
ipcMain.on('simulation-success', (event, payload) => mainWindow.webContents.send('simulation-success', payload));
ipcMain.on('simulation-failure', (event, payload) => mainWindow.webContents.send('simulation-failure', payload));