inquirer.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. "Remove Installed Apps",
  17. "Quit"
  18. ],
  19. filter: function (val) {
  20. return val.toLowerCase();
  21. },
  22. }, ];
  23. return inquirer.prompt(questions);
  24. },
  25. connectWifi: () => {
  26. const questions = [{
  27. type: "input",
  28. name: "connectWifi",
  29. message: "What is your MiWatch IpAdress?",
  30. }, ];
  31. return inquirer.prompt(questions);
  32. },
  33. removeAppsList: async () => {
  34. const packages = await files.loadPackageList();
  35. const questions = [{
  36. type: "checkbox",
  37. name: "removeAppsList",
  38. message: "What apps do you want to remove?",
  39. choices: packages.apps,
  40. }, ];
  41. return inquirer.prompt(questions);
  42. },
  43. compatibleApps: async () => {
  44. await module.exports.getCompatibleApps()
  45. const appList = []
  46. for (let element of compatibleApps) {
  47. appList.push(element.name)
  48. }
  49. const questions = [{
  50. type: "checkbox",
  51. name: "removeAppsList",
  52. message: "What apps do you want to Install?",
  53. choices: appList,
  54. }, ];
  55. return inquirer.prompt(questions);
  56. },
  57. installedApps: async (installedApps) => {
  58. const questions = [{
  59. type: "checkbox",
  60. name: "removeAppsList",
  61. message: "What Installed apps do you want to remove?",
  62. choices: installedApps,
  63. }, ];
  64. return inquirer.prompt(questions);
  65. },
  66. getCompatibleApps: async () => {
  67. var options = {
  68. method: 'GET',
  69. uri: 'http://kithub.cf/Karl/MiWatchKleaner-APKs/raw/master/compatibleApps.json',
  70. };
  71. await rp(options)
  72. .then(function (response) {
  73. compatibleApps = JSON.parse(response)
  74. })
  75. .catch(function (err) {
  76. console.log('compatibleApps.json Not Found')
  77. });
  78. }
  79. };