123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333 |
- const chalk = require('chalk');
- const common = require('../lib/common');
- const inquirer = require('../lib/inquirer');
- const files = require('../lib/files')
- const logger = require('perfect-logger');
- const Language = require("@shypes/language-translator");
- const globalVariables = require('../lib/globalVars');
- const adb = require('../lib/adb');
- const settings = require("settings-store");
- logger.info(process.platform + " detected")
- if (process.platform === 'win32' || process.platform === 'win64') {
- adbRun = 'adb'
- } else {
- adbRun = './adb'
- }
- logger.initialize('RunTIme', {
- logLevelFile: 0, // Log level for file
- logLevelConsole: -1, // Log level for STDOUT/STDERR
- logDirectory: 'data/', // Log directory
- });
- module.exports = {
- oneClick: async () => {
- common.log('main-menu-item-1')
- common.header('main-menu-item-1')
- common.print('remove-xiaomi-apps', 'whiteBright')
- const removalPackagesList = await common.getXiaomiAppsList()
- for (let package of removalPackagesList) {
- if (package.klean === "X" || package.global === "X") {
- await adb.removeXiaomiApk(package.name)
- }
- }
- common.print('removal-complete', 'green')
- await common.pause(2000)
- common.log('removal-complete')
- common.log('compatible-apps')
- await common.clearApkFolder()
- const compatibleApps = await common.getCompatibleAppsList()
- console.log(chalk.whiteBright('----------'))
- common.print('downloading-compatible-apps', 'whiteBright')
- for (const package of compatibleApps) {
- if (package.Klean === "X") {
- try {
- newPacakgeName = package.name.replace(/\s/g, '');
- await common.downloadFile(package.url, './data/apps/' + newPacakgeName + '.apk')
- logger.info(await Language.get('downloading-latest', 'en') + ' ' + package.name + ' ' + chalk.green(await Language.get('complete', 'en')))
- console.log(await Language.get('downloading-latest') + ' ' + package.name + ' ' + await Language.get('complete'))
- } catch (error) {
- logger.info(await Language.get('downloading-latest', 'en') + ' ' + package.name + ' ' + chalk.red(await Language.get('failed', 'en')))
- console.log(await Language.get('downloading-latest') + ' ' + package.name + ' ' + await Language.get('failed'))
- }
- }
- }
- const apkList = await files.getListOfAPk('./data/apps')
- console.log(chalk.whiteBright('----------'))
- common.print('installing-apps', 'whiteBright')
- for (let element of apkList) {
- await adb.installApk(element)
- }
- common.dualLog('compatible-apps-installed', 'green')
- await common.pause(2000)
- module.exports.mainMenu()
- },
- removeXiaomiApps: async () => {
- common.header('main-menu-item-2')
- common.log('main-menu-item-2')
- const value = await inquirer.xiaomiAppsList();
- for (let package of value.appList) {
- await adb.removeXiaomiApk(package)
- }
- common.dualLog('removal-complete', 'green')
- await common.pause(2000)
- module.exports.mainMenu()
- },
- restoreXiaomiApps: async () => {
- common.header('main-menu-item-3')
- common.log('main-menu-item-3')
- const value = await inquirer.xiaomiAppsList();
- for (let package of value.appList) {
- await adb.restoreXiaomiApk(package)
- }
- common.dualLog('restoring-apps-complete', 'green')
- await common.pause(2000)
- module.exports.mainMenu()
- },
- installCompatibleApps: async () => {
- common.header('main-menu-item-4')
- common.log('main-menu-item-4')
- const compatibleApps = await common.getCompatibleAppsList()
- const value = await inquirer.compatibleApps();
- await common.clearApkFolder()
- for (let element of value.removeAppsList) {
- for (let element2 of compatibleApps) {
- if (element === element2.name) {
- newName = element.replace(/\s/g, '');
- await common.downloadFile(element2.url, './data/apps/' + newName + '.apk')
- }
- }
- }
- const apkList = await files.getListOfAPk('./data/apps')
- for (let package of apkList) {
- common.dualLog('installing', 'whiteBright')
- await adb.installApk(package)
- }
- common.dualLog('compatible-apps-installed', 'green')
- await common.pause(2000)
- module.exports.mainMenu()
- },
- restoreAnyApp: async () => {
- common.header('main-menu-item-5')
- common.log('main-menu-item-5')
- const value = await inquirer.restoreAnyApp();
- await adb.restoreAnyApk(value)
- common.dualLog('restoring-apps-complete', 'green')
- await common.pause(2000)
- module.exports.mainMenu()
- },
- removeAnyApp: async () => {
- common.header('main-menu-item-6')
- common.log('main-menu-item-6')
- const value = await inquirer.removeAnyApp();
- await adb.restoreAnyApk(value)
- common.dualLog('removing-apps-complete', 'green')
- await common.pause(2000)
- module.exports.mainMenu()
- },
- batchInstallApps: async () => {
- common.header('main-menu-item-7')
- common.log('main-menu-item-7')
- let apkList = await files.getListOfAPk('./my_apk/')
- await files.renameLocalApk(apkList)
- apkList = await files.getListOfAPk('./my_apk/')
- for (let element of apkList) {
- console.log(await Language.get('installing') + ' ' + element)
- logger.info(await Language.get('installing') + ' ' + element)
- await adb.installApk(element)
- }
- common.dualLog('batch-install-apps-complete', 'green')
- await common.pause(2000)
- module.exports.mainMenu()
- },
- batchRemoveInstalledApps: async () => {
- common.header('main-menu-item-8')
- common.log('main-menu-item-8')
- value = await adb.getInstalledPacakges()
- for (let element of value.removeAppsList) {
- console.log(await Language.get('removing') + ' ' + element)
- logger.info(await Language.get('removing') + ' ' + element)
- const package = element.substring(8)
- await adb.removeApk(package)
- }
- common.dualLog('remove-selected-user-apps', 'green')
- await common.pause(2000)
- module.exports.mainMenu()
- },
- changeWatchDPI: async () => {
- common.header('main-menu-item-10')
- common.log('main-menu-item-10')
- const defaultDPI = 320
- const currentDPI = await adb.getCurrentDPI()
- console.log(chalk.white(await Language.get('default-dpi-is') + ' ' + defaultDPI))
- await common.pause(1000)
- console.log(chalk.whiteBright(await Language.get('current-dpi-is') + ' ' + currentDPI))
- if (currentDPI.includes('error')) {
- common.dualLog('failed', 'red')
- await common.pause(2000)
- module.exports.mainMenu()
- } else {
- await common.pause(1000)
- const v = await inquirer.setDPI()
- const setDPIValue = v.setDPI
- const t = await adb.setDPI(setDPIValue)
- common.dualLog('complete', 'green')
- await common.pause(2000)
- module.exports.mainMenu()
- }
- },
- connectWatch: async () => {
- common.header('connect-to-watch')
- common.log('connect-to-watch')
- const value = await inquirer.connectionType()
- await common.pause(1000)
- connected = await adb.watchConnection(value)
- if (connected != true) {
- module.exports.connectWatch()
- } else {
- module.exports.mainMenu()
- }
- },
- selectLanguage: async () => {
- if (await settings.value("Lang") != undefined) {
- common.log(await settings.value("Lang") + " Selected")
- module.exports.connectWatch()
- } else {
- common.header('Select Language')
- common.log('Select Language')
- const v = await inquirer.LanguageSelect()
- settings.setValue("Lang", v.selection)
- }
- },
- globalTheme: async () => {
- const v = await inquirer.globalMenu()
- console.log(v)
- if (v.globalSelection === "enable global theme") {
- common.log('main-menu-item-11')
- common.header('main-menu-item-11')
- common.print('enable-global-theme', 'whiteBright')
- const removalPackagesList = await common.getXiaomiAppsList()
- for (let package of removalPackagesList) {
- if (package.global === "X") {
- await adb.removeXiaomiApk(package.name)
- }
- }
- common.print('removal-complete', 'green')
- await common.pause(2000)
- // common.log('removal-complete')
- // common.log('compatible-apps')
- module.exports.mainMenu()
- } else {
- common.log('main-menu-item-11')
- common.header('main-menu-item-11')
- common.print('disable-global-theme', 'whiteBright')
- const removalPackagesList = await common.getXiaomiAppsList()
- for (let package of removalPackagesList) {
- if (package.global === "X") {
- await adb.restoreXiaomiApk(package.name)
- }
- }
- // common.print('removal-complete', 'green')
- await common.pause(2000)
- // common.log('removal-complete')
- // common.log('compatible-apps')
- module.exports.mainMenu()
- }
- },
- xiaomiApps: async () => {
- const v = await inquirer.xiaomiMenu()
- console.log(v)
- n = await Language.get('main-menu-item-2')
- if (v.xiaomiSelection === n.toLowerCase()) {
- module.exports.removeXiaomiApps()
- } else {
- module.exports.restoreXiaomiApps()
- }
- },
- mainMenu: async () => {
- common.header('Main Menu')
- const mainMenuSelection = await inquirer.mainMenu();
- menu_1 = await Language.get('main-menu-item-1')
- menu_12 = await Language.get('main-menu-item-12')
- menu_4 = await Language.get('main-menu-item-4')
- menu_5 = await Language.get('main-menu-item-5')
- menu_6 = await Language.get('main-menu-item-6')
- menu_7 = await Language.get('main-menu-item-7')
- menu_8 = await Language.get('main-menu-item-8')
- menu_9 = await Language.get('main-menu-item-9')
- menu_10 = await Language.get('main-menu-item-10')
- menu_11 = await Language.get('main-menu-item-11')
- switch (mainMenuSelection.mainMenu) {
- case menu_1.toLowerCase():
- module.exports.oneClick()
- break;
- case menu_12.toLowerCase():
- module.exports.xiaomiApps()
- break;
- // case menu_3.toLowerCase():
- // module.exports.restoreXiaomiApps()
- // break;
- case menu_4.toLowerCase():
- module.exports.installCompatibleApps()
- break;
- case menu_5.toLowerCase():
- module.exports.restoreAnyApp()
- break;
- case menu_6.toLowerCase():
- module.exports.removeAnyApp()
- break;
- case menu_7.toLowerCase():
- module.exports.batchInstallApps()
- break;
- case menu_8.toLowerCase():
- module.exports.batchRemoveInstalledApps()
- break;
- case '-----------------------':
- module.exports.mainMenu()
- break;
- case menu_10.toLowerCase():
- module.exports.changeWatchDPI()
- break;
- case menu_9.toLowerCase():
- process.kill(process.pid)
- break;
- case menu_11.toLowerCase():
- module.exports.globalTheme();
- break;
- default:
- // code block
- }
- }
- };
|