forked from Sol-Client/client
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
199 lines (165 loc) · 4.48 KB
/
main.js
File metadata and controls
199 lines (165 loc) · 4.48 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
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
async function run() {
if(require("electron-squirrel-startup")) return;
const fs = require("fs");
const Updater = require("./updater");
const Utils = require("./utils");
const Config = require("./config");
Utils.init();
Config.init(Utils.dataDirectory);
Config.load();
const { app, BrowserWindow, ipcMain, dialog, shell } = require("electron");
ipcMain.on("disableUpdates", async() => {
Config.data.autoUpdate = false;
Config.save();
});
if(Config.data.autoUpdate && await Updater.update()) {
return;
}
const path = require("path");
const msmc = require("msmc");
const hastebin = require("hastebin");
var window;
var canQuit = false;
function createWindow() {
var options = {
width: 800,
height: 650,
icon: __dirname + "/assets/icon.png",
webPreferences: {
preload: path.join(__dirname, "app.js")
},
title: "ProCrafters Client " + Utils.version,
show: false,
backgroundColor: "#1e1e1e"
};
if(Utils.getOsName() == "osx") {
options.titleBarStyle = "hidden";
}
window = new BrowserWindow(options);
window.loadFile("app.html");
window.setMenu(null);
window.on("close", (event) => {
if(!canQuit) {
event.preventDefault();
window.webContents.send("close");
}
});
window.once("ready-to-show", () => window.show());
ipcMain.on("directory", async(event) => {
var result = await dialog.showOpenDialog(window,
{
title: "Select Minecraft Folder",
properties: ["openDirectory" ]
}
);
var file = result.filePaths[0];
if(!result.canceled && file) {
event.sender.send("directory", file);
}
});
ipcMain.on("skinFile", async(event) => {
var result = await dialog.showOpenDialog(window,
{
title: "Select Skin File",
filters: [
{
name: "Minecraft Skins",
extensions: ["png"]
},
{
name: "All Files",
extensions: ["*"]
}
]
}
);
var file = result.filePaths[0];
if(!result.canceled && file) {
event.sender.send("skinFile", file);
}
});
}
ipcMain.on("msa", async(event) => {
msmc.fastLaunch("electron", () => {})
.then((result) => {
event.sender.send("msa", JSON.stringify(result));
});
});
ipcMain.on("crash", async(_event, report, file, optifine) => {
var option = dialog.showMessageBoxSync(window, {
title: "Game Crashed",
message: `The game has crashed.
You may submit a report on GitHub, so it can be fixed.
This may include chat messages.
If you have private messages, try reproducing this issue again.`,
type: "question",
buttons: [
"Do Nothing",
"Open log file",
"Submit a report"
]
});
// Indentation matters.
if(option == 1) {
shell.openPath(file);
}
if(option != 2) {
return;
}
var crashReportText = "Add any applicable crash reports, making sure not to include any personal information. It is most important that you do not include the session id.";
if(report) {
report = report.replace(/\[.*\] \[.*\]: \(Session ID is .{3,}\)/gm, "<censored>");
hasteUrl = await hastebin.createPaste(report, {
raw: true,
contentType: "text/plain",
server: "https://www.toptal.com/developers/hastebin/"
});
hasteUrl = "https://www.toptal.com/developers/hastebin/" + hasteUrl.substring(hasteUrl.lastIndexOf('/') + 1) + ".txt";
crashReportText = `<!-- Do not change this unless you need to. -->
[Game Log on Hastebin](${hasteUrl})`
}
var running = `Running ProCrafters Client v${Utils.version}`;
if(optifine) {
running += " with " + optifine;
}
running += ".";
var url = new URL("https://github.com/1ProCrafters/ProCrafters-Client/issues/new/")
url.searchParams.set("body", `## Description
A description of the problem that is occurring.
## Steps to Reproduce
1. What did you do...
2. ...to crash the game?
## Client Version
${running}
## Logs/Crash Report
${crashReportText}
`);
url.searchParams.set("title", "Short Description")
url.searchParams.set("labels", "bug");
shell.openExternal(url.toString());
});
ipcMain.on("devtools", () => window.webContents.openDevTools());
ipcMain.on("quit", (event, result) => {
if(result) {
canQuit = true;
app.quit();
}
else {
if(dialog.showMessageBoxSync(window, {
title: "Quit Launcher?",
message: "If you quit, the game will be closed.",
type: "question",
buttons: [
"Don't quit",
"Quit game and launcher"
]
}) == 1) {
event.sender.send("quitGame");
}
}
});
app.whenReady().then(() => {
createWindow();
});
}
run();