This repository has been archived by the owner on Feb 18, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
708 lines (676 loc) · 22.7 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
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
const clientId = '810552076304121866';
const {
app,
BrowserWindow,
Menu,
dialog,
autoUpdater,
ipcMain
} = require('electron');
const path = require('path');
var fs = require('fs');
const ipc = require('electron').ipcMain;
const {
findSteam
} = require('find-steam-app');
const cp = require('child_process');
var window;
var os = require('os');
const fetch = require('node-fetch');
// var {
// Collection
// } = require('discord.js');
var updateStatus = "none";
// Handle creating/removing shortcuts on Windows when installing/uninstalling.
if (require('electron-squirrel-startup')) {
// eslint-disable-line global-require
app.quit();
}
if (app.isPackaged) {
const server = 'https://hazel-jacubrstnc.vercel.app';
const feed = `${server}/update/${process.platform}/${app.getVersion()}`;
autoUpdater.setFeedURL(feed);
}
async function checkForUpdates() {
if (app.isPackaged) {
autoUpdater.checkForUpdates();
}
}
autoUpdater.on("checking-for-update", () => {
updateStatus = "none"
window.webContents.send('update-changed', updateStatus);
})
autoUpdater.on("update-available", () => {
updateStatus = "downloading"
window.webContents.send('update-changed', updateStatus);
})
autoUpdater.on("update-downloaded", (ehm) => {
updateStatus = "ready"
window.webContents.send('update-changed', updateStatus);
})
autoUpdater.on("update-not-available", () => {
updateStatus = "none"
window.webContents.send('update-changed', updateStatus);
})
const DiscordRPC = require('discord-rpc');
var rpc = new DiscordRPC.Client({
transport: 'ipc'
});
const startTimestamp = new Date();
function nthMostCommon(string, amount) {
var wordsArrayr = string.split(/\s/);
var wordsArray = wordsArrayr.filter((f) => f.length > 0).map((f) => String(f).toLowerCase());
var wordOccurrences = {};
for (var i = 0; i < wordsArray.length; i++) {
wordOccurrences['_' + wordsArray[i]] = (wordOccurrences['_' + wordsArray[i]] || 0) + 1;
}
var result = Object.keys(wordOccurrences).reduce(function (acc, currentKey) {
/* you may want to include a binary search here */
for (var i = 0; i < amount; i++) {
if (!acc[i]) {
acc[i] = {
word: currentKey.slice(1, currentKey.length),
occurences: wordOccurrences[currentKey]
};
break;
} else if (acc[i].occurences < wordOccurrences[currentKey]) {
acc.splice(i, 0, {
word: currentKey.slice(1, currentKey.length),
occurences: wordOccurrences[currentKey]
});
if (acc.length > amount) acc.pop();
break;
}
}
return acc;
}, []);
return result;
}
async function getSteamInfo(steamid, notfetch) {
var rawsteaminfo = await fetch(`https://api.unicorn.wombos.xyz/api/mlauncher/steam/${steamid}`).then(f => f.json());
let steaminfo;
if (rawsteaminfo.status == "success" && rawsteaminfo.data.length > 0 && !notfetch) {
rawsteaminfo = rawsteaminfo.data[0];
steaminfo = {
steamid,
steamname: rawsteaminfo.personaname,
avatar: rawsteaminfo.avatarfull
}
} else {
steaminfo = {
steamid: steamid,
steamname: "not found",
avatar: ""
}
}
return steaminfo;
}
async function getConvInfo() {
return new Promise(async (resolve, reject) => {
var convos = await getConversations();
if (convos == '404') {
resolve(
`An error occured in the process of retrieving iMessages. It could possibly be that we simply couldn't find your Garry's Mod installation.`
);
}
var bigmsg = await convos.map((c) => c.chats.map((f) => f.msg).join(' ')).join(' ');
var camount = convos.size;
var mostcommonw = nthMostCommon(bigmsg, 20).map((f) => `${f.word} [${f.occurences}]`).join('\n');
var bignames = await convos.map((c) => c.name).join(' ');
var mostcommonn = nthMostCommon(bignames, 5).map((f) => `${f.word} [${f.occurences}]`).join('\n');
resolve(
`Found ${camount} conversations. Where the 20 most common words are:\n\n${mostcommonw}\nAnd the 5 most common first names/last names are:\n\n${mostcommonn}`.replaceAll(
'\n',
'<br>'
)
);
});
}
async function getServer() {
var SteamLocation = await findSteam();
if (!SteamLocation) SteamLocation = __dirname
var monoappdatapath = path.join(process.env.APPDATA, 'monolauncher');
var monoappdataex = fs.existsSync(monoappdatapath);
if (!monoappdataex) fs.mkdirSync(monoappdatapath);
var monoappsettingspath = path.join(monoappdatapath, 'settings');
var monoappsettex = fs.existsSync(monoappsettingspath);
if (!monoappsettex) fs.mkdirSync(monoappsettingspath);
var monoappsettingsfilepath = path.join(monoappsettingspath, 'settings.json');
var monoappsfileex = fs.existsSync(monoappsettingsfilepath);
var settings = monoappsfileex ?
JSON.parse(fs.readFileSync(monoappsettingsfilepath).toString()) : {
gmod: path.join(SteamLocation, 'steamapps', 'common', 'GarrysMod'),
ip: '208.103.169.58:27015'
};
if (!settings.ip) settings.ip = '208.103.169.58:27015';
return settings.ip;
}
async function getGame() {
var SteamLocation = await findSteam();
if (!SteamLocation) SteamLocation = __dirname
var monoappdatapath = path.join(process.env.APPDATA, 'monolauncher');
var monoappdataex = fs.existsSync(monoappdatapath);
if (!monoappdataex) fs.mkdirSync(monoappdatapath);
var monoappsettingspath = path.join(monoappdatapath, 'settings');
var monoappsettex = fs.existsSync(monoappsettingspath);
if (!monoappsettex) fs.mkdirSync(monoappsettingspath);
var monoappsettingsfilepath = path.join(monoappsettingspath, 'settings.json');
var monoappsfileex = fs.existsSync(monoappsettingsfilepath);
var settings = monoappsfileex ?
JSON.parse(fs.readFileSync(monoappsettingsfilepath).toString()) : {
gmod: path.join(SteamLocation, 'steamapps', 'common', 'GarrysMod'),
gamepath: path.join(SteamLocation, 'steamapps', 'common', 'GarrysMod', 'hl2.exe'),
game: 'defgmod'
};
if (!settings.game || !settings.gamepath) { settings.game = 'defgmod'; settings.gamepath = path.join(SteamLocation, 'steamapps', 'common', 'GarrysMod', 'hl2.exe'); }
return { game: settings.game, gamepath: settings.gamepath };
}
async function getMultiCore() {
var monoappdatapath = path.join(process.env.APPDATA, 'monolauncher');
var monoappdataex = fs.existsSync(monoappdatapath);
if (!monoappdataex) fs.mkdirSync(monoappdatapath);
var monoappsettingspath = path.join(monoappdatapath, 'settings');
var monoappsettex = fs.existsSync(monoappsettingspath);
if (!monoappsettex) fs.mkdirSync(monoappsettingspath);
var monoappsettingsfilepath = path.join(monoappsettingspath, 'settings.json');
var monoappsfileex = fs.existsSync(monoappsettingsfilepath);
var settings = monoappsfileex ?
JSON.parse(fs.readFileSync(monoappsettingsfilepath).toString()) : {
multicore: 'false'
};
if (!settings.multicore) settings.multicore = 'false';
return settings.multicore
}
async function setServer(server) {
var SteamLocation = await findSteam();
var monoappdatapath = path.join(process.env.APPDATA, 'monolauncher');
var monoappdataex = fs.existsSync(monoappdatapath);
if (!monoappdataex) fs.mkdirSync(monoappdatapath);
var monoappsettingspath = path.join(monoappdatapath, 'settings');
var monoappsettex = fs.existsSync(monoappsettingspath);
if (!monoappsettex) fs.mkdirSync(monoappsettingspath);
var monoappsettingsfilepath = path.join(monoappsettingspath, 'settings.json');
var monoappsfileex = fs.existsSync(monoappsettingsfilepath);
var settings = monoappsfileex ?
JSON.parse(fs.readFileSync(monoappsettingsfilepath).toString()) : {
gmod: path.join(SteamLocation, 'steamapps', 'common', 'GarrysMod'),
ip: server || '208.103.169.58:27015'
};
if (!settings.ip) settings.ip = server || '208.103.169.58:27015';
settings.ip = server;
try {
fs.writeFileSync(monoappsettingsfilepath, JSON.stringify(settings));
window.webContents.send('server-changed', settings.ip);
} catch (e) { }
return {
success: true,
ip: settings.ip
};
}
async function setMultiCore(multicore) {
var monoappdatapath = path.join(process.env.APPDATA, 'monolauncher');
var monoappdataex = fs.existsSync(monoappdatapath);
if (!monoappdataex) fs.mkdirSync(monoappdatapath);
var monoappsettingspath = path.join(monoappdatapath, 'settings');
var monoappsettex = fs.existsSync(monoappsettingspath);
if (!monoappsettex) fs.mkdirSync(monoappsettingspath);
var monoappsettingsfilepath = path.join(monoappsettingspath, 'settings.json');
var monoappsfileex = fs.existsSync(monoappsettingsfilepath);
var settings = monoappsfileex ?
JSON.parse(fs.readFileSync(monoappsettingsfilepath).toString()) : {
multicore: 'false'
};
if (!settings.multicore) settings.multicore = multicore || 'false';
settings.multicore = multicore;
try {
fs.writeFileSync(monoappsettingsfilepath, JSON.stringify(settings));
window.webContents.send('multicore-changed', settings.multicore);
} catch (e) { }
return {
success: true,
multicore: settings.multicore
};
}
async function getgmodlocation() {
var SteamLocation = await findSteam();
var monoappdatapath = path.join(process.env.APPDATA, 'monolauncher');
var monoappdataex = fs.existsSync(monoappdatapath);
if (!monoappdataex) fs.mkdirSync(monoappdatapath);
var monoappsettingspath = path.join(monoappdatapath, 'settings');
var monoappsettex = fs.existsSync(monoappsettingspath);
if (!monoappsettex) fs.mkdirSync(monoappsettingspath);
var monoappsettingsfilepath = path.join(monoappsettingspath, 'settings.json');
var monoappsfileex = fs.existsSync(monoappsettingsfilepath);
var settings = monoappsfileex ?
JSON.parse(fs.readFileSync(monoappsettingsfilepath).toString()) : {
gmod: path.join(SteamLocation, 'steamapps', 'common', 'GarrysMod'),
ip: '208.103.169.58:27015'
};
return settings.gmod;
}
async function setGame(game) {
var SteamLocation = await findSteam();
var monoappdatapath = path.join(process.env.APPDATA, 'monolauncher');
var monoappdataex = fs.existsSync(monoappdatapath);
if (!monoappdataex) fs.mkdirSync(monoappdatapath);
var monoappsettingspath = path.join(monoappdatapath, 'settings');
var monoappsettex = fs.existsSync(monoappsettingspath);
if (!monoappsettex) fs.mkdirSync(monoappsettingspath);
var monoappsettingsfilepath = path.join(monoappsettingspath, 'settings.json');
var monoappsfileex = fs.existsSync(monoappsettingsfilepath);
var settings = monoappsfileex ?
JSON.parse(fs.readFileSync(monoappsettingsfilepath).toString()) : {
gmod: path.join(SteamLocation, 'steamapps', 'common', 'GarrysMod'),
game: game || "defgmod",
gamepath: path.join(SteamLocation, 'steamapps', 'common', 'GarrysMod', 'hl2.exe'),
};
if (!settings.game) settings.game = game || 'defgmod';
settings.game = game;
if (settings.game == '64gmod') {
settings.gamepath = path.join(settings.gmod, 'bin', 'win64', 'gmod.exe');
} else if (settings.game == '32gmod') {
settings.gamepath = path.join(settings.gmod, 'bin', 'gmod.exe');
} else if (settings.game == 'defgmod') {
settings.gamepath = path.join(settings.gmod, 'GarrysMod', 'hl2.exe');
}
if (!fs.existsSync(settings.gamepath)) {
return {
success: false,
error: 'Monolauncher was unable to find the game location.'
};
}
try {
fs.writeFileSync(monoappsettingsfilepath, JSON.stringify(settings));
window.webContents.send('game-changed', settings.game);
} catch (e) { }
return {
success: true,
game: settings.game,
gamepath: settings.gamepath
};
}
async function setgmodlocation() {
var location = dialog.showOpenDialogSync(null, {
title: "MonoLauncher - Select Garry's Mod Directory",
properties: ['openDirectory']
});
if (!location) return 'cancelled';
var SteamLocation = await findSteam();
location = location[0];
var locationex = fs.existsSync(location);
if (!locationex) return 'location404';
var folders = fs.readdirSync(location);
if (!folders) return 'failedread';
if (!folders.includes('garrysmod')) return 'notgmod';
var monoappdatapath = path.join(process.env.APPDATA, 'monolauncher');
var monoappdataex = fs.existsSync(monoappdatapath);
if (!monoappdataex) fs.mkdirSync(monoappdatapath);
var monoappsettingspath = path.join(monoappdatapath, 'settings');
var monoappsettex = fs.existsSync(monoappsettingspath);
if (!monoappsettex) fs.mkdirSync(monoappsettingspath);
var monoappsettingsfilepath = path.join(monoappsettingspath, 'settings.json');
var monoappsfileex = fs.existsSync(monoappsettingsfilepath);
var settings = monoappsfileex ?
JSON.parse(fs.readFileSync(monoappsettingsfilepath).toString()) : {
gmod: path.join(SteamLocation, 'steamapps', 'common', 'GarrysMod'),
ip: '208.103.169.58:27015'
};
settings.gmod = location;
try {
fs.writeFileSync(monoappsettingsfilepath, JSON.stringify(settings));
window.webContents.send('gmod-changed', settings.gmod);
} catch (e) { }
return {
success: true,
path: settings.gmod
};
}
async function launchMonolith() {
var GameLocation = await getGame();
var ip = await getServer();
var multicore = await getMultiCore();
if (!GameLocation || !ip || !GameLocation.gamepath || !GameLocation.game) {
const dialogOpts = {
type: 'error',
title: 'Error',
message: "We can't launch Garry's Mod",
detail: 'Hey yeah.. We had some issues trying to start monolith. This could be because either, we couldnt find the server ip or Garry\'s Mods installation path'
};
return dialog.showMessageBox(dialogOpts);
}
StartArgs = [
"+connect", ip
]
if (multicore) {
StartArgs.push("+gmod_mcore_test");
StartArgs.push("1");
}
cp.spawn(`${GameLocation.gamepath}`, StartArgs);
}
// async function getConversations() {
// return new Promise(async (resolve, reject) => {
// var GmodLocation = await getgmodlocation();
// var chatsC = new Collection();
// try {
// var datadir = path.join(GmodLocation, 'garrysmod', 'data');
// var chatdir = path.join(datadir, 'chats');
// var chats = fs.readdirSync(chatdir);
// chats.forEach((chatFile) => {
// var chat = JSON.parse(fs.readFileSync(path.join(chatdir, chatFile)).toString());
// chat.chats = chat.chats.reverse();
// chat.id = chatFile.split('.txt')[0];
// chatsC.set(chatFile.split('.txt')[0], chat);
// });
// resolve(chatsC);
// } catch (e) {
// resolve('404');
// }
// });
// }
function formatMPNumber(number) {
let rnumb = number.replace("7656119", "")
let fnumb = `${rnumb.slice(0, 3)}-${rnumb.slice(3, 6)}-${rnumb.slice(6, 10)}`
return fnumb
}
async function getMPContact(sid, nf) {
return new Promise(async (resolve, reject) => {
var GmodLocation = await getgmodlocation();
var monofolder = path.join(GmodLocation, 'garrysmod', 'data', 'monolith');
if (!fs.existsSync(monofolder)) fs.mkdirSync(monofolder);
var contactfile = path.join(monofolder, 'monophone_contacts.json');
if (!fs.existsSync(contactfile)) fs.writeFileSync(contactfile, JSON.stringify({}));
var contacts = JSON.parse(fs.readFileSync(contactfile).toString());
var rcontact = contacts[sid] || contacts[sid + "_"];
var contact = {}
let steaminfo = await getSteamInfo(sid, nf);
if (!rcontact) {
contact.id = sid.replaceAll("_", "");
contact.number = formatMPNumber(sid);
contact.name = `Unknown | ${contact.number}`;
contact.image = steaminfo.avatar;
} else {
contact.id = sid.replaceAll("_", "");
contact.number = formatMPNumber(sid);
contact.name = `${rcontact.Name} | ${contact.number}`;
contact.image = steaminfo.avatar;
}
resolve(contact)
});
}
async function getMPContacts(nf) {
return new Promise(async (resolve, reject) => {
var GmodLocation = await getgmodlocation();
try {
var monofolder = path.join(GmodLocation, 'garrysmod', 'data', 'monolith');
if (!fs.existsSync(monofolder)) fs.mkdirSync(monofolder);
var contactfile = path.join(monofolder, 'monophone_contacts.json');
if (!fs.existsSync(contactfile)) fs.writeFileSync(contactfile, JSON.stringify({}));
var contacts = JSON.parse(fs.readFileSync(contactfile).toString());
ncontacts = {}
for (let k in contacts) {
k = k.split(".json")[0]
var contact = getMPContact(k)
ncontacts[k] = contact
}
resolve(ncontacts);
} catch (e) {
resolve("404")
}
});
}
async function getMPConversation(sid, nf) {
return new Promise(async (resolve, reject) => {
var GmodLocation = await getgmodlocation();
try {
var monofolder = path.join(GmodLocation, 'garrysmod', 'data', 'monolith');
if (!fs.existsSync(monofolder)) fs.mkdirSync(monofolder);
var conversationfolder = path.join(monofolder, 'mono_message');
if (!fs.existsSync(conversationfolder)) fs.mkdirSync(conversationfolder);
var convo = JSON.parse(fs.readFileSync(path.join(conversationfolder, `${sid}.json`)).toString());
var contact = await getMPContact(sid, nf);
convo.contact = contact;
resolve(convo)
} catch (e) {
resolve("404")
console.error(e)
}
});
}
async function getMPConversations(nf) {
return new Promise(async (resolve, reject) => {
var GmodLocation = await getgmodlocation();
try {
var monofolder = path.join(GmodLocation, 'garrysmod', 'data', 'monolith');
if (!fs.existsSync(monofolder)) fs.mkdirSync(monofolder);
var conversationfolder = path.join(monofolder, 'mono_message');
if (!fs.existsSync(conversationfolder)) fs.mkdirSync(conversationfolder);
var conversations = fs.readdirSync(conversationfolder);
convos = [];
for (let k in conversations) {
var convfile = conversations[k];
var convo = JSON.parse(fs.readFileSync(path.join(conversationfolder, convfile)).toString());
var sid = convfile.split(".json")[0]
var contact = await getMPContact(sid, nf);
convo.contact = contact;
convos.push(convo)
}
resolve(convos)
} catch (e) {
resolve("404")
console.error(e)
}
});
}
function getramusage() {
var owo = os.totalmem() - os.freemem();
var awa = owo / 1024 / 1024 / 1024;
var awo = os.totalmem / 1024 / 1024 / 1024;
return `${awa.toFixed(2)}/${awo.toFixed(2)}GB (${Math.round(awa / awo * 100)}%)`;
}
async function setActivity() {
if (app.isPackaged) {
rpc.setActivity({
details: 'Thinking about joining Monolith',
state: 'Exploring menus',
startTimestamp,
largeImageKey: 'monolith',
largeImageText: 'Monolith Servers',
smallImageKey: 'discord',
smallImageText: 'discord.gg/monolithservers',
buttons: [
{
label: 'Download MonoLauncher',
url: 'https://hazel-jacubrstnc.vercel.app/download'
},
{
label: 'Join the Monolith Discord',
url: 'https://discord.gg/monolithservers'
}
]
});
} else {
rpc.setActivity({
details: 'Adding new features',
state: 'Improving MonoLauncher',
startTimestamp,
largeImageKey: 'monolith',
largeImageText: 'Monolith Servers',
smallImageKey: 'discord',
smallImageText: 'discord.gg/monolithservers',
buttons: [
{
label: 'Download MonoLauncher',
url: 'https://hazel-jacubrstnc.vercel.app/download'
},
{
label: 'Join the Monolith Discord',
url: 'https://discord.gg/monolithservers'
}
]
});
}
}
const createWindow = async () => {
rpc.login({
clientId
}).catch((err) => {
if (err) {
rpc = {
setActivity: function () { },
user: {
username: 'Username',
discriminator: '0000'
}
};
}
});
// Create the browser window.
const mainWindow = new BrowserWindow({
width: 1100,
height: 725,
title: 'MonoLauncher - Launching',
toolbar: false,
frame: false,
autoHideMenuBar: true,
webPreferences: {
nodeIntegration: true,
contextIsolation: false
}
});
mainWindow.setResizable(false);
mainWindow.setMenuBarVisibility(false);
// and load the index.html of the app.
await mainWindow.loadFile(path.join(__dirname, 'launcher.html'));
mainWindow.setTitle('MonoLauncher');
setActivity();
window = mainWindow;
checkForUpdates();
};
// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
app.on('ready', createWindow);
// Quit when all windows are closed, except on macOS. There, it's common
// for applications and their menu bar to stay active until the user quits
// explicitly with Cmd + Q.
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit();
}
});
app.on('activate', () => {
// On OS X it's common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open.
if (BrowserWindow.getAllWindows().length === 0) {
createWindow();
}
});
ipc.on('game-launch', () => {
launchMonolith();
});
ipc.handle('request-ram', async (event) => {
var result = getramusage();
return result;
});
ipc.handle('is-development', async (event) => {
var result = !app.isPackaged;
return result;
});
ipc.handle('request-discord', async (event) => {
var result = `${rpc.user.username}#${rpc.user.discriminator}`;
return result;
});
ipc.handle('request-imsgs', async (event) => {
var result = await getMPConversations();
return result;
});
ipc.handle('request-imsgs-nofetch', async (event, arg) => {
var result = await getMPConversation(arg, true);
return result;
});
ipc.handle('request-gmod', async (event) => {
var result = await getgmodlocation();
return result;
});
ipc.handle('set-gmod', async (event) => {
var result = await setgmodlocation();
return result;
});
ipc.handle('controlbox-action', async (event, arg) => {
switch (arg) {
case `minimize`:
window.isMinimizable() ? window.minimize() : null;
return;
case `close`:
window.isClosable() ? window.close() : null;
return;
default:
return;
}
});
ipc.handle('request-server', async (event) => {
var result = await getServer();
return result;
});
ipc.handle('request-game', async (event) => {
var result = await getGame();
return result;
});
ipc.handle('request-multicore', async (event) => {
var result = await getMultiCore();
return result;
});
ipc.handle('change-server', async (event, arg) => {
var result = await setServer(arg);
return result;
});
ipc.handle('change-game', async (event, arg) => {
var result = await setGame(arg);
return result;
});
ipc.handle('change-multicore', async (event, arg) => {
var result = await setMultiCore(arg);
return result;
});
ipc.handle('steam-avatar', async (event, arg) => {
var response = await getSteamInfo(arg)
return response.avatar;
});
ipc.handle('request-update', async (event) => {
return updateStatus;
})
ipc.on("restartupdate", async () => {
autoUpdater.quitAndInstall();
})
ipc.on('join-discord', async () => {
const secondWindow = new BrowserWindow({
width: 50,
height: 50,
show: false,
title: 'MonoLauncher Discord',
webPreferences: {
nodeIntegration: true,
contextIsolation: true
}
});
secondWindow.loadURL('https://discord.gg/RcAdxHXJ');
secondWindow.setMenuBarVisibility(false);
secondWindow.setTitle('Discord Prompt');
secondWindow.webContents.on('did-finish-load', function () {
secondWindow.show();
secondWindow.hide();
});
});
autoUpdater.on('error', (message) => {
console.error('There was a problem updating the application');
console.error(message);
const dialogOpts = {
type: 'error',
title: 'Application Update Error',
message: 'Error',
detail: message
};
dialog.showMessageBox(dialogOpts);
});
setInterval(setActivity, 16000);
setInterval(checkForUpdates, 60000);