inquirer.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. const inquirer = require("inquirer");
  2. const files = require("./files");
  3. const rp = require('request-promise-native')
  4. let compatibleApps
  5. module.exports = {
  6. mainMenu: () => {
  7. const questions = [{
  8. type: "list",
  9. name: "mainMenu",
  10. message: "What do you want to do?",
  11. choices: [
  12. "Connect to MiWatch via Wifi",
  13. "Remove Xiaomi Apps",
  14. "Restore Xiaomi Apps",
  15. "Install Compatible Apps",
  16. "Quit"
  17. ],
  18. filter: function (val) {
  19. return val.toLowerCase();
  20. },
  21. }, ];
  22. return inquirer.prompt(questions);
  23. },
  24. connectWifi: () => {
  25. const questions = [{
  26. type: "input",
  27. name: "connectWifi",
  28. message: "What is your MiWatch IpAdress?",
  29. }, ];
  30. return inquirer.prompt(questions);
  31. },
  32. removeAppsList: async () => {
  33. const packages = await files.loadPackageList();
  34. const questions = [{
  35. type: "checkbox",
  36. name: "removeAppsList",
  37. message: "What apps do you want to remove?",
  38. choices: packages.apps,
  39. }, ];
  40. return inquirer.prompt(questions);
  41. },
  42. compatibleApps: async () => {
  43. await module.exports.getCompatibleApps()
  44. const appList = []
  45. for (let element of compatibleApps) {
  46. appList.push(element.name)
  47. }
  48. const questions = [{
  49. type: "checkbox",
  50. name: "removeAppsList",
  51. message: "What apps do you want to remove?",
  52. choices: appList,
  53. }, ];
  54. return inquirer.prompt(questions);
  55. },
  56. getCompatibleApps: async () => {
  57. var options = {
  58. method: 'GET',
  59. uri: 'http://kithub.cf/Karl/MiWatchKleaner-APKs/raw/master/compatibleApps.json',
  60. };
  61. await rp(options)
  62. .then(function (response) {
  63. compatibleApps = JSON.parse(response)
  64. })
  65. .catch(function (err) {
  66. console.log('compatibleApps.json Not Found')
  67. });
  68. }
  69. };