process.switch

This commit is contained in:
karl.hudgell 2020-04-26 12:24:50 +01:00
parent c509ab8969
commit 042df8b69e
2 changed files with 151 additions and 67 deletions

View File

@ -3,14 +3,20 @@ const shellExec = require('shell-exec')
module.exports = { module.exports = {
getListOfAPk: () => { getListOfAPk: () => {
this.apkListToInstall = gfin('./data/apps', matchFiletypes = ["apk"], checkSubDirectories = false) this.apkListToInstall = gfin('./data/apps', matchFiletypes = ["apk"], checkSubDirectories = false)
}, },
installApk: async () => { installApk: async () => {
await module.exports.getListOfAPk() await module.exports.getListOfAPk()
for (let element of this.apkListToInstall) { for (let element of this.apkListToInstall) {
await shellExec('adb install -r ' + element).then(function (result) { if (process.platform === 'win32' || process.platform === 'win64') {
console.log('Installing ' + element + ' - ' + result.stdout); await shellExec('adb install -r ' + element).then(function (result) {
}); console.log('Installing ' + element + ' - ' + result.stdout);
});
} else {
await shellExec('./adb install -r ' + element).then(function (result) {
console.log('Installing ' + element + ' - ' + result.stdout);
});
}
} }
// console.log(chalk.green('Removal Complete')) // console.log(chalk.green('Removal Complete'))
}, },

View File

@ -58,9 +58,15 @@ module.exports = {
for (let element of apkList) { for (let element of apkList) {
console.log('Installing ' + element) console.log('Installing ' + element)
await shellExec('adb install -r ' + element).then(function (result) { if (process.platform === 'win32' || process.platform === 'win64') {
console.log(element + ' - ' + result.stdout); await shellExec('adb install -r ' + element).then(function (result) {
}); console.log(element + ' - ' + result.stdout);
});
} else {
await shellExec('./adb install -r ' + element).then(function (result) {
console.log(element + ' - ' + result.stdout);
});
}
} }
console.log(chalk.green('Compatible Apps Installed')) console.log(chalk.green('Compatible Apps Installed'))
await common.pause(2000) await common.pause(2000)
@ -70,9 +76,15 @@ module.exports = {
common.header('Remove Apps') common.header('Remove Apps')
const value = await inquirer.removeAppsList(); const value = await inquirer.removeAppsList();
for (let element of value.removeAppsList) { for (let element of value.removeAppsList) {
await shellExec('adb shell pm uninstall -k --user 0 ' + element).then(function (result) { if (process.platform === 'win32' || process.platform === 'win64') {
console.log('Removing ' + element + ' - ' + result.stdout); await shellExec('adb shell pm uninstall -k --user 0 ' + element).then(function (result) {
}); console.log('Removing ' + element + ' - ' + result.stdout);
});
} else {
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')) console.log(chalk.green('Removal Complete'))
await common.pause(2000) await common.pause(2000)
@ -82,9 +94,15 @@ module.exports = {
common.header('Restore Apps') common.header('Restore Apps')
const value = await inquirer.removeAppsList(); const value = await inquirer.removeAppsList();
for (let element of value.removeAppsList) { for (let element of value.removeAppsList) {
await shellExec('adb shell cmd package install-existing ' + element).then(function (result) { if (process.platform === 'win32' || process.platform === 'win64') {
console.log('Restoring ' + element + ' - ' + result.stdout); await shellExec('adb shell cmd package install-existing ' + element).then(function (result) {
}); console.log('Restoring ' + element + ' - ' + result.stdout);
});
} else {
await shellExec('./adb shell cmd package install-existing ' + element).then(function (result) {
console.log('Restoring ' + element + ' - ' + result.stdout);
});
}
} }
console.log(chalk.green('Restore Complete')) console.log(chalk.green('Restore Complete'))
await common.pause(2000) await common.pause(2000)
@ -95,63 +113,123 @@ module.exports = {
common.header('Connect Wifi') common.header('Connect Wifi')
if (miwatchData.ipAddress !== "") { if (miwatchData.ipAddress !== "") {
console.log('Trying to connect with stored ipAddress') console.log('Trying to connect with stored ipAddress')
shellExec('adb connect ' + miwatchData.ipAddress).then(async function (result) { if (process.platform === 'win32' || process.platform === 'win64') {
if (result.stdout.includes('unable to connect')) { shellExec('adb connect ' + miwatchData.ipAddress).then(async function (result) {
console.log(chalk.red('MiWatch not found')) if (result.stdout.includes('unable to connect')) {
await common.pause(2000) console.log(chalk.red('MiWatch not found'))
console.log(chalk.white('Try Again')) await common.pause(2000)
files.writeIpAddress('') console.log(chalk.white('Try Again'))
await common.pause(1000) files.writeIpAddress('')
module.exports.connectWifi() await common.pause(1000)
} else if (result.stdout.includes('cannot connect')) { module.exports.connectWifi()
console.log(chalk.red('MiWatch not found')) } else if (result.stdout.includes('cannot connect')) {
await common.pause(2000) console.log(chalk.red('MiWatch not found'))
console.log(chalk.white('Try Again')) await common.pause(2000)
files.writeIpAddress('') console.log(chalk.white('Try Again'))
await common.pause(1000) files.writeIpAddress('')
module.exports.connectWifi() await common.pause(1000)
} else if (result.stdout.includes('cannot resolve host')) { module.exports.connectWifi()
console.log(chalk.red('MiWatch not found')) } else if (result.stdout.includes('cannot resolve host')) {
await common.pause(2000) console.log(chalk.red('MiWatch not found'))
console.log(chalk.white('Try Again')) await common.pause(2000)
files.writeIpAddress('') console.log(chalk.white('Try Again'))
await common.pause(1000) files.writeIpAddress('')
module.exports.connectWifi() await common.pause(1000)
} else { module.exports.connectWifi()
console.log(chalk.green('MiWatch Connected')) } else {
await common.pause(3000) console.log(chalk.green('MiWatch Connected'))
module.exports.mainMenu() await common.pause(3000)
} module.exports.mainMenu()
}).catch() }
}).catch()
} else {
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()
}
} else { } else {
const value = await inquirer.connectWifi(); const value = await inquirer.connectWifi();
const miWatchIpaddress = value.connectWifi const miWatchIpaddress = value.connectWifi
shellExec('adb connect ' + miWatchIpaddress).then(async function (result) { if (process.platform === 'win32' || process.platform === 'win64') {
if (result.stdout.includes('unable to connect')) { shellExec('adb connect ' + miWatchIpaddress).then(async function (result) {
console.log(chalk.red('MiWatch not found')) if (result.stdout.includes('unable to connect')) {
await common.pause(2000) console.log(chalk.red('MiWatch not found'))
console.log(chalk.white('Try Again')) await common.pause(2000)
await common.pause(1000) console.log(chalk.white('Try Again'))
module.exports.connectWifi() await common.pause(1000)
} else if (result.stdout.includes('cannot connect')) { module.exports.connectWifi()
console.log(chalk.red('MiWatch not found')) } else if (result.stdout.includes('cannot connect')) {
await common.pause(2000) console.log(chalk.red('MiWatch not found'))
console.log(chalk.white('Try Again')) await common.pause(2000)
await common.pause(1000) console.log(chalk.white('Try Again'))
module.exports.connectWifi() await common.pause(1000)
} else if (result.stdout.includes('cannot resolve host')) { module.exports.connectWifi()
console.log(chalk.red('MiWatch not found')) } else if (result.stdout.includes('cannot resolve host')) {
await common.pause(2000) console.log(chalk.red('MiWatch not found'))
console.log(chalk.white('Try Again')) await common.pause(2000)
await common.pause(1000) console.log(chalk.white('Try Again'))
module.exports.connectWifi() await common.pause(1000)
} else { module.exports.connectWifi()
console.log(chalk.green('MiWatch Connected')) } else {
files.writeIpAddress(miWatchIpaddress) console.log(chalk.green('MiWatch Connected'))
await common.pause(3000) files.writeIpAddress(miWatchIpaddress)
module.exports.mainMenu() await common.pause(3000)
} module.exports.mainMenu()
}).catch() }
}).catch()
} else {
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()
}
} }
}, },
mainMenu: async () => { mainMenu: async () => {