-
Notifications
You must be signed in to change notification settings - Fork 7
/
renderer.js
295 lines (242 loc) · 11.2 KB
/
renderer.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
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
function updateProgress(percentage) {
const progressStatus = document.querySelector('.progress-status');
if (progressStatus) {
progressStatus.style.width = percentage + '%';
}
const progressText = document.getElementById('progress-text');
if (progressText) {
switch (percentage) {
case 5:
progressText.textContent = '5% - Booting up the oven... 🖥️🔥';
break;
case 15:
progressText.textContent = '15% - Parsing the ingredients... 📝🥣';
break;
case 20:
progressText.textContent = '20% - Laying out code blocks... or brownie blocks! 🧱🍫';
break;
case 25:
progressText.textContent = '25% - Setting the framework (and oven) to optimal temp... ⚙️🌡️';
break;
case 35:
progressText.textContent = '35% - Debugging dough discrepancies! 🐞🍪';
break;
case 40:
progressText.textContent = '40% - Embedding sweet data clusters... 🍬📊';
break;
case 45:
progressText.textContent = '45% - Preheating the compiler... and oven! 💻🔥';
break;
case 50:
progressText.textContent = '50% - Halfway through baking the code! 💾🍕';
break;
case 60:
progressText.textContent = '60% - Layers compiling smoothly... like icing! 🍰💾';
break;
case 70:
progressText.textContent = '70% - Pulling flavor libraries from the pantry... ehm, cloud! ☁️🍩';
break;
case 100:
progressText.textContent = '100% - Code baked flawlessly! Ready for a byte! 🎉🥧';
break;
default:
if (percentage < 50) {
progressText.textContent = percentage + '% 🔄';
} else if (percentage < 100) {
progressText.textContent = percentage + '% ✨';
}
break;
}
}
}
document.addEventListener('DOMContentLoaded', function () {
const coinSelection = document.getElementById('coinSelection');
const selectInstallationPathButton = document.getElementById('select-installation-path');
const selectedPathElement = document.getElementById('selected-path');
const startInstallButton = document.getElementById('startInstallButton');
const toPage2Button = document.getElementById('to-page2');
const backButton2 = document.getElementById('backButton2');
const backButton3 = document.getElementById('backButton3');
const toPage4Button = document.getElementById('to-page4');
const backButton4 = document.getElementById('backButton4');
const outputTextarea = document.getElementById('output');
const coinsList = ["Particl", "Firo", "Monero", "Bitcoin", "Litecoin", "Dash", "PIVX"];
let selectedCoins = {};
let installationPath = '';
const electron = window.electron;
const closeButton = document.getElementById('window-all-closed');
closeButton.addEventListener('click', () => {
electron.closeApp();
});
function showCustomAlert(message) {
let customAlert = document.getElementById('custom-alert');
let customAlertText = document.getElementById('custom-alert-text');
let overlay = document.getElementById('overlay');
customAlertText.textContent = message;
customAlert.style.display = 'flex';
overlay.style.display = 'block';
}
function hideCustomAlert() {
let customAlert = document.getElementById('custom-alert');
let overlay = document.getElementById('overlay');
customAlert.style.display = 'none';
overlay.style.display = 'none';
}
document.getElementById('custom-alert-close').addEventListener('click', hideCustomAlert);
coinsList.forEach((coin) => {
const coinContainer = document.createElement('div');
coinContainer.className = 'coin-container';
const coinImage = document.createElement('img');
coinImage.src = `images/coins/${coin}.png`;
coinImage.alt = coin;
coinImage.width = 20;
coinImage.height = 20;
const coinName = document.createElement('div');
coinName.className = 'coin-name';
coinName.textContent = coin;
if (coin === 'Particl') {
coinContainer.classList.add('default');
coinName.textContent += ' (Default)';
}
if (coin === 'Firo') {
coinContainer.classList.add('disabled');
coinName.textContent += ' (Disabled)';
}
coinContainer.appendChild(coinImage);
coinContainer.appendChild(coinName);
coinSelection.appendChild(coinContainer);
if (coin !== 'Particl' && coin !== 'Firo') {
coinContainer.addEventListener('click', function () {
this.classList.toggle('selected');
selectedCoins[coin] = this.classList.contains('selected');
// Check if Monero is selected
const xmrHeightDiv = document.querySelector('.xmr-height-enabled');
if (selectedCoins["Monero"]) {
xmrHeightDiv.style.display = 'block';
} else {
xmrHeightDiv.style.display = 'none';
}
});
}
});
selectInstallationPathButton.addEventListener('click', async () => {
selectedPathElement.textContent = "Fetching path...";
const result = await electron.selectDirectory();
if (!result.canceled && result.filePaths.length > 0) {
installationPath = result.filePaths[0];
selectedPathElement.textContent = installationPath;
document.getElementById('INSTALL_PATH_1').textContent = installationPath;
document.getElementById('INSTALL_PATH_2').textContent = installationPath;
console.log("Updating INSTALL_PATH with:", installationPath);
} else {
selectedPathElement.textContent = "Path selection canceled";
}
});
toPage2Button.addEventListener('click', function () {
if (installationPath) {
document.getElementById('page1').style.display = 'none';
document.getElementById('page2').style.display = 'block';
} else {
showCustomAlert("Please select the installation path first!");
}
});
backButton2.addEventListener('click', function () {
document.getElementById('page2').style.display = 'none';
document.getElementById('page1').style.display = 'block';
});
startInstallButton.addEventListener('click', function () {
const selectedCoinNames = Object.keys(selectedCoins).filter(coin => selectedCoins[coin]);
if (selectedCoinNames.length > 0) {
document.getElementById('page2').style.display = 'none';
document.getElementById('page3').style.display = 'block';
electron.executePowerShell(installationPath, selectedCoinNames.join(','));
} else {
showCustomAlert("Please select at least one coin to install!");
}
});
backButton3.addEventListener('click', function () {
document.getElementById('page3').style.display = 'none';
document.getElementById('page2').style.display = 'block';
});
toPage4Button.addEventListener('click', function () {
document.getElementById('page3').style.display = 'none';
document.getElementById('page4').style.display = 'block';
});
electron.receivePowerShellOutput((data) => {
console.log('Received data from PowerShell:', data);
const matchProgress = data.match(/PROGRESS:(\d+)/);
if (matchProgress) {
const progress = parseInt(matchProgress[1], 10);
console.log('Progress:', progress);
updateProgress(progress);
} else if (data.includes("IMPORTANT")) {
console.log('Detected IMPORTANT keyword.');
updateProgress(100);
document.getElementById('to-page4').style.display = 'block';
const importantOutputDiv = document.getElementById('important-output');
if (importantOutputDiv) {
const messageDiv = document.createElement('div');
messageDiv.textContent = data;
importantOutputDiv.appendChild(messageDiv);
importantOutputDiv.scrollTop = importantOutputDiv.scrollHeight;
}
}
outputTextarea.value += data;
outputTextarea.scrollTop = outputTextarea.scrollHeight;
});
electron.receivePowerShellError((error) => {
outputTextarea.value += `[ALERT]: ${error}\n`;
outputTextarea.scrollTop = outputTextarea.scrollHeight;
});
electron.receivePowerShellExit((code) => {
outputTextarea.value += `Child process exited with code ${code}\n`;
outputTextarea.scrollTop = outputTextarea.scrollHeight;
});
electron.receiveUpdateProgress((percentage) => {
console.log('Received progress update:', percentage);
updateProgress(percentage);
});
electron.receiveXMRHeightUpdate((height) => {
const importantOutput = document.getElementById('important-output');
importantOutput.textContent = `Current XMR height: ${height}`;
});
function createProgressBar() {
const progressBar = document.createElement('div');
progressBar.className = 'progress-bar';
const progressStatus = document.createElement('div');
progressStatus.className = 'progress-status';
progressBar.appendChild(progressStatus);
return progressBar;
}
});
document.addEventListener('DOMContentLoaded', () => {
const importantOutputDiv = document.getElementById('important-output');
const toggleButton = document.getElementById('toggle-important-output');
const showTextSpan = document.getElementById('show-text');
showTextSpan.innerHTML = '<strong>WARNING:</strong> DO NOT FORGET TO WRITE DOWN THE 24 WORDS RECOVERY PHRASE (SHOW)'; // Set initial value
importantOutputDiv.style.display = 'none';
toggleButton.style.display = 'block';
toggleButton.addEventListener('click', () => {
if (importantOutputDiv.style.display === 'none') {
importantOutputDiv.style.display = 'block';
showTextSpan.innerHTML = '<strong>WARNING:</strong> DO NOT FORGET TO WRITE DOWN THE 24 WORDS RECOVERY PHRASE (HIDE)';
} else {
importantOutputDiv.style.display = 'none';
showTextSpan.innerHTML = '<strong>WARNING:</strong> DO NOT FORGET TO WRITE DOWN THE 24 WORDS RECOVERY PHRASE (SHOW)';
}
});
electron.receivePowerShellOutput((data) => {
if (data.includes('IMPORTANT')) {
data = data.replace('Done.', '');
data = data.replace('IMPORTANT - Save your particl wallet recovery phrase:', '');
const words = data.split(' ');
const wrappedText = words.map(word => `<span class="word">${word}</span>`).join(' ');
importantOutputDiv.innerHTML = wrappedText;
toggleButton.style.display = 'block';
}
});
electron.receiveXMRHeightUpdate((height) => {
const importantOutput = document.getElementById('update-xmr-height');
importantOutput.textContent = `Current XMR height: ${height}`;
});
});