-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.js
executable file
·227 lines (211 loc) · 5.22 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
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
var ua = require("universal-analytics");
var visitor = ua("UA-111374271-3");
visitor.pageview("index.html").send();
const {
app,
BrowserWindow,
Menu,
protocol,
ipcMain,
shell
} = require("electron");
const {
autoUpdater
} = require("electron-updater");
const name = app.getName();
const version = app.getVersion();
const client = require("discord-rich-presence")("434432973362954241");
client.updatePresence({
details: "Running R6RC",
state: 'Calculating matches',
largeImageKey: "r6rc-calc-logo",
instance: true
});
console.log("App initialized on platform: " + process.platform);
let win;
let loadwin;
function createDefaultWindow() {
win = new BrowserWindow({
width: 1280,
height: 720,
minWidth: 1100,
minHeight: 650,
maxWidth: 7680,
maxHeight: 4320,
frame: false,
show: false,
backgroundColor: "#1c1d26",
autoHideMenuBar: true,
webPreferences: {
nodeIntegration: true
}
});
//win.webContents.openDevTools();
win.on("closed", () => {
win = null;
});
win.loadURL(`file://${__dirname}/index.html#v${version}`);
return win;
}
function createLoadWindow() {
loadwin = new BrowserWindow({
width: 500,
height: 300,
frame: false,
resizable: false,
show: false,
backgroundColor: "#1c1d26",
autoHideMenuBar: true,
alwaysontop: true,
webPreferences: {
nodeIntegration: true
}
});
//loadwin.webContents.openDevTools();
loadwin.on("closed", () => {
loadwinwin = null;
});
loadwin.loadURL(`file://${__dirname}/loader.html#v${version}`);
return loadwin;
}
function updateSplashStatus(text) {
loadwin.webContents.send("message", text);
}
let template = [];
// Windows Menu
console.log("Menu loaded for " + name + " on platform: " + process.platform);
template.unshift({
label: name,
submenu: [
{
label: "Join the Discord",
accelerator: "Shift+Control+D",
click() {
console.log("Shift+Control+D has been pressed");
shell.openExternal("https://discord.gg/NaAmbbb");
}
},
{
label: "Learn More",
accelerator: "Control+L",
click() {
console.log("Control+L has been pressed");
shell.openExternal("https://www.github.com/austinleath/r6rc");
}
},
{
label: "Donate",
accelerator: "Control+D",
click() {
console.log("Control+D has been pressed");
shell.openExternal(
"https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=3NS3ZERCW9GD8"
);
}
},
{
label: "Fullscreen",
accelerator: "F11",
click() {
fullScreenModule();
}
},
{
label: "Minimize",
accelerator: "Control+M",
click() {
console.log("Control+M has been pressed");
win.minimize();
}
},
{
label: "Quit",
accelerator: "Control+Q",
click() {
console.log("Control+Q has been pressed");
win.close();
}
}]
});
function fullScreenModule() {
if (win.isFullScreen(true)) {
win.setFullScreen(false);
console.log("Application exited fullscreen");
} else {
win.setFullScreen(true);
console.log("Application entered fullscreen");
}
}
const gotTheLock = app.requestSingleInstanceLock();
if (!gotTheLock) return app.quit();
app.on("second-instance", (event, commandLine, workingDirectory) => {
if (win) {
if (win.isMinimized()) win.restore();
win.focus();
}
});
function isDev(boolean) {
let statusArray = ["[A MEME]", "Error 404: Joke Not Found", "We at pumpkin hill, you ready?", "ULTIMATE IS READY!", "Building Lore", "Wubba Lubba Dub Dub"];
if (boolean) {
createLoadWindow();
createDefaultWindow();
loadwin.show();
win.show();
setInterval(function() {
updateSplashStatus(statusArray[Math.floor(Math.random() * 6)]);
}, 1500);
} else {
createLoadWindow();
setTimeout(function() {
loadwin.show();
autoUpdater.checkForUpdatesAndNotify();
}, 500);
}
}
app.on("ready", () => {
isDev(false);
});
autoUpdater.on("checking-for-update", () => {
updateSplashStatus("Checking for updates");
console.log("Checking for updates");
});
autoUpdater.on("update-available", info => {
updateSplashStatus("Downloading updates");
console.log("Downloading updates");
});
autoUpdater.on("update-not-available", info => {
updateSplashStatus("Up to date, starting R6RC");
console.log("All up to date!");
createDefaultWindow();
const menu = Menu.buildFromTemplate(template);
Menu.setApplicationMenu(menu);
setTimeout(function() {
win.show();
loadwin.destroy();
}, 3500);
});
autoUpdater.on("error", err => {
updateSplashStatus("An unexpected error occurred " + err);
console.log("An unexpected error occurred " + err);
createDefaultWindow();
const menu = Menu.buildFromTemplate(template);
Menu.setApplicationMenu(menu);
setTimeout(function() {
win.show();
loadwin.destroy();
}, 5500);
});
autoUpdater.on("update-downloaded", info => {
updateSplashStatus("Update downloaded, restart to install.");
createDefaultWindow();
const menu = Menu.buildFromTemplate(template);
Menu.setApplicationMenu(menu);
setTimeout(function() {
win.show();
loadwin.destroy();
}, 7000);
});
app.on("window-all-closed", () => {
app.quit();
console.log("Application has been closed successfully");
});