From 74fa89e795d1dece2ac8c98fb312148679f8cdb5 Mon Sep 17 00:00:00 2001 From: "karl.hudgell" Date: Wed, 29 Apr 2020 09:09:01 +0100 Subject: [PATCH] combative code for connections --- package.json | 10 ++++------ pages/pages.js | 41 +++++++++++++++++++++++++++-------------- 2 files changed, 31 insertions(+), 20 deletions(-) diff --git a/package.json b/package.json index dd244aa..21288f1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "miwatchkleaner2.0", - "version": "2.0.2", + "version": "2.0.3", "description": "MiWatch Cleaning Tool", "main": "app.js", "bin": "app.js", @@ -18,8 +18,6 @@ "chalk": "^4.0.0", "clear": "^0.1.0", "clui": "^0.3.6", - "download-file": "^0.1.5", - "download-file-with-progressbar": "^1.2.3", "figlet": "^1.3.0", "get-files-in": "^1.2.0", "inquirer": "^7.1.0", @@ -27,13 +25,13 @@ "pkg": "^4.4.7", "request-promise-native": "^1.0.8", "shell-exec": "^1.0.2", - "shelljs": "^0.8.4", - "zip": "^1.2.0" + "shelljs": "^0.8.4" }, "pkg": { "scripts": [], "assets": [ - "node_modules/figlet/fonts/Standard.flf" + "node_modules/figlet/fonts/Standard.flf", + "data/packageList.json" ], "targets": [ "node12-linux-x64", diff --git a/pages/pages.js b/pages/pages.js index 9d67669..fd92a5b 100644 --- a/pages/pages.js +++ b/pages/pages.js @@ -18,25 +18,37 @@ module.exports = { let installedAppList common.header('Remove Installed Apps') await shellExec(adbRun + ' shell pm list packages -3').then(async function (result) { - if (process.platform === 'win32' || process.platform === 'win64') { - installedAppList = result.stdout.split('\r\n'); // split string on comma space + if (result.stderr.includes('error')) { + console.log(chalk.red('Device not authorised')) + common.pause(3000) + await shellExec(adbRun + ' kill-server').then(async function (result) { + console.log('Please reconnect to watch') + common.pause(3000) + module.exports.mainMenu() + }) } else { - installedAppList = result.stdout.split('\n'); // split string on comma space - } - installedAppList.splice(-1, 1) - }); - const value = await inquirer.installedApps(installedAppList); + if (process.platform === 'win32' || process.platform === 'win64') { + installedAppList = result.stdout.split('\r\n'); // split string on comma space + installedAppList.splice(-1, 1) + } else { + installedAppList = result.stdout.split('\n'); // split string on comma space + installedAppList.splice(-1, 1) + } + const value = await inquirer.installedApps(installedAppList); - for (let element of value.removeAppsList) { - console.log('Removing ' + element) - const package = element.substring(8) - await shellExec(adbRun + ' uninstall ' + package).then(async function (result) { - console.log(element + ' - ' + result.stdout); - }); - } + for (let element of value.removeAppsList) { + console.log('Removing ' + element) + const package = element.substring(8) + await shellExec(adbRun + ' uninstall ' + package).then(async function (result) { + console.log(element + ' - ' + result.stdout); + }); + } + // }); console.log(chalk.green('Removed Selected User Apps')) await common.pause(2000) module.exports.mainMenu() + } + }) }, compatibleApps: async () => { common.header('Install Compatible Apps') @@ -133,6 +145,7 @@ module.exports = { } else { console.log(chalk.red('MiWatch not found')) await common.pause(2000) + files.writeIpAddress('') console.log(chalk.white('Try Again')) await common.pause(1000) module.exports.connectWifi()