-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
56 lines (45 loc) · 1.27 KB
/
Copy pathmain.js
File metadata and controls
56 lines (45 loc) · 1.27 KB
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
const { app, BrowserWindow, ipcMain } = require('electron');
const path = require('path');
const { EXEBuilder } = require('./src/exe_builder');
let mainWindow;
let exeBuilder;
function createWindow() {
mainWindow = new BrowserWindow({
width: 900,
height: 600,
webPreferences: {
nodeIntegration: false,
contextIsolation: true,
preload: path.join(__dirname, 'preload.js')
},
backgroundColor: '#1e1e1e',
title: 'RunnerPython'
});
mainWindow.loadFile('index.html');
mainWindow.on('closed', () => {
mainWindow = null;
});
}
ipcMain.on('build-and-run', async (event, code) => {
if (exeBuilder) {
exeBuilder.removeAllListeners();
}
exeBuilder = new EXEBuilder();
exeBuilder.on('log', (msg) => {
mainWindow.webContents.send('build-log', msg);
});
exeBuilder.on('error', (msg) => {
mainWindow.webContents.send('build-error', msg);
});
try {
await exeBuilder.buildAndRun(code);
} catch (error) {
mainWindow.webContents.send('build-error', error.message);
}
});
app.whenReady().then(createWindow);
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit();
}
});