connect.js
2.06 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
const {remote, ipcRenderer} = require("electron");
const {exec} = require("child_process");
const connect_btn = document.getElementById("connect_btn");
var result;
var ary = new Array();
connect_btn.addEventListener("click", () => {
exec("adb devices", (error, stdout, stderr)=>{
result = stdout;
ary = result.split("\n");
ary = ary.slice(1, -1);
ary.pop();
});
if(ary.length==0){
document.getElementById("status").innerHTML = "None";
document.getElementById("status").style.visibility = "visible";
}
else{
document.querySelector(".container").style.visibility = "visible";
document.getElementById("status").innerHTML = ary.length.toString().concat(" device(s) connected!");
document.getElementById("status").style.visibility = "visible";
for (let index = 0; index < ary.length; index++) {
var name = "connectDevice".concat((index+1).toString());
document.getElementById(name).innerHTML = ary[index].toString();
document.getElementById(name).style.visibility = "visible";
}
}
});
const connectDevice1 = document.getElementById("connectDevice1");
const connectDevice2 = document.getElementById("connectDevice2");
const connectDevice3 = document.getElementById("connectDevice3");
const closeBtn = document.getElementById("closeBtn");
closeBtn.addEventListener("click", () => {
let window = remote.getCurrentWindow();
window.close();
});
connectDevice1.addEventListener("click", ()=>{
var new_ary = new Array();
new_ary = ary[0].split("\t");
ipcRenderer.send(
"device-name",
new_ary[0]
);
let window = remote.getCurrentWindow();
window.close();
})
connectDevice2.addEventListener("click", ()=>{
var new_ary = new Array();
new_ary = ary[1].split("\t");
ipcRenderer.send(
"device-name",
new_ary[0]
);
let window = remote.getCurrentWindow();
window.close();
})
connectDevice3.addEventListener("click", ()=>{
var new_ary = new Array();
new_ary = ary[2].split("\t");
ipcRenderer.send(
"device-name",
new_ary[0]
);
let window = remote.getCurrentWindow();
window.close();
})