125 lines
5.4 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-25 14:54:31 +01:00
const fs = require('fs')
2020-04-24 21:40:03 +01:00
module.exports = {
2020-04-25 15:35:15 +01:00
compatibleApps: async () => {
common.header('Install Compatible Apps')
const compatibleApps = JSON.parse(fs.readFileSync('./data/compatibleApps.json', 'utf8'));
const value = await inquirer.compatibleApps();
console.log(value)
},
2020-04-25 10:44:12 +01:00
removeApps: async () => {
common.header('Remove Apps')
2020-04-25 14:21:45 +01:00
const value = await inquirer.removeAppsList();
for (let element of value.removeAppsList) {
await shellExec('adb shell pm uninstall -k --user 0 ' + element).then(function (result) {
console.log('Removing ' + element + ' - ' + result.stdout);
});
}
console.log(chalk.green('Removal Complete'))
await common.pause(2000)
module.exports.mainMenu()
2020-04-25 11:06:05 +01:00
},
restoreApps: async () => {
2020-04-25 14:21:45 +01:00
common.header('Remove Apps')
2020-04-25 11:06:05 +01:00
const value = await inquirer.removeAppsList();
2020-04-25 14:21:45 +01:00
for (let element of value.removeAppsList) {
await shellExec('adb shell cmd package install-existing ' + element).then(function (result) {
console.log('Removing ' + element + ' - ' + result.stdout);
});
}
console.log(chalk.green('Restore Complete'))
await common.pause(2000)
module.exports.mainMenu()
2020-04-25 10:44:12 +01:00
},
2020-04-24 21:40:03 +01:00
connectWifi: async () => {
2020-04-25 14:54:31 +01:00
const miwatchData = JSON.parse(fs.readFileSync('./data/MiWatch.json', 'utf8'));
2020-04-24 22:55:00 +01:00
common.header('Connect Wifi')
2020-04-25 14:54:31 +01:00
if (miwatchData.ipAddress !== "") {
2020-04-25 15:09:41 +01:00
console.log('Trying to connect with stored ipAddress')
shellExec('adb connect ' + miwatchData.ipAddress).then(async function (result) {
if (result.stdout.includes('unable to connect')) {
console.log(chalk.red('MiWatch not found'))
await common.pause(2000)
console.log(chalk.white('Try Again'))
files.writeIpAddress('')
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'))
files.writeIpAddress('')
await common.pause(1000)
module.exports.connectWifi()
} else if (result.stdout.includes('cannot resolve host')) {
console.log(chalk.red('MiWatch not found'))
await common.pause(2000)
console.log(chalk.white('Try Again'))
files.writeIpAddress('')
await common.pause(1000)
module.exports.connectWifi()
} else {
console.log(chalk.green('MiWatch Connected'))
await common.pause(3000)
module.exports.mainMenu()
}
}).catch()
2020-04-25 14:54:31 +01:00
} else {
const value = await inquirer.connectWifi();
const miWatchIpaddress = value.connectWifi
shellExec('adb connect ' + miWatchIpaddress).then(async function (result) {
if (result.stdout.includes('unable to connect')) {
console.log(chalk.red('MiWatch not found'))
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)
module.exports.connectWifi()
} else if (result.stdout.includes('cannot resolve host')) {
console.log(chalk.red('MiWatch not found'))
await common.pause(2000)
console.log(chalk.white('Try Again'))
await common.pause(1000)
module.exports.connectWifi()
} else {
console.log(chalk.green('MiWatch Connected'))
files.writeIpAddress(miWatchIpaddress)
await common.pause(3000)
module.exports.mainMenu()
}
}).catch()
}
2020-04-24 22:20:41 +01:00
},
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 11:11:10 +01:00
case 'remove xiaomi apps':
2020-04-25 10:44:12 +01:00
module.exports.removeApps()
2020-04-24 22:55:00 +01:00
break;
2020-04-25 11:11:10 +01:00
case 'restore xiaomi apps':
2020-04-25 11:06:05 +01:00
module.exports.restoreApps()
break;
2020-04-25 15:35:15 +01:00
case 'install compatible apps':
module.exports.compatibleApps()
break;
2020-04-25 14:54:31 +01:00
case 'quit':
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
};