-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathmain.js
78 lines (70 loc) · 2.06 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
const {app, BrowserWindow, ipcMain} = require('electron');
const fetch = require('node-fetch');
console.log( process.env.NODE_ENV );
let is_dev = (process.env.NODE_ENV || '').trim() === 'dev';
app.on('ready', async () => {
const window = new BrowserWindow({
icon: './icon.png',
width: 600,
height: 500,
// useContentSize: true,
title: 'FiveM Launcher',
center: true,
autoHideMenuBar: true,
kiosk: false,
webPreferences: {
nodeIntegration: true,
// contextIsolation: true,
// sandbox: true,
webSecurity: true//true
},
});
window.webContents.on('crashed', () => {
app.relaunch();
app.quit();
});
ipcMain.on('close-app', () => {
console.log('Closing');
app.quit();
});
ipcMain.on('get-request', async (event, arg) => {
try {
event.returnValue = await fetch(arg, {
method: "GET",
mode: 'cors',//'cors' : 'same-origin',
headers: {
"Content-Type": "application/json; charset=utf-8",
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3',
'Accept-Encoding': ' gzip, deflate',
'Accept-Language': 'pl-PL,pl;q=0.9,en-US;q=0.8,en;q=0.7',
'Cache-Control': 'no-cache',
'Connection': 'keep-alive',
'Host': '51.38.140.161:30110',
'Pragma': 'no-cache',
'Upgrade-Insecure-Requests': '1',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.142 Safari/537.36'
},
}).then(res => res.json());
}
catch (e) {
console.error(e);
event.returnValue = {};
}
});
try {
window.loadFile(`${__dirname}/dist/index.html`).catch(console.error);
}
catch(e) {
console.log('Template loading error:', e);
}
window.setMenu(null);
if(is_dev)
window.webContents.openDevTools();
window.webContents.once('dom-ready', () => {
//renderer is loaded
});
});
app.on('window-all-closed', function() {//way to close electron on IOS
if(process.platform !== 'darwin')
app.quit()
});