pages.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  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. const settings = require("settings-store");
  10. logger.info(process.platform + " detected")
  11. if (process.platform === 'win32' || process.platform === 'win64') {
  12. adbRun = 'adb'
  13. } else {
  14. adbRun = './adb'
  15. }
  16. logger.initialize('RunTIme', {
  17. logLevelFile: 0, // Log level for file
  18. logLevelConsole: -1, // Log level for STDOUT/STDERR
  19. logDirectory: 'data/', // Log directory
  20. });
  21. module.exports = {
  22. oneClick: async () => {
  23. common.log('main-menu-item-1')
  24. common.header('main-menu-item-1')
  25. common.print('remove-xiaomi-apps', 'whiteBright')
  26. const removalPackagesList = await common.getXiaomiAppsList()
  27. for (let package of removalPackagesList) {
  28. if (package.klean === "X" || package.global === "X") {
  29. await adb.removeXiaomiApk(package.name)
  30. }
  31. }
  32. common.print('removal-complete', 'green')
  33. await common.pause(2000)
  34. common.log('removal-complete')
  35. common.log('compatible-apps')
  36. await common.clearApkFolder()
  37. const compatibleApps = await common.getCompatibleAppsList()
  38. console.log(chalk.whiteBright('----------'))
  39. common.print('downloading-compatible-apps', 'whiteBright')
  40. for (const package of compatibleApps) {
  41. if (package.Klean === "X") {
  42. try {
  43. newPacakgeName = package.name.replace(/\s/g, '');
  44. await common.downloadFile(package.url, './data/apps/' + newPacakgeName + '.apk')
  45. logger.info(await Language.get('downloading-latest', 'en') + ' ' + package.name + ' ' + chalk.green(await Language.get('complete', 'en')))
  46. console.log(await Language.get('downloading-latest') + ' ' + package.name + ' ' + await Language.get('complete'))
  47. } catch (error) {
  48. logger.info(await Language.get('downloading-latest', 'en') + ' ' + package.name + ' ' + chalk.red(await Language.get('failed', 'en')))
  49. console.log(await Language.get('downloading-latest') + ' ' + package.name + ' ' + await Language.get('failed'))
  50. }
  51. }
  52. }
  53. const apkList = await files.getListOfAPk('./data/apps')
  54. console.log(chalk.whiteBright('----------'))
  55. common.print('installing-apps', 'whiteBright')
  56. for (let element of apkList) {
  57. await adb.installApk(element)
  58. }
  59. common.dualLog('compatible-apps-installed', 'green')
  60. await common.pause(2000)
  61. module.exports.mainMenu()
  62. },
  63. removeXiaomiApps: async () => {
  64. common.header('main-menu-item-2')
  65. common.log('main-menu-item-2')
  66. const value = await inquirer.xiaomiAppsList();
  67. for (let package of value.appList) {
  68. await adb.removeXiaomiApk(package)
  69. }
  70. common.dualLog('removal-complete', 'green')
  71. await common.pause(2000)
  72. module.exports.mainMenu()
  73. },
  74. restoreXiaomiApps: async () => {
  75. common.header('main-menu-item-3')
  76. common.log('main-menu-item-3')
  77. const value = await inquirer.xiaomiAppsList();
  78. for (let package of value.appList) {
  79. await adb.restoreXiaomiApk(package)
  80. }
  81. common.dualLog('restoring-apps-complete', 'green')
  82. await common.pause(2000)
  83. module.exports.mainMenu()
  84. },
  85. installCompatibleApps: async () => {
  86. common.header('main-menu-item-4')
  87. common.log('main-menu-item-4')
  88. const compatibleApps = await common.getCompatibleAppsList()
  89. const value = await inquirer.compatibleApps();
  90. await common.clearApkFolder()
  91. for (let element of value.removeAppsList) {
  92. for (let element2 of compatibleApps) {
  93. if (element === element2.name) {
  94. newName = element.replace(/\s/g, '');
  95. await common.downloadFile(element2.url, './data/apps/' + newName + '.apk')
  96. }
  97. }
  98. }
  99. const apkList = await files.getListOfAPk('./data/apps')
  100. for (let package of apkList) {
  101. common.dualLog('installing', 'whiteBright')
  102. await adb.installApk(package)
  103. }
  104. common.dualLog('compatible-apps-installed', 'green')
  105. await common.pause(2000)
  106. module.exports.mainMenu()
  107. },
  108. restoreAnyApp: async () => {
  109. common.header('main-menu-item-5')
  110. common.log('main-menu-item-5')
  111. const value = await inquirer.restoreAnyApp();
  112. await adb.restoreAnyApk(value)
  113. common.dualLog('restoring-apps-complete', 'green')
  114. await common.pause(2000)
  115. module.exports.mainMenu()
  116. },
  117. removeAnyApp: async () => {
  118. common.header('main-menu-item-6')
  119. common.log('main-menu-item-6')
  120. const value = await inquirer.removeAnyApp();
  121. await adb.restoreAnyApk(value)
  122. common.dualLog('removing-apps-complete', 'green')
  123. await common.pause(2000)
  124. module.exports.mainMenu()
  125. },
  126. batchInstallApps: async () => {
  127. common.header('main-menu-item-7')
  128. common.log('main-menu-item-7')
  129. let apkList = await files.getListOfAPk('./my_apk/')
  130. await files.renameLocalApk(apkList)
  131. apkList = await files.getListOfAPk('./my_apk/')
  132. for (let element of apkList) {
  133. console.log(await Language.get('installing') + ' ' + element)
  134. logger.info(await Language.get('installing') + ' ' + element)
  135. await adb.installApk(element)
  136. }
  137. common.dualLog('batch-install-apps-complete', 'green')
  138. await common.pause(2000)
  139. module.exports.mainMenu()
  140. },
  141. batchRemoveInstalledApps: async () => {
  142. common.header('main-menu-item-8')
  143. common.log('main-menu-item-8')
  144. value = await adb.getInstalledPacakges()
  145. for (let element of value.removeAppsList) {
  146. console.log(await Language.get('removing') + ' ' + element)
  147. logger.info(await Language.get('removing') + ' ' + element)
  148. const package = element.substring(8)
  149. await adb.removeApk(package)
  150. }
  151. common.dualLog('remove-selected-user-apps', 'green')
  152. await common.pause(2000)
  153. module.exports.mainMenu()
  154. },
  155. changeWatchDPI: async () => {
  156. common.header('main-menu-item-10')
  157. common.log('main-menu-item-10')
  158. const defaultDPI = 320
  159. const currentDPI = await adb.getCurrentDPI()
  160. console.log(chalk.white(await Language.get('default-dpi-is') + ' ' + defaultDPI))
  161. await common.pause(1000)
  162. console.log(chalk.whiteBright(await Language.get('current-dpi-is') + ' ' + currentDPI))
  163. if (currentDPI.includes('error')) {
  164. common.dualLog('failed', 'red')
  165. await common.pause(2000)
  166. module.exports.mainMenu()
  167. } else {
  168. await common.pause(1000)
  169. const v = await inquirer.setDPI()
  170. const setDPIValue = v.setDPI
  171. const t = await adb.setDPI(setDPIValue)
  172. common.dualLog('complete', 'green')
  173. await common.pause(2000)
  174. module.exports.mainMenu()
  175. }
  176. },
  177. connectWatch: async () => {
  178. common.header('connect-to-watch')
  179. common.log('connect-to-watch')
  180. const value = await inquirer.connectionType()
  181. await common.pause(1000)
  182. connected = await adb.watchConnection(value)
  183. if (connected != true) {
  184. module.exports.connectWatch()
  185. } else {
  186. module.exports.mainMenu()
  187. }
  188. },
  189. selectLanguage: async () => {
  190. if (await settings.value("Lang") != undefined) {
  191. common.log(await settings.value("Lang") + " Selected")
  192. module.exports.connectWatch()
  193. } else {
  194. common.header('Select Language')
  195. common.log('Select Language')
  196. const v = await inquirer.LanguageSelect()
  197. settings.setValue("Lang", v.selection)
  198. }
  199. },
  200. globalTheme: async () => {
  201. const v = await inquirer.globalMenu()
  202. console.log(v)
  203. if (v.globalSelection === "enable global theme") {
  204. common.log('main-menu-item-11')
  205. common.header('main-menu-item-11')
  206. common.print('enable-global-theme', 'whiteBright')
  207. const removalPackagesList = await common.getXiaomiAppsList()
  208. for (let package of removalPackagesList) {
  209. if (package.global === "X") {
  210. await adb.removeXiaomiApk(package.name)
  211. }
  212. }
  213. common.print('removal-complete', 'green')
  214. await common.pause(2000)
  215. // common.log('removal-complete')
  216. // common.log('compatible-apps')
  217. module.exports.mainMenu()
  218. } else {
  219. common.log('main-menu-item-11')
  220. common.header('main-menu-item-11')
  221. common.print('disable-global-theme', 'whiteBright')
  222. const removalPackagesList = await common.getXiaomiAppsList()
  223. for (let package of removalPackagesList) {
  224. if (package.global === "X") {
  225. await adb.restoreXiaomiApk(package.name)
  226. }
  227. }
  228. // common.print('removal-complete', 'green')
  229. await common.pause(2000)
  230. // common.log('removal-complete')
  231. // common.log('compatible-apps')
  232. module.exports.mainMenu()
  233. }
  234. },
  235. xiaomiApps: async () => {
  236. const v = await inquirer.xiaomiMenu()
  237. console.log(v)
  238. n = await Language.get('main-menu-item-2')
  239. if (v.xiaomiSelection === n.toLowerCase()) {
  240. module.exports.removeXiaomiApps()
  241. } else {
  242. module.exports.restoreXiaomiApps()
  243. }
  244. },
  245. mainMenu: async () => {
  246. common.header('Main Menu')
  247. const mainMenuSelection = await inquirer.mainMenu();
  248. menu_1 = await Language.get('main-menu-item-1')
  249. menu_12 = await Language.get('main-menu-item-12')
  250. menu_4 = await Language.get('main-menu-item-4')
  251. menu_5 = await Language.get('main-menu-item-5')
  252. menu_6 = await Language.get('main-menu-item-6')
  253. menu_7 = await Language.get('main-menu-item-7')
  254. menu_8 = await Language.get('main-menu-item-8')
  255. menu_9 = await Language.get('main-menu-item-9')
  256. menu_10 = await Language.get('main-menu-item-10')
  257. menu_11 = await Language.get('main-menu-item-11')
  258. switch (mainMenuSelection.mainMenu) {
  259. case menu_1.toLowerCase():
  260. module.exports.oneClick()
  261. break;
  262. case menu_12.toLowerCase():
  263. module.exports.xiaomiApps()
  264. break;
  265. // case menu_3.toLowerCase():
  266. // module.exports.restoreXiaomiApps()
  267. // break;
  268. case menu_4.toLowerCase():
  269. module.exports.installCompatibleApps()
  270. break;
  271. case menu_5.toLowerCase():
  272. module.exports.restoreAnyApp()
  273. break;
  274. case menu_6.toLowerCase():
  275. module.exports.removeAnyApp()
  276. break;
  277. case menu_7.toLowerCase():
  278. module.exports.batchInstallApps()
  279. break;
  280. case menu_8.toLowerCase():
  281. module.exports.batchRemoveInstalledApps()
  282. break;
  283. case '-----------------------':
  284. module.exports.mainMenu()
  285. break;
  286. case menu_10.toLowerCase():
  287. module.exports.changeWatchDPI()
  288. break;
  289. case menu_9.toLowerCase():
  290. process.kill(process.pid)
  291. break;
  292. case menu_11.toLowerCase():
  293. module.exports.globalTheme();
  294. break;
  295. default:
  296. // code block
  297. }
  298. }
  299. };