-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
82 lines (78 loc) · 2.03 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
const { app, BrowserWindow,ipcMain,dialog } = require('electron')
const path = require('path')
let win;
// const userDataPath = app.getPath('userData');
const exePath = app.getPath('exe');
var basePath = exePath.slice(0, exePath.lastIndexOf("\\"));
basePath = "./backend";
console.log(basePath);
function createWindow() {
let backend;
backend = path.join(process.cwd(), './engine.exe')
var execfile = require('child_process').execFile;
execfile(
backend,
{
windowsHide: true,
},
(err, stdout, stderr) => {
if (err) {
console.log(err);
}
if (stdout) {
console.log(stdout);
}
if (stderr) {
console.log(stderr);
}
}
)
win = new BrowserWindow({
width: 790,
height: 620,
frame:false,
webPreferences: {
nodeIntegration:true,
contextIsolation: false
}
})
win.removeMenu();
win.webContents.openDevTools();
win.loadFile('index.html');
ipcMain.on('xylent-get-path',(event,data)=>{
if (data ==="XYLENT_GET_APP_PATH"){
event.reply('xylent-get-path', basePath);
}
});
ipcMain.on('minimize',() => {
win.minimize()
})
ipcMain.on('close',() => {
win.close()
});
ipcMain.handle('file-picker', (event, params) => {
return dialog.showOpenDialog(params);
});
}
app.whenReady().then(() => {
createWindow()
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) {
createWindow()
}
})
})
app.on('window-all-closed', () => {
const { exec } = require('child_process');
exec('taskkill /f /t /im engine.exe', (err, stdout, stderr) => {
if (err) {
console.log(err)
return;
}
console.log(`stdout: ${stdout}`);
console.log(`stderr: ${stderr}`);
});
if (process.platform !== 'darwin') {
app.quit()
}
})