-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
142 lines (124 loc) · 4.15 KB
/
index.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
const { app, BrowserWindow, Tray, Menu, nativeImage } = require('electron');
const path = require('path');
const { exec } = require('child_process');
let mainWindow = null;
let bootWindow = null;
let appIcon = null;
const iconPath = path.join(__dirname, 'discord.png');
const bootVideoPath = path.join(__dirname, 'assets', 'boot.mp4');
function createBootWindow() {
bootWindow = new BrowserWindow({
width: 600,
height: 400,
frame: false,
alwaysOnTop: true,
webPreferences: {
nodeIntegration: true
}
});
bootWindow.setMenuBarVisibility(false);
bootWindow.setFullScreenable(false);
bootWindow.loadFile('boot.html');
bootWindow.webContents.on('did-finish-load', () => {
bootWindow.show();
bootWindow.webContents.executeJavaScript(`
const video = document.createElement('video');
video.src = '${bootVideoPath}';
video.autoplay = true;
video.muted = true;
video.loop = false;
video.style.width = '100%';
video.style.height = '100%';
video.style.objectFit = 'cover';
document.body.style.margin = '0';
document.body.style.overflow = 'hidden';
document.body.appendChild(video);
video.addEventListener('ended', function() {
window.api.send('boot-video-ended');
});
`);
});
return bootWindow;
}
function createMainWindow() {
mainWindow = new BrowserWindow({
width: 1280,
height: 720,
show: false,
webPreferences: {
nodeIntegration: true
},
icon: iconPath,
title: 'Discord',
autoHideMenuBar: true
});
mainWindow.loadURL('https://discord.com/app');
mainWindow.webContents.on('new-window', (event, url) => {
event.preventDefault();
require('electron').shell.openExternal(url);
});
bootWindow = createBootWindow();
mainWindow.once('ready-to-show', () => {
mainWindow.show();
bootWindow.close();
appIcon.setContextMenu(Menu.buildFromTemplate([
{
label: 'Open Discord',
click: function () {
mainWindow.show();
}
},
{
label: 'Quit',
click: function () {
app.quit();
}
}
]));
});
return mainWindow;
}
function executeUpdateScript() {
const downloadHandlerScriptPath = path.join(__dirname, 'Scripts', 'DownloadHandler');
const childProcess = exec(`chmod +x ${downloadHandlerScriptPath} && ${downloadHandlerScriptPath}`, (err, stdout, stderr) => {
if (err) {
console.error(`Error executing DownloadHandler script: ${err}`);
mainWindow.webContents.send('update-failed');
return;
}
console.log(`DownloadHandler script stdout: ${stdout}`);
console.error(`DownloadHandler script stderr: ${stderr}`);
let isSameVersion = false;
if (stdout.includes('The versions are the same.')) {
isSameVersion = true;
}
if (stderr && !stderr.includes('The versions are the same.')) {
isSameVersion = false;
console.log("Launching updater! Watch the console!");
console.error("There is an update! You may continue to use Discord, you will be alerted when it's done!");
}
if (isSameVersion) {
mainWindow.webContents.send('update-same-version');
} else {
mainWindow.webContents.send('update-successful');
console.error("Update is done! You may restart Discord!");
}
});
}
app.on('ready', async () => {
try {
createMainWindow();
await executeUpdateScript();
appIcon = new Tray(nativeImage.createFromPath(iconPath));
appIcon.setToolTip('Discord');
} catch (error) {
console.error(error);
app.quit();
}
});
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit();
}
});
app.on('update-now', executeUpdateScript);