-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
49 lines (40 loc) · 1.38 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
function sendToBackend(formData) {
window.localApi.sendNodeForm(formData);
}
const nodeName = document.querySelector('#node-name');
const nodePort = document.querySelector('#node-port');
const nodeRpc = document.querySelector('#node-rpc');
const selectDir = document.querySelector('#select-dir');
const submit = document.querySelector('#submit');
selectDir.addEventListener('click', () => {
window.localApi.sendAction('open-directory-dialog');
//ipcRenderer.send('action', 'open-directory-dialog');
});
window.localApi.onSelectedDirectory(path => {
document.getElementById('node-name').value = path;
});
submit.addEventListener('click', (event) => {
event.preventDefault();
if (!nodeName.value) {
alert('Node name is required');
return;
}
const formData = {
nodeName: nodeName.value,
nodePort: nodePort.value || null,
nodeRpc: nodeRpc.value || null
};
sendToBackend(formData);
checkAndRedirect((nodePort.value) ? nodePort.value : '8080');
});
function checkAndRedirect(port) {
console.log(`Redirecting to http://localhost:${port}`);
fetch(`http://localhost:${port}`, { mode: 'no-cors' })
.then(() => {
window.localApi.sendGoHome(port);
//ipcRenderer.send('go-home', port);
})
.catch(() => {
setTimeout(() => checkAndRedirect(port), 1000);
});
}