pages.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. const chalk = require('chalk');
  2. const common = require('../lib/common');
  3. const inquirer = require('../lib/inquirer');
  4. const shellExec = require('shell-exec')
  5. const files = require('../lib/files')
  6. module.exports = {
  7. removeApps: async () => {
  8. common.header('Remove Apps')
  9. const value = await inquirer.removeAppsList();
  10. value.removeAppsList.forEach(async (element) => {
  11. await shellExec('adb shell pm uninstall -k --user 0 ' + element).then(async function (result) {
  12. console.log('Removing ' + element + ' - ' + result.stdout)
  13. }).catch()
  14. });
  15. console.log('complete')
  16. },
  17. restoreApps: async () => {
  18. common.header('Restore Apps')
  19. const value = await inquirer.removeAppsList();
  20. value.removeAppsList.forEach(element => {
  21. shellExec('adb shell cmd package install-existing ' + element).then(async function (result) {
  22. console.log('Installing ' + element + ' - ' + result.stdout)
  23. }).catch()
  24. });
  25. },
  26. connectWifi: async () => {
  27. common.header('Connect Wifi')
  28. const value = await inquirer.connectWifi();
  29. const miWatchIpaddress = value.connectWifi
  30. shellExec('adb connect ' + miWatchIpaddress).then(async function (result) {
  31. if (result.stdout.includes('unable to connect')) {
  32. console.log(chalk.red('MiWatch not found'))
  33. await common.pause(2000)
  34. console.log(chalk.white('Try Again'))
  35. await common.pause(1000)
  36. module.exports.connectWifi()
  37. } else if (result.stdout.includes('cannot connect')) {
  38. console.log(chalk.red('MiWatch not found'))
  39. await common.pause(2000)
  40. console.log(chalk.white('Try Again'))
  41. await common.pause(1000)
  42. module.exports.connectWifi()
  43. } else {
  44. console.log(chalk.green('MiWatch Connected'))
  45. files.writeIpAddress(miWatchIpaddress)
  46. await common.pause(3000)
  47. module.exports.mainMenu()
  48. }
  49. }).catch()
  50. },
  51. mainMenu: async () => {
  52. common.header('Main Menu')
  53. const mainMenuSelection = await inquirer.mainMenu();
  54. switch (mainMenuSelection.mainMenu) {
  55. case 'connect to miwatch via wifi':
  56. module.exports.connectWifi()
  57. break;
  58. case 'remove xiaomi apps':
  59. module.exports.removeApps()
  60. break;
  61. case 'restore xiaomi apps':
  62. module.exports.restoreApps()
  63. break;
  64. default:
  65. // code block
  66. }
  67. }
  68. };