forked from alairon/SwitchRP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
99 lines (79 loc) · 2.04 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
99
/* Electron */
const { app, BrowserWindow } = require('electron');
/* IPC */
const { ipcMain } = require('electron');
/* Child Processes */
const exec = require('child_process');
/* Global Electron Window Values */
let mainWindow = null;
/* Main Window */
function createLauncherWindow() {
mainWindow = new BrowserWindow({
webPreferences: {
nodeIntegration: true,
},
width: 800,
height: 600,
resizable: true,
});
// Load the main page
mainWindow.loadFile('./index.html');
// Hide the menu bar
mainWindow.setMenu(null);
// Show the Chrome development tools when launched
// mainWindow.toggleDevTools();
mainWindow.on('closed', () => {
mainWindow = null;
});
}
/* Electron Application */
app.on('ready', createLauncherWindow);
app.on('window-all-closed', () => {
// Process is different with Darwin (Mac OS/OS X)
if (process.platform !== 'darwin') {
app.quit();
}
});
app.on('activate', () => {
if (mainWindow === null) {
createLauncherWindow();
}
});
/* Process Functions */
// Uncaught Rejection, in case of Discord Timeouts
process.on('unhandledRejection', (reason) => {
console.log(reason.stack || reason);
});
/* IPC -- Update Function */
let winLauncher = null;
function statusWindow(clientAppID) {
winLauncher = new BrowserWindow({
width: 800,
height: 250,
resizable: false,
});
// Shift control of windows
mainWindow.minimize();
mainWindow.hide();
winLauncher.loadFile('gameConfig-temp.html');
const pidVal = exec.spawn('node', ['discordConnect.js', clientAppID]);
// Hide the menu bar
winLauncher.setMenu(null);
winLauncher.on('closed', () => {
winLauncher = null;
if (process.platform === 'win32') {
const cmd = `taskkill /pid ${pidVal.pid} /t /f`;
exec.exec(cmd);
} else {
pidVal.kill('SIGINT');
}
// Restore control to the main interface
mainWindow.show();
mainWindow.restore();
});
}
ipcMain.on('updateStat', (event, clientAppID) => {
if (winLauncher === null) {
statusWindow(clientAppID);
}
});