inquirer.js 2.2 KB

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