-
Notifications
You must be signed in to change notification settings - Fork 4
/
prompt.js
105 lines (96 loc) · 2.29 KB
/
prompt.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
/* eslint-disable no-sync */
/* eslint-disable import/no-commonjs */
const inquirer = require("inquirer");
const fs = require("fs");
const path = require("path");
const { adbExec } = require("./adb");
const { flash, check_firmware } = require("./actions");
function show_menu(deviceConnected, sku, carrier) {
const choices = [];
if (deviceConnected) {
choices.push(
{
name: "Flash/extract stock firmware",
value: "flash",
},
{
name: "Check firmwares for my device",
value: "check_firmware",
}
);
}
choices.push({
name: "Exit",
value: "exit",
});
inquirer
.prompt([
{
type: "list",
message: "Select an action",
name: "action",
choices,
},
])
.then((answers) => {
switch (answers.action) {
case "flash":
flash();
break;
case "check_firmware":
check_firmware(sku, carrier);
break;
case "exit":
adbExec({ cmd: "kill-server" });
process.exit(0);
}
});
}
function show_firmwares(firmwares, sku, carrier) {
const menu = {
type: "list",
message: "Select a firmware to download",
name: "firmware",
pageSize: 500,
choices: [],
};
firmwares.forEach((firmware) => {
menu.choices.push({
name:
firmware.carrierName.join(" ") +
" :\n " +
firmware.name.split("_subsi")[0] +
"\n",
value: firmware.url,
});
});
menu.choices.push({
name: "Back to main menu\n",
value: "main_menu",
});
inquirer.prompt(menu).then((answers) => {
if (answers.firmware === "main_menu") {
show_menu(true, sku, carrier);
} else {
const download = require("./download");
if (
!fs.existsSync(
path.resolve("firmware", answers.firmware.split("/").pop())
)
) {
download(
answers.firmware,
path.resolve("firmware", answers.firmware.split("/").pop()),
() => {
console.log("Firmwared downloaded");
show_menu(true, sku, carrier);
}
);
} else {
console.log("Firmware already downloaded");
show_menu(true, sku, carrier);
}
}
});
}
module.exports = { show_menu, show_firmwares };