forked from lexogrine/hud-manager
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathelectron.ts
62 lines (52 loc) · 1.58 KB
/
electron.ts
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
import init from './server'
import { Server } from 'http';
import * as directories from './init/directories';
import { ChildProcess } from "child_process";
import args from './init/args';
import { spawn } from "child_process";
import { app } from 'electron';
import { createMainWindow } from './renderer';
interface HLAEChild {
process: ChildProcess | null
}
export const AFXInterop: HLAEChild = {
process: null
}
export const isDev = process.env.DEV === "true";
async function createRenderer(server: Server, forceDev = false) {
const closeManager = () => {
if(server) {
server.close();
}
if(AFXInterop.process){
AFXInterop.process.kill();
}
app.quit();
}
const args = ["./", "--renderer"];
if(forceDev) args.push("--dev");
const renderer = spawn(process.execPath, ["./", "--renderer", "--dev"], {
stdio: ['ignore'],
});
app.on("window-all-closed", () => {});
if(forceDev) renderer.stdout.on("data", data => console.log(data.toString()))
renderer.on("exit", closeManager);
renderer.on("close", closeManager);
app.on("quit", () => {
renderer.kill();
});
}
async function startManager() {
if(process.argv.includes("--renderer")) {
createMainWindow(process.argv.includes("--dev"));
return;
}
app.setAppUserModelId("com.lexogrine.hudmanager");
directories.checkDirectories();
const server = await init();
const argv = args(process.argv);
if(!argv.noGui){
createRenderer(server, argv.dev);
}
}
app.on("ready", startManager);