pages.js 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. const chalk = require('chalk');
  2. const common = require('../lib/common');
  3. const inquirer = require('../lib/inquirer');
  4. const files = require('../lib/files')
  5. const logger = require('perfect-logger');
  6. const Language = require("@shypes/language-translator");
  7. const globalVariables = require('../lib/globalVars');
  8. const adb = require('../lib/adb');
  9. logger.info(process.platform + " detected")
  10. if (process.platform === 'win32' || process.platform === 'win64') {
  11. adbRun = 'adb'
  12. } else {
  13. adbRun = './adb'
  14. }
  15. logger.initialize('RunTIme', {
  16. logLevelFile: 0, // Log level for file
  17. logLevelConsole: -1, // Log level for STDOUT/STDERR
  18. logDirectory: 'data/', // Log directory
  19. });
  20. module.exports = {
  21. oneClick: async () => {
  22. common.log('main-menu-item-1')
  23. common.header('main-menu-item-1')
  24. common.print('remove-xiaomi-apps', 'whiteBright')
  25. const removalPackagesList = files.loadPackageList()
  26. for (let package of removalPackagesList.apps) {
  27. await adb.removeXiaomiApk(package)
  28. }
  29. common.print('removal-complete', 'green')
  30. await common.pause(2000)
  31. common.log('removal-complete')
  32. common.log('compatible-apps')
  33. await common.clearApkFolder()
  34. const compatibleApps = await common.getCompatibleAppsList()
  35. console.log(chalk.whiteBright('----------'))
  36. common.print('downloading-compatible-apps', 'whiteBright')
  37. for (const package of compatibleApps) {
  38. if (package.Klean === "X") {
  39. try {
  40. newPacakgeName = package.name.replace(/\s/g, '');
  41. await common.downloadFile(package.url, './data/apps/' + newPacakgeName + '.apk')
  42. logger.info(await Language.get('downloading-latest', 'en') + ' ' + package.name + ' ' + chalk.green(await Language.get('complete', 'en')))
  43. console.log(await Language.get('downloading-latest') + ' ' + package.name + ' ' + await Language.get('complete'))
  44. } catch (error) {
  45. logger.info(await Language.get('downloading-latest', 'en') + ' ' + package.name + ' ' + chalk.red(await Language.get('failed', 'en')))
  46. console.log(await Language.get('downloading-latest') + ' ' + package.name + ' ' + await Language.get('failed'))
  47. }
  48. }
  49. }
  50. const apkList = await files.getListOfAPk('./data/apps')
  51. console.log(chalk.whiteBright('----------'))
  52. common.print('installing-apps', 'whiteBright')
  53. for (let element of apkList) {
  54. await adb.installApk(element)
  55. }
  56. common.dualLog('compatible-apps-installed', 'green')
  57. await common.pause(2000)
  58. module.exports.mainMenu()
  59. },
  60. removeXiaomiApps: async () => {
  61. common.header('main-menu-item-2')
  62. common.log('main-menu-item-2')
  63. const value = await inquirer.removeAppsList();
  64. for (let package of value.removeAppsList) {
  65. await adb.removeXiaomiApk(package)
  66. }
  67. common.dualLog('removal-complete', 'green')
  68. await common.pause(2000)
  69. module.exports.mainMenu()
  70. },
  71. restoreXiaomiApps: async () => {
  72. common.header('main-menu-item-3')
  73. common.log('main-menu-item-3')
  74. const value = await inquirer.removeAppsList();
  75. for (let package of value.removeAppsList) {
  76. await adb.restoreXiaomiApk(package)
  77. }
  78. common.dualLog('restoring-apps-complete', 'green')
  79. await common.pause(2000)
  80. module.exports.mainMenu()
  81. },
  82. installCompatibleApps: async () => {
  83. common.header('main-menu-item-4')
  84. common.log('main-menu-item-4')
  85. const compatibleApps = await common.getCompatibleAppsList()
  86. const value = await inquirer.compatibleApps();
  87. await common.clearApkFolder()
  88. for (let element of value.removeAppsList) {
  89. for (let element2 of compatibleApps) {
  90. if (element === element2.name) {
  91. newName = element.replace(/\s/g, '');
  92. await common.downloadFile(element2.url, './data/apps/' + newName + '.apk')
  93. }
  94. }
  95. }
  96. const apkList = await files.getListOfAPk('./data/apps')
  97. for (let package of apkList) {
  98. common.dualLog('installing', 'whiteBright')
  99. await adb.installApk(package)
  100. }
  101. common.dualLog('compatible-apps-installed', 'green')
  102. await common.pause(2000)
  103. module.exports.mainMenu()
  104. },
  105. restoreAnyApp: async () => {
  106. common.header('main-menu-item-5')
  107. common.log('main-menu-item-5')
  108. const value = await inquirer.restoreAnyApp();
  109. await adb.restoreAnyApk(value)
  110. common.dualLog('restoring-apps-complete', 'green')
  111. await common.pause(2000)
  112. module.exports.mainMenu()
  113. },
  114. removeAnyApp: async () => {
  115. common.header('main-menu-item-6')
  116. common.log('main-menu-item-6')
  117. const value = await inquirer.removeAnyApp();
  118. await adb.restoreAnyApk(value)
  119. common.dualLog('removing-apps-complete', 'green')
  120. await common.pause(2000)
  121. module.exports.mainMenu()
  122. },
  123. batchInstallApps: async () => {
  124. common.header('main-menu-item-7')
  125. common.log('main-menu-item-7')
  126. let apkList = await files.getListOfAPk('./my-apk/')
  127. await files.renameLocalApk(apkList)
  128. apkList = await files.getListOfAPk('./my-apk/')
  129. for (let element of apkList) {
  130. console.log(await Language.get('installing') + ' ' + element)
  131. logger.info(await Language.get('installing') + ' ' + element)
  132. await adb.installApk(element)
  133. }
  134. common.dualLog('batch-install-apps-complete', 'green')
  135. await common.pause(2000)
  136. module.exports.mainMenu()
  137. },
  138. batchRemoveInstalledApps: async () => {
  139. common.header('main-menu-item-8')
  140. common.log('main-menu-item-8')
  141. value = await adb.getInstalledPacakges()
  142. for (let element of value.removeAppsList) {
  143. console.log(await Language.get('removing') + ' ' + element)
  144. logger.info(await Language.get('removing') + ' ' + element)
  145. const package = element.substring(8)
  146. await adb.removeApk(package)
  147. }
  148. common.dualLog('remove-selected-user-apps', 'green')
  149. await common.pause(2000)
  150. module.exports.mainMenu()
  151. },
  152. connectWatch: async () => {
  153. common.header('connect-to-watch')
  154. common.log('connect-to-watch')
  155. const value = await inquirer.connectionType()
  156. connected = await adb.watchConnection(value)
  157. if (connected != true) {
  158. module.exports.connectWatch()
  159. } else {
  160. module.exports.mainMenu()
  161. }
  162. },
  163. selectLanguage: async () => {
  164. common.header('Select Language')
  165. common.log('Select Language')
  166. const v = await inquirer.LanguageSelect()
  167. globalVariables.language = v.selection
  168. module.exports.connectWatch()
  169. },
  170. mainMenu: async () => {
  171. common.header('Main Menu')
  172. const mainMenuSelection = await inquirer.mainMenu();
  173. menu_1 = await Language.get('main-menu-item-1')
  174. menu_2 = await Language.get('main-menu-item-2')
  175. menu_3 = await Language.get('main-menu-item-3')
  176. menu_4 = await Language.get('main-menu-item-4')
  177. menu_5 = await Language.get('main-menu-item-5')
  178. menu_6 = await Language.get('main-menu-item-6')
  179. menu_7 = await Language.get('main-menu-item-7')
  180. menu_8 = await Language.get('main-menu-item-8')
  181. menu_9 = await Language.get('main-menu-item-9')
  182. switch (mainMenuSelection.mainMenu) {
  183. case menu_1.toLowerCase():
  184. module.exports.oneClick()
  185. break;
  186. case menu_2.toLowerCase():
  187. module.exports.removeXiaomiApps()
  188. break;
  189. case menu_3.toLowerCase():
  190. module.exports.restoreXiaomiApps()
  191. break;
  192. case menu_4.toLowerCase():
  193. module.exports.installCompatibleApps()
  194. break;
  195. case menu_5.toLowerCase():
  196. module.exports.restoreAnyApp()
  197. break;
  198. case menu_6.toLowerCase():
  199. module.exports.removeAnyApp()
  200. break;
  201. case menu_7.toLowerCase():
  202. module.exports.batchInstallApps()
  203. break;
  204. case menu_8.toLowerCase():
  205. module.exports.batchRemoveInstalledApps()
  206. break;
  207. case menu_9.toLowerCase():
  208. break;
  209. default:
  210. // code block
  211. }
  212. }
  213. };