From 042df8b69e40ed7f3fff17154eb95d4152c4ca74 Mon Sep 17 00:00:00 2001 From: "karl.hudgell" Date: Sun, 26 Apr 2020 12:24:50 +0100 Subject: [PATCH] process.switch --- lib/adb.js | 14 +++- pages/pages.js | 204 ++++++++++++++++++++++++++++++++++--------------- 2 files changed, 151 insertions(+), 67 deletions(-) diff --git a/lib/adb.js b/lib/adb.js index bb52f78..e2d6e10 100644 --- a/lib/adb.js +++ b/lib/adb.js @@ -3,14 +3,20 @@ const shellExec = require('shell-exec') module.exports = { getListOfAPk: () => { - this.apkListToInstall = gfin('./data/apps', matchFiletypes = ["apk"], checkSubDirectories = false) + this.apkListToInstall = gfin('./data/apps', matchFiletypes = ["apk"], checkSubDirectories = false) }, installApk: async () => { await module.exports.getListOfAPk() for (let element of this.apkListToInstall) { - await shellExec('adb install -r ' + element).then(function (result) { - console.log('Installing ' + element + ' - ' + result.stdout); - }); + if (process.platform === 'win32' || process.platform === 'win64') { + 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')) }, diff --git a/pages/pages.js b/pages/pages.js index 01e9473..f223c6b 100644 --- a/pages/pages.js +++ b/pages/pages.js @@ -58,9 +58,15 @@ module.exports = { for (let element of apkList) { console.log('Installing ' + element) - await shellExec('adb install -r ' + element).then(function (result) { - console.log(element + ' - ' + result.stdout); - }); + if (process.platform === 'win32' || process.platform === 'win64') { + 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')) await common.pause(2000) @@ -70,9 +76,15 @@ module.exports = { common.header('Remove Apps') 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); - }); + if (process.platform === 'win32' || process.platform === 'win64') { + 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')) await common.pause(2000) @@ -82,9 +94,15 @@ module.exports = { common.header('Restore Apps') const value = await inquirer.removeAppsList(); for (let element of value.removeAppsList) { - await shellExec('adb shell cmd package install-existing ' + element).then(function (result) { - console.log('Restoring ' + element + ' - ' + result.stdout); - }); + if (process.platform === 'win32' || process.platform === 'win64') { + 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')) await common.pause(2000) @@ -95,63 +113,123 @@ module.exports = { common.header('Connect Wifi') if (miwatchData.ipAddress !== "") { 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() + if (process.platform === 'win32' || process.platform === 'win64') { + 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 { + 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 { 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() + if (process.platform === 'win32' || process.platform === 'win64') { + 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() + } 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 () => {