-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
212 lines (199 loc) · 6.37 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
// Modules to control application life and create native browser window
const { app, BrowserWindow, screen, clipboard, dialog } = require("electron");
const shortcut = require("electron-localshortcut");
const path = require("path");
const prompt = require("electron-prompt");
var mainWindow;
let fromlogin = false;
if (process.platform == "win32") {
app.commandLine.appendSwitch("ignore-gpu-blacklist");
app.commandLine.appendSwitch("disable-gpu-vsync");
app.commandLine.appendSwitch("enable-pointer-lock-options");
app.commandLine.appendSwitch("enable-quic");
app.commandLine.appendSwitch("disable-accelerated-video-decode", false);
}
function Init() {
mainWindow = new BrowserWindow({
webPreferences: {
preload: path.join(__dirname, "preload.js"),
},
removeMenu: true,
});
mainWindow.on("close", () => {
mainWindow = null;
if (!fromlogin) {
app.quit();
}
});
mainWindow.setFullScreen(true);
mainWindow.loadURL("https://ev.io/");
if (process.platform == "win32") {
mainWindow.webContents.on("did-finish-load", (event) => {
if (mainWindow.webContents.getURL() == "https://ev.io/user/login") {
mainWindow.loadURL("https://ev.io/");
createNewWindow("https://ev.io/user/login", mainWindow);
}
});
}
function LinkBox() {
function input() {
var myPrompt = prompt({
title: "Join a Private game",
label: "Please enter your Invite link here",
value: paste,
inputAttrs: {
type: "url",
},
type: "input",
});
return myPrompt;
}
}
function ispasted(url) {
mainWindow.loadURL(url);
}
let shortcut1 = "F1";
let shortcut2 = "F2";
if (process.platform == "darwin") {
shortcut1 = "CommandOrControl+" + shortcut1;
shortcut2 = "CommandOrControl+" + shortcut2;
}
shortcut.register(mainWindow, shortcut2, () => {
LinkBox();
//check paste for joining private game
let clipboardText = clipboard.readText();
if (clipboardText.indexOf("ev.io/?game=") === -1) {
clipboardText = "https://ev.io/";
}
ispasted(clipboardText);
});
shortcut.register(mainWindow, shortcut1, () => {
mainWindow.loadURL("https://ev.io/");
});
shortcut.register("ESC", () => {
mainWindow.webContents.executeJavaScript(`
document.exitPointerLock = document.exitPointerLock || document.mozExitPointerLock;
document.exitPointerLock();
`);
});
mainWindow.webContents.on("will-prevent-unload", (event) =>
event.preventDefault()
);
mainWindow.webContents.on("dom-ready", (event) => {
mainWindow.setTitle(`EvClient V${app.getVersion()}`);
event.preventDefault();
});
shortcut.register(mainWindow, "Alt+F4", () => {
app.quit();
});
shortcut.register(mainWindow, "F11", () => {
mainWindow.setSimpleFullScreen(!mainWindow.isSimpleFullScreen());
});
}
function createNewWindow(url, mainWindow) {
const { width, height } = screen.getPrimaryDisplay().workAreaSize;
var win = new BrowserWindow({
width: width * 0.8,
height: height * 0.8,
show: false,
parent: mainWindow,
removeMenu: true,
webPreferences: {
nodeIntegration: true,
},
});
win.setSimpleFullScreen(false);
win.loadURL(url);
win.webContents.on("dom-ready", (event) => {
event.preventDefault();
});
win.webContents.on("will-prevent-unload", (event) => event.preventDefault());
shortcut.register(win, "Alt+F4", () => {
app.quit();
});
win.on("ready-to-show", () => {
setTimeout(() => {
if (!win.isDestroyed()) {
win.show();
}
}, 500);
});
win.webContents.on("did-finish-load", (event) => {
if (win.webContents.getURL() == "https://ev.io/") {
win.close();
setTimeout(() => {
fromlogin = true;
mainWindow.close();
Init();
fromlogin = false;
}, 500);
}
});
}
const { autoUpdater } = require("electron-updater");
console.log("autoUpdater entered");
autoUpdater.logger = require("electron-log");
autoUpdater.logger.transports.file.level = "info";
autoUpdater.checkForUpdates();
autoUpdater.on("checking-for-update", () => {
console.log("Checking for updates...");
});
autoUpdater.on("update-available", (info) => {
const dialogOpts = {
type: "info",
buttons: ["Alright!"],
title: "EvClient Update",
message: "New Version of EvClient has been released",
detail:
"It will be downloaded in the background and notify you when the download is finished.",
};
dialog.showMessageBox(dialogOpts).then((returnValue) => {
if (returnValue.response === 0) console.log("Version message seen");
});
});
autoUpdater.on("update-not-available", () => {
console.log("Version is up-to-date");
});
autoUpdater.on("download-progress", (progressObj) => {
console.log(
`Download Speed: ${progressObj.bytesPerSecond} - Downloaded ${progressObj.transferred} + '/ ${progressObj.total}`
);
});
autoUpdater.on("update-downloaded", (event, releaseNotes, releaseName) => {
const dialogOpts = {
type: "info",
buttons: ["Restart", "Later"],
title: "Application Update",
message: process.platform === "win32" ? releaseNotes : releaseName,
detail:
"A new version has been downloaded. Restart the application to apply the updates.",
};
dialog.showMessageBox(dialogOpts).then((returnValue) => {
if (returnValue.response === 0) autoUpdater.quitAndInstall();
});
});
autoUpdater.on("error", (error) => {
console.log(error);
});
// 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.whenReady().then(() => {
Init();
app.on("activate", function () {
// On macOS 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) Init();
});
});
app.on("browser-window-created", function (e, window) {
window.setMenu(null);
});
// 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", function () {
if (process.platform !== "darwin") 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.