-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathmain.js
More file actions
149 lines (131 loc) · 4.33 KB
/
main.js
File metadata and controls
149 lines (131 loc) · 4.33 KB
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
// Modules to control application life and create native browser window
const { app, BrowserWindow } = require('electron');
const { ipcMain } = require('electron/main');
const Promise = require('bluebird');
const fs = require('fs');
const path = require('path');
const yargs = require('yargs/yargs');
global.AppPath = app.getPath('userData');
global.AppData = app.getAppPath();
global.ExecPath = process.execPath;
const { argv, parse } = yargs(process.argv);
const configExists = fs.existsSync(`${AppPath}/config.json`);
if (!configExists) fs.writeFileSync(`${AppPath}/config.json`, JSON.stringify({}));
const initializeApp = require('./lib/startup');
require('./lib/openDirectory');
const state = require('./lib/stateManager');
const { importMap } = require('./lib/customMaps');
require('./lib/manageMapFiles');
const config = require(`${AppPath}/config.json`);
async function createWindow () {
// Create the browser window.
const mainWindow = new BrowserWindow({
width: 790,
height: 550,
minWidth: 790,
minHeight: 305,
// resizable: false,
autoHideMenuBar: true,
show: false,
useContentSize: true,
webPreferences: {
preload: path.join(__dirname, 'preload.js'),
nodeIntegration: true,
enableRemoteModule: true,
},
});
const startupWindow = new BrowserWindow({
width: 400,
height: 200,
resizable: false,
// parent: mainWindow,
fullscreenable: false,
fullscreen: false,
maximizable: false,
// modal: true,
show: false,
frame: false,
webPreferences: {
nodeIntegration: true,
},
});
const findRocketLeagueModal = new BrowserWindow({
width: 400,
height: 200,
resizable: false,
parent: mainWindow,
fullscreenable: false,
fullscreen: false,
maximizable: false,
modal: true,
show: false,
frame: false,
webPreferences: {
nodeIntegration: true,
},
});
state.setState({ mainWindow });
if (!config.customMapDirectory) {
startupWindow.loadFile('./src/intro.html');
// startupWindow.webContents.openDevTools({ mode: 'detach' });
startupWindow.show();
startupWindow.on('close', () => {
if (!state.getFromState('customMapDirectory')) app.quit();
});
} else {
startupWindow.close();
mainWindow.loadFile('src/index.html');
// mainWindow.webContents.openDevTools({ mode: 'detach' });
mainWindow.show();
}
ipcMain.on('locateRocketLeague', () => {
findRocketLeagueModal.loadFile('./src/rocketLeagueDirectoryModal.html');
findRocketLeagueModal.show();
// findRocketLeagueModal.webContents.openDevTools({ mode: 'detach' });
});
ipcMain.on('configLoaded', () => {
mainWindow.loadFile('src/index.html');
// mainWindow.webContents.openDevTools({ mode: 'detach' });
mainWindow.show();
if (!config || !config.rocketLeagueDirectory) {
findRocketLeagueModal.loadFile('./src/rocketLeagueDirectoryModal.html');
findRocketLeagueModal.show();
}
});
// and load the index.html of the app.
// Open the DevTools.
// mainWindow.webContents.openDevTools()
}
const handleArgs = () => {
if (!argv.map) return null;
return importMap(argv.map, state.getFromState('customMapDirectory'));
};
const gotTheLock = app.requestSingleInstanceLock();
const handleSecond = () => {
if (!gotTheLock) return app.quit().then(Promise.delay(500));
app.on('second-instance', (event, commandLine, workingDirectory) => {
const mainWindow = state.getFromState('mainWindow');
if (mainWindow) {
if (mainWindow.isMinimized()) mainWindow.restore();
mainWindow.focus();
}
return importMap(parse(commandLine).allowFileAccessFromFiles, state.getFromState('customMapDirectory'));
});
return null;
};
// 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.
initializeApp()
.then(handleSecond)
.then(handleArgs)
.then(app.whenReady)
.then(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', () => {
app.quit();
});
// In this file you can include the rest of your app's specific main process
// code. You can also put them in separate files and require them here.