68 lines
2.7 KiB
JavaScript
Raw Normal View History

2020-04-24 21:40:03 +01:00
const chalk = require('chalk');
const common = require('../lib/common');
const inquirer = require('../lib/inquirer');
2020-04-24 22:20:41 +01:00
const shellExec = require('shell-exec')
2020-04-25 10:27:17 +01:00
const files = require('../lib/files')
2020-04-24 21:40:03 +01:00
module.exports = {
2020-04-25 10:44:12 +01:00
removeApps: async () => {
common.header('Remove Apps')
const value = await inquirer.removeAppsList();
2020-04-25 11:06:05 +01:00
value.removeAppsList.forEach(element => {
shellExec('adb shell pm uninstall -k --user 0 ' + element).then(async function (result) {
console.log('Removing ' + element + ' - ' + result.stdout)
}).catch()
});
},
restoreApps: async () => {
common.header('Restore Apps')
const value = await inquirer.removeAppsList();
value.removeAppsList.forEach(element => {
shellExec('adb shell cmd package install-existing ' + element).then(async function (result) {
console.log('Installing ' + element + ' - ' + result.stdout)
}).catch()
});
2020-04-25 10:44:12 +01:00
},
2020-04-24 21:40:03 +01:00
connectWifi: async () => {
2020-04-24 22:55:00 +01:00
common.header('Connect Wifi')
2020-04-25 10:22:47 +01:00
const value = await inquirer.connectWifi();
const miWatchIpaddress = value.connectWifi
2020-04-24 22:55:00 +01:00
shellExec('adb connect ' + miWatchIpaddress).then(async function (result) {
if (result.stdout.includes('unable to connect')) {
2020-04-24 22:20:41 +01:00
console.log(chalk.red('MiWatch not found'))
2020-04-25 10:22:47 +01:00
await common.pause(2000)
console.log(chalk.white('Try Again'))
await common.pause(1000)
module.exports.connectWifi()
} else if (result.stdout.includes('cannot connect')) {
console.log(chalk.red('MiWatch not found'))
await common.pause(2000)
console.log(chalk.white('Try Again'))
await common.pause(1000)
2020-04-24 22:20:41 +01:00
module.exports.connectWifi()
} else {
console.log(chalk.green('MiWatch Connected'))
2020-04-25 10:27:17 +01:00
files.writeIpAddress(miWatchIpaddress)
2020-04-24 22:20:41 +01:00
await common.pause(3000)
module.exports.mainMenu()
}
}).catch()
},
mainMenu: async () => {
2020-04-24 22:55:00 +01:00
common.header('Main Menu')
2020-04-24 22:20:41 +01:00
const mainMenuSelection = await inquirer.mainMenu();
switch (mainMenuSelection.mainMenu) {
2020-04-24 22:55:00 +01:00
case 'connect to miwatch via wifi':
module.exports.connectWifi()
break;
2020-04-25 10:44:12 +01:00
case 'remove install xiaomi apps':
module.exports.removeApps()
2020-04-24 22:55:00 +01:00
break;
2020-04-25 11:06:05 +01:00
case 'restore uninstalled apps':
module.exports.restoreApps()
break;
2020-04-24 22:55:00 +01:00
default:
// code block
2020-04-24 22:20:41 +01:00
}
2020-04-24 22:55:00 +01:00
}
2020-04-24 21:40:03 +01:00
};