-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
230 lines (192 loc) · 5.81 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
228
229
230
const { app, BrowserWindow, dialog, autoUpdater, session, globalShortcut } = require("electron");
const path = require("path");
const process = require('process');
const os = require('os');
require('dotenv').config();
let env = process.env;
if (require("electron-squirrel-startup")) app.quit();
if (process.platform != "darwin") require("update-electron-app")({ repo: "PenguinDimension/CPD-Multi-Client" });
const unhandled = require('electron-unhandled');
const createIssue = require('github-create-issue');
const {corrigirAcentos} = require(path.join(__dirname, "lib/extensions/corrigirAcentos"));
const debugInfo = () => {
/*
let info = `
### Informações da aplicação:
${app.name}: \`v${app.getVersion()}\`
NodeJS: \`v${process.versions.node ?? '0.0.0'}\`
Electron: \`v${process.versions.electron ?? '0.0.0'}\`
### Informações do processo:
Duração: \`${process.uptime()}\` segundos até o erro
Localização: \`${process.cwd()}\`
### Informações do ambiente:
OS: \`${os.type()}\`
Plataforma: \`${os.platform()} (${os.release()})\`
Arch: \`${os.arch()}\`
`;
*/
let info = `
### Informações da aplicação:
<table>
<tr>
<td>${app.name}</td>
<td><code>v${app.getVersion()}</code></td>
</tr>
<tr>
<td>NodeJS</td>
<td><code>v${process.versions.node ?? '0.0.0'}</code></td>
</tr>
<tr>
<td>Electron</td>
<td><code>v${process.versions.electron ?? '0.0.0'}</code></td>
</tr>
</table>
### Informações do processo:
<table>
<tr>
<td>Duração</td>
<td><code>${process.uptime()}</code> segundos até o erro</td>
</tr>
<tr>
<td>Localização</td>
<td><code>${process.cwd()}</code></td>
</tr>
</table>
### Informações do ambiente:
<table>
<tr>
<td>OS</td>
<td><code>${os.type()}</code></td>
</tr>
<tr>
<td>Plataforma</td>
<td><code>${os.platform()} (${os.release()})</code></td>
</tr>
<tr>
<td>Arch</td>
<td><code>${os.arch()}</code></td>
</tr>
</table>
`;
return corrigirAcentos(info);
};
var issue_opts = (error) => {
return {
token: env.GH_TOKEN,
body: `\`\`\`sh\n${error.stack}\n\`\`\`\n\n---\n\n${debugInfo()}`
};
};
function issue_clbk( error, issue, info ) {
if (info) {
console.error( 'Limit: %d', info.limit );
console.error( 'Remaining: %d', info.remaining );
console.error( 'Reset: %s', (new Date( info.reset*1000 )).toISOString() );
}
if (error) {
throw new Error( error.message );
}
console.log(JSON.stringify( issue ));
};
unhandled({
showDialog: true,
reportButton: error => {
createIssue('PenguinDimension/CPD-Multi-Client', 'Novo erro!', issue_opts(error), issue_clbk );
}
});
const pluginPaths = {
win32: path.join(__dirname, "lib/pepflashplayer.dll"),
darwin: path.join(__dirname, "lib/PepperFlashPlayer.plugin"),
linux: path.join(__dirname, "lib/libpepflashplayer.so")
};
if (process.platform === "linux") app.commandLine.appendSwitch("no-sandbox");
const pluginName = pluginPaths[process.platform];
app.commandLine.appendSwitch("ppapi-flash-path", pluginName);
app.commandLine.appendSwitch("ppapi-flash-version", "31.0.0.122");
app.commandLine.appendSwitch("ignore-certificate-errors");
var mainWindow;
function clearCache() {
if (mainWindow && mainWindow !== null) {
mainWindow.webContents.session.clearCache();
mainWindow.webContents.session.clearAuthCache();
mainWindow.webContents.session.clearStorageData();
mainWindow.webContents.session.clearHostResolverCache();
};
};
const createWindow = () => {
// Início - tela carregando
let splashWindow = new BrowserWindow({
width: 600,
height: 320,
frame: false,
transparent: true,
show: false,
icon: path.join(__dirname, "lib/icons/icon.ico") || path.join(__dirname, "lib/icons/icon.png")
});
splashWindow.setMenu(null);
splashWindow.setResizable(false);
splashWindow.loadURL('https://cpdimensions.com/client/carregando');
splashWindow.on("closed", () => (splashWindow = null));
splashWindow.webContents.on("did-finish-load", () => {
splashWindow.show();
});
// Fim - tela carregando
// TELA INICIAL
mainWindow = new BrowserWindow({
useContentSize: false,
show: false,
autoHideMenuBar: true,
width: 960,
height: 540,
icon: path.join(__dirname, "lib/icons/icon.ico") || path.join(__dirname, "lib/icons/icon.png"),
webPreferences: {
plugins: true
}
});
mainWindow.setResizable(true);
mainWindow.webContents.on("did-finish-load", () => {
if (splashWindow) {
splashWindow.close();
mainWindow.show();
};
});
new Promise(resolve => setTimeout(() => {
clearCache();
mainWindow.loadURL(`https://cpdimensions.com`);
title: "";
resolve();
}, 5000));
mainWindow.on('closed', () => (mainWindow = null));
};
if (!app.requestSingleInstanceLock()) return app.quit();
app.on("second-instance", (event, commandLine, workingDirectory) => {
dialog.showMessageBox({
type: "info",
title: "AVISO!",
message: "Você não pode executar mais de 1 instância do nosso cliente multi!"
});
if (mainWindow) {
if (mainWindow.isMinimized()) mainWindow.restore();
mainWindow.focus();
};
});
app.setAsDefaultProtocolClient("cpdm");
app.on("ready", function () {
// if (isThereAnError) return;
createWindow();
globalShortcut.register('Alt+CommandOrControl+B', () => {
mainWindow.loadURL("https://beta.cpdimensions.com");
});
session.defaultSession.webRequest.onBeforeSendHeaders((details, callback) => {
details.requestHeaders['User-Agent'] = `cpdimensions-multi/${app.getVersion()}`;
callback({ cancel: false, requestHeaders: details.requestHeaders });
});
});
app.on("window-all-closed", () => {
app.quit();
});
app.on("activate", () => {
if (BrowserWindow.getAllWindows().length === 0) {
createWindow();
};
});
setInterval(clearCache, 1000*60*30); //Limpar o cache de 30 em 30 minutos