Merge branch '2.0' of Karl/MiWatchKleaner into master

This commit is contained in:
Karl 2020-04-26 04:30:59 -05:00 committed by Gogs
commit e6a50ac266
23 changed files with 1823 additions and 438 deletions

4
.gitignore vendored
View File

@ -1 +1,3 @@
data/apps/
node_modules/
data/MiWatch.json
data/apps/*.apk

17
.vscode/launch.json vendored Normal file
View File

@ -0,0 +1,17 @@
{"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "sssas",
// "program": "${workspaceFolder}/bin/test",
"program": "${workspaceFolder}/app.js",
"args": [
"init",
"aasas",
],
"console": "integratedTerminal"
},
],
}

View File

@ -1,403 +0,0 @@
echo off
mode con: cols=85 lines=50
set ch=data\chgcolor.exe
set fast=data\fastboot.exe
set adb=data\adb.exe
echo. && echo. && echo.
%ch% cc
echo ___________________________________________________________________________________
%ch% 00
echo. && echo. && echo. && echo. && echo. && echo. && echo. && echo. && echo. && echo.
echo. && echo. && echo. && echo. && echo. && echo. && echo. && echo. && echo. && echo.
%ch% 0f
echo MiWatchKleaner 1.7
%ch% 00
echo. && echo. && echo. && echo. && echo. && echo. && echo. && echo. && echo. && echo.
echo. && echo. && echo. && echo. && echo. && echo. && echo. && echo. && echo.
%ch% cc
echo ___________________________________________________________________________________
%ch% 0f
Timeout /t 2 >data/null
:START
cls
%ch% 07
echo. && echo. && echo.
%ch% cc
echo ___________________________________________________________________________________
%ch% 0f
echo. && echo. && echo.
echo MiWatchKleaner 1.7
echo.
echo -- MENU --
echo. && echo. && echo. && echo. && echo. && echo. && echo. && echo. && echo.
Timeout /t 1 >data/null
echo _________________________________________________________________________________
echo. && echo.
%ch% 0a
echo 1 - Connect to MiWatch via Wifi
echo.
%ch% 08
%ch% 0f
echo _________________________________________________________________________________
echo. && echo.
%ch% 0a
echo 2 - Remove Installed Xiaomi Apps
echo.
%ch% 08
%ch% 0f
echo _________________________________________________________________________________
echo. && echo.
%ch% 0a
echo 3 - Install Compatible Apps
echo.
%ch% 08
%ch% 0f
echo _________________________________________________________________________________
echo. && echo.
%ch% 0a
echo 4 - Restore Uninstall App
echo.
%ch% 08
%ch% 0f
echo _________________________________________________________________________________
echo. && echo. && echo. && echo. && echo. && echo. && echo. && echo. && echo.
echo E - exit
%ch% cc
echo ___________________________________________________________________________________
%ch% 0f
Timeout /t 1 >data/null
echo Choose an option:
%ch% 00
echo. && choice /c:1234E /M ""
IF %ERRORLEVEL% == 1 GOTO CONNECT
IF %ERRORLEVEL% == 2 GOTO REMOVEAPPS
IF %ERRORLEVEL% == 3 GOTO INSTALLAPPS
IF %ERRORLEVEL% == 4 GOTO REINSTALLAPPS
IF %ERRORLEVEL% == 5 GOTO EXIT
:EXIT
exit
:REMOVEAPPS
cls
%ch% 07
echo. && echo. && echo.
%ch% cc
echo ___________________________________________________________________________________
%ch% 0f
echo. && echo. && echo.
echo.
echo -- REMOVE XIAOMI APPS MENU --
echo. && echo. && echo. && echo. && echo. && echo. && echo. && echo. && echo.
Timeout /t 1 >data/null
echo _________________________________________________________________________________
echo. && echo.
%ch% 0a
echo 1 - Remove Xiaomi Apps and Overlays
echo.
%ch% 08
%ch% 0f
echo _________________________________________________________________________________
echo. && echo.
%ch% 0a
echo 2 - Manual Remove Any Package
echo.
%ch% 08
%ch% 0f
echo _________________________________________________________________________________
echo. && echo.
%ch% 0a
echo 3 - Retrun to Main Menu
echo.
%ch% 08
%ch% 0f
echo _________________________________________________________________________________
echo. && echo. && echo. && echo. && echo. && echo. && echo. && echo. && echo.
echo E - exit
%ch% cc
echo ___________________________________________________________________________________
%ch% 0f
Timeout /t 1 >data/null
echo Choose an option:
%ch% 00
echo. && choice /c:123 /M ""
IF %ERRORLEVEL% == 1 GOTO REMOVEAPP
IF %ERRORLEVEL% == 2 GOTO REMOVEANYAPP
IF %ERRORLEVEL% == 3 GOTO START
:EXIT
exit
:INSTALLAPPS
cls
%ch% 07
echo. && echo. && echo.
%ch% cc
echo ___________________________________________________________________________________
%ch% 0f
echo. && echo. && echo.
echo.
echo -- INSTALL APPS --
echo. && echo. && echo. && echo. && echo. && echo. && echo. && echo. && echo.
Timeout /t 1 >data/null
echo _________________________________________________________________________________
echo. && echo.
%ch% 0a
echo 1 - INSTALL Google Apps
echo (Google Fit, Google Maps, Google Quick Search,
echo Google Translate, Google TTS, WearOs Keyboard)
echo.
%ch% 08
%ch% 0f
echo _________________________________________________________________________________
echo. && echo.
%ch% 0a
echo 2 - INSTALL Other Apps
echo (AccuWeather, Alberto Store, PujieBlack,
echo Ultimate Alexa)
echo.
%ch% 08
%ch% 0f
echo _________________________________________________________________________________
echo. && echo.
%ch% 0a
echo 3 - INSTALL MoreLocale
echo.
%ch% 08
%ch% 0f
echo _________________________________________________________________________________
echo. && echo.
%ch% 0a
echo 4 - Retrun to Main Menu
echo.
%ch% 08
%ch% 0f
echo _________________________________________________________________________________
echo. && echo. && echo. && echo. && echo. && echo. && echo. && echo. && echo.
echo E - exit
%ch% cc
echo ___________________________________________________________________________________
%ch% 0f
Timeout /t 1 >data/null
echo Choose an option:
%ch% 00
echo. && choice /c:123 /M ""
IF %ERRORLEVEL% == 1 GOTO GOOGLE
IF %ERRORLEVEL% == 2 GOTO OTHERS
IF %ERRORLEVEL% == 3 GOTO MORELOCALE
IF %ERRORLEVEL% == 4 GOTO START
:EXIT
exit
:REMOVEAPP
cls
color 47
color 47
%adb% shell pm uninstall -k --user 0 com.xiaomi.wear.calculator && %adb% shell pm uninstall -k --user 0 com.ximalayaos.wear.common && %adb% shell pm uninstall -k --user 0 com.eg.android.AlipayGphone && %adb% shell pm uninstall -k --user 0 com.xiaomi.wear.hotwordle && %adb% shell pm uninstall -k --user 0 com.xiaomi.wear.fitness && %adb% shell pm uninstall -k --user 0 com.xiaomi.wear.watchface.function && %adb% shell pm uninstall -k --user 0 com.xiaomi.wear.watchface.art && %adb% shell pm uninstall -k --user 0 com.xiaomi.wear.watchface.album && %adb% shell pm uninstall -k --user 0 com.xiaomi.wear.watchface.decomposite && %adb% shell pm uninstall -k --user 0 com.xiaomi.wear.watchface.classic && %adb% shell pm uninstall -k --user 0 com.xiaomi.wear.tutorial && %adb% shell pm uninstall -k --user 0 com.xiaomi.wear.deskclock && %adb% shell pm uninstall -k --user 0 com.xiaomi.wear.sportlogger && %adb% shell pm uninstall -k --user 0 com.xiaomi.wear.weather && %adb% shell pm uninstall -k --user 0 com.xiaomi.wear.charging && %adb% shell pm uninstall -k --user 0 com.xiaomi.wear.anonymous.xiaoai && %adb% shell pm uninstall -k --user 0 com.xiaomi.wear.lpa && %adb% shell pm uninstall -k --user 0 com.xiaomi.wear.setupprovider && %adb% shell pm uninstall -k --user 0 com.xiaomi.wear.xiaoai && %adb% shell pm uninstall -k --user 0 com.xiaomi.wear.card && %adb% shell pm uninstall -k --user 0 com.google.android.inputmethod.pinyin && %adb% shell pm uninstall -k --user 0 com.sogou.ime.wear && %adb% shell pm uninstall -k --user 0 com.tencent.qqmusicwatch && %adb% shell pm uninstall -k --user 0 com.sogou.map.android.maps && %adb% shell pm uninstall -k --user 0 com.umetrip.android.msky.app && %adb% shell pm uninstall -k --user 0 com.gotokeep.keep && %adb% shell pm uninstall -k --user 0 com.tigerbrokers.stock
Timeout /t 10 >data/null
%ch% 4F
echo. ******** Apps Removed *****
Timeout /t 2 >data/null
echo.-----------------------------------------------------------------------------------
%ch% 47
Timeout /t 1 >data/null
echo.
echo Press any key to back to MAIN MEMU
%ch% 44
pause
%ch% 00
GOTO START
:CONNECT
cls
color 47
set /p miwatchIp=Please enter MiWatch IP Address:
Timeout /t 5 >data/null
%ch% 4F
%adb% connect %miwatchIp%
Timeout /t 2 >data/null
%adb% devices
echo.-----------------------------------------------------------------------------------
%ch% 47
Timeout /t 1 >data/null
echo.
echo. && echo.
echo Press any key to back to MAIN MEMU
%ch% 44
pause
%ch% 00
GOTO START
:GOOGLE
cls
color 47
echo. Downloading Latest Google Fit
data\wget.exe -q http://kithub.cf/Karl/MiWatchKleaner-APKs/raw/master/Google/GoogleFit.apk -P ./data/apps
echo. Installing Latest Google Fit
%adb% install -r data/apps/GoogleFit.apk
echo. Latest Google Fit Installed
echo. Downloading Latest Google Maps
data\wget.exe -q http://kithub.cf/Karl/MiWatchKleaner-APKs/raw/master/Google/GoogleMaps.apk -P ./data/apps
echo. Installing Latest Google Maps
%adb% install -r data/apps/GoogleMaps.apk
echo. Latest Google Maps Installed
echo. Downloading Latest Google Quick Search
data\wget.exe -q http://kithub.cf/Karl/MiWatchKleaner-APKs/raw/master/Google/GoogleQuickSearch.apk -P ./data/apps
echo. Installing Latest Google Quick Search
%adb% install -r data/apps/GoogleQuickSearch.apk
echo. Latest Google Quick Search Installed
echo. Downloading Latest GoogleTTS
data\wget.exe -q http://kithub.cf/Karl/MiWatchKleaner-APKs/raw/master/Google/GoogleTTS.apk -P ./data/apps
echo. Installing Latest GoogleTTS
%adb% install -r data/apps/GoogleTTS.apk
echo. Latest GoogleTTS Installed
echo. Downloading Latest Google Translate
data\wget.exe -q http://kithub.cf/Karl/MiWatchKleaner-APKs/raw/master/Google/GoogleTranslate.apk -P ./data/apps
echo. Installing Latest Google Translate
%adb% install -r data/apps/GoogleTranslate.apk
echo. Latest Google Translate Installed
echo. Downloading Latest Google Wear Keyboard
data\wget.exe -q http://kithub.cf/Karl/MiWatchKleaner-APKs/raw/master/Google/WearKeyboard.apk -P ./data/apps
echo. Installing Latest Google Wear Keyboard
%adb% install -r data/apps/WearKeyboard.apk
echo. Latest Google Wear Keyboard Installed
echo. Downloading Latest Google Calculator
data\wget.exe -q http://kithub.cf/Karl/MiWatchKleaner-APKs/raw/master/Google/GoogleCalc.apk -P ./data/apps
echo. Installing Latest Google Calculator
%adb% install -r data/apps/GoogleCalc.apk
echo. Latest Google Calculator Installed
echo. Downloading Latest Google Clock
data\wget.exe -q http://kithub.cf/Karl/MiWatchKleaner-APKs/raw/master/Google/GoogleClock.apk -P ./data/apps
echo. Installing Latest Google Clock
%adb% install -r data/apps/GoogleClock.apk
echo. Latest Google Clock Installed
echo. Downloading Latest Google Services
data\wget.exe -q http://kithub.cf/Karl/MiWatchKleaner-APKs/raw/master/Google/GoogleServices.apk -P ./data/apps
echo. Installing Latest Google Services
%adb% install -r data/apps/GoogleServices.apk
echo. Latest Google Services Installed
Timeout /t 5 >data/null
%ch% 4F
del /S data\apps\*.apk
echo. ******** All Google Apps Installed *****
Timeout /t 2 >data/null
echo.-----------------------------------------------------------------------------------
%ch% 47
Timeout /t 1 >data/null
echo.
echo. && echo.
echo. && echo.
echo Press any key to back to MAIN MEMU
%ch% 44
pause
%ch% 00
GOTO START
:OTHERS
cls
color 47
echo. Downloading Latest Pujie Black
data\wget.exe -q http://kithub.cf/Karl/MiWatchKleaner-APKs/raw/master/Others/Pujie.apk -P ./data/apps
echo. Installing Latest Pujie Black
%adb% install -r data/apps/Pujie.apk
echo. Latest Pujie Black Installed
echo. Downloading Latest AccuWeather
data\wget.exe -q http://kithub.cf/Karl/MiWatchKleaner-APKs/raw/master/Others/AccuWeather.apk -P ./data/apps
echo. Installing Latest AccuWeather
%adb% install -r data/apps/AccuWeather.apk
echo. Latest AccuWeather Installed
echo. Downloading Latest Ultimate Alexa
data\wget.exe -q http://kithub.cf/Karl/MiWatchKleaner-APKs/raw/master/Others/UltimateAlexa.apk -P ./data/apps
echo. Installing Latest Ultimate Alexa
%adb% install -r data/apps/UltimateAlexa.apk
echo. Latest Ultimate Alexa Installed
Timeout /t 5 >data/null
%ch% 4F
del /S data\apps\*.apk
echo. ******** Other Apps All Installed *****
Timeout /t 2 >data/null
echo.-----------------------------------------------------------------------------------
%ch% 47
Timeout /t 1 >data/null
echo.
echo. && echo.
echo. && echo.
echo Press any key to back to MAIN MEMU
%ch% 44
pause
%ch% 00
GOTO START
:MORELOCALE
cls
color 47
echo. Downloading Latest MoreLocale
data\wget.exe -q http://kithub.cf/Karl/MiWatchKleaner-APKs/raw/master/Others/MoreLocale.apk -P ./data/apps
echo. Installing Latest MoreLocale
%adb% install -r data/apps/MoreLocale.apk
echo. Latest MoreLocale Installed
echo. Running MoreLocale Config
%adb% shell pm grant jp.co.c_lis.ccl.morelocale android.permission.CHANGE_CONFIGURATION
Timeout /t 5 >data/null
%ch% 4F
del /S data\apps\*.apk
echo. ******** MoreLocale Installed & Enabled *****
Timeout /t 2 >data/null
echo.-----------------------------------------------------------------------------------
%ch% 47
Timeout /t 1 >data/null
echo.
echo. && echo.
echo. && echo.
echo Press any key to back to MAIN MEMU
%ch% 44
pause
%ch% 00
GOTO START
:REINSTALLAPPS
cls
color 47
set /p appToEnable=Please enter app name to re-enable:
Timeout /t 5 >data/null
echo. Re-enabling %appToEnable%
%ch% 4F
%adb% shell cmd package install-existing %appToEnable%
Timeout /t 2 >data/null
echo.-----------------------------------------------------------------------------------
%ch% 47
Timeout /t 1 >data/null
echo.
echo. && echo.
echo. && echo.
echo Press any key to back to MAIN MEMU
%ch% 44
pause
%ch% 00
GOTO START
:REMOVEANYAPP
cls
color 47
set /p appToRemove=Please enter app name to remove:
Timeout /t 5 >data/null
echo. Removing %appToRemove%
%ch% 4F
%adb% shell pm uninstall -k --user 0 %appToRemove%
Timeout /t 2 >data/null
echo.-----------------------------------------------------------------------------------
%ch% 47
Timeout /t 1 >data/null
echo.
echo. && echo.
echo. && echo.
echo Press any key to back to MAIN MEMU
%ch% 44
pause
%ch% 00
GOTO START

View File

@ -1,32 +0,0 @@
Version 1.7
Option to manually remove any package
Version 1.6
Option to re-enable uninstalled applications
Stop removing com.xiaomi.account
Stop removing com.xiaomi.mihome
Stop removing com.xiaomi.wear.market
Version 1.5
Remove com.xiaomi.wear.calculator
Version 1.4
Add Google Clock
Update GoogleQuickSearch
Add Google Services
Version 1.3
Add moreLocale
Version 1.2
Add Google Calculator to Google Install set
Version 1.1
This allows install of working Google and Other Apps.
Google Fit Google Maps Google Quick Search Google Translate Google TTS GBoard Wear Os
AccuWeather Puji Black Ultimate Alexa
Version 1.0
Initial Version

BIN
adb Normal file

Binary file not shown.

BIN
adb.exe Normal file

Binary file not shown.

3
app.js Normal file
View File

@ -0,0 +1,3 @@
const pages = require('./pages/pages')
pages.mainMenu();

1
data/MiWatch.json Normal file
View File

@ -0,0 +1 @@
{"ipAddress":""}

Binary file not shown.

0
data/apps/.gitkeep Normal file
View File

Binary file not shown.

View File

@ -1,2 +0,0 @@
Waiting for 1 seconds, press a key to continue ...0

34
data/packageList.json Normal file
View File

@ -0,0 +1,34 @@
{
"apps": [
"com.xiaomi.wear.calculator",
"com.ximalayaos.wear.common",
"com.eg.android.AlipayGphone",
"com.xiaomi.wear.hotwordle",
"com.xiaomi.wear.fitness",
"com.xiaomi.wear.watchface.function",
"com.xiaomi.wear.watchface.art",
"com.xiaomi.wear.watchface.album",
"com.xiaomi.wear.watchface.decomposite",
"com.xiaomi.wear.watchface.classic",
"com.xiaomi.wear.tutorial",
"com.xiaomi.wear.deskclock",
"com.xiaomi.wear.sportlogger",
"com.xiaomi.wear.weather",
"com.xiaomi.wear.charging",
"com.xiaomi.wear.anonymous.xiaoai",
"com.xiaomi.wear.lpa",
"com.xiaomi.wear.setupprovider",
"com.xiaomi.wear.xiaoai",
"com.xiaomi.wear.card",
"com.google.android.inputmethod.pinyin",
"com.sogou.ime.wear",
"com.tencent.qqmusicwatch",
"com.sogou.map.android.maps",
"com.umetrip.android.msky.app",
"com.gotokeep.keep",
"com.tigerbrokers.stock",
"com.xiaomi.wear.market",
"com.xiaomi.mihome",
"com.xiaomi.account"
]
}

Binary file not shown.

18
lib/adb.js Normal file
View File

@ -0,0 +1,18 @@
const gfin = require('get-files-in')
const shellExec = require('shell-exec')
module.exports = {
getListOfAPk: () => {
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);
});
}
// console.log(chalk.green('Removal Complete'))
},
};

40
lib/common.js Normal file
View File

@ -0,0 +1,40 @@
const chalk = require('chalk');
const clear = require('clear');
const figlet = require('figlet');
const fs = require('fs')
var pjson = require('../package.json');
module.exports = {
header: (page) => {
clear();
console.log(
chalk.red(
figlet.textSync('MiWatch Kleaner', {
horizontalLayout: 'full'
})
)
);
console.log(chalk.red(' ' + pjson.version));
console.log();
console.log(
chalk.red(
'-------------------------------------------------------------------------------------------------------'
)
)
console.log(chalk.blue(page))
module.exports.ipCheck()
console.log(chalk.red('----------'))
},
pause: async (time) => {
await new Promise(resolve => setTimeout(resolve, time));
},
ipCheck: async () => {
const miwatchData = JSON.parse(fs.readFileSync('./data/MiWatch.json', 'utf8'));
if (miwatchData.ipAddress === "") {
console.log(chalk.white('MiWatch IP: ') + chalk.red('Not Connected'))
} else {
console.log(chalk.white('MiWatch IP: ' + chalk.green(miwatchData.ipAddress)))
}
}
}

30
lib/files.js Normal file
View File

@ -0,0 +1,30 @@
const fs = require('fs');
const path = require('path');
module.exports = {
getCurrentDirectoryBase: () => {
return path.basename(process.cwd());
},
directoryExists: (filePath) => {
return fs.existsSync(filePath);
},
writeIpAddress: (value) => {
const data = {
ipAddress: value
}
try {
fs.writeFileSync('./data/MiWatch.json', JSON.stringify(data))
} catch (err) {
console.log(err)
}
},
loadPackageList: () => {
try {
const packageList = JSON.parse(fs.readFileSync('./data/packageList.json', 'utf8'));
return packageList
} catch (err) {
console.log(err)
}
},
}

73
lib/inquirer.js Normal file
View File

@ -0,0 +1,73 @@
const inquirer = require("inquirer");
const files = require("./files");
const rp = require('request-promise-native')
let compatibleApps
module.exports = {
mainMenu: () => {
const questions = [{
type: "list",
name: "mainMenu",
message: "What do you want to do?",
choices: [
"Connect to MiWatch via Wifi",
"Remove Xiaomi Apps",
"Restore Xiaomi Apps",
"Install Compatible Apps",
"Quit"
],
filter: function (val) {
return val.toLowerCase();
},
}, ];
return inquirer.prompt(questions);
},
connectWifi: () => {
const questions = [{
type: "input",
name: "connectWifi",
message: "What is your MiWatch IpAdress?",
}, ];
return inquirer.prompt(questions);
},
removeAppsList: async () => {
const packages = await files.loadPackageList();
const questions = [{
type: "checkbox",
name: "removeAppsList",
message: "What apps do you want to remove?",
choices: packages.apps,
}, ];
return inquirer.prompt(questions);
},
compatibleApps: async () => {
await module.exports.getCompatibleApps()
const appList = []
for (let element of compatibleApps) {
appList.push(element.name)
}
const questions = [{
type: "checkbox",
name: "removeAppsList",
message: "What apps do you want to remove?",
choices: appList,
}, ];
return inquirer.prompt(questions);
},
getCompatibleApps: async () => {
var options = {
method: 'GET',
uri: 'http://kithub.cf/Karl/MiWatchKleaner-APKs/raw/master/compatibleApps.json',
};
await rp(options)
.then(function (response) {
compatibleApps = JSON.parse(response)
})
.catch(function (err) {
console.log('compatibleApps.json Not Found')
});
}
};

1398
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

29
package.json Normal file
View File

@ -0,0 +1,29 @@
{
"name": "miwatchkleaner2.0",
"version": "2.0.0",
"description": "MiWatch Cleaning Tool",
"main": "app.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "http://kithub.cf/Karl/MiWatchKleaner.git"
},
"author": "Karl Hudgell",
"license": "ISC",
"dependencies": {
"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",
"node-downloader-helper": "^1.0.12",
"pkg": "^4.4.7",
"request-promise-native": "^1.0.8",
"shell-exec": "^1.0.2"
}
}

177
pages/pages.js Normal file
View File

@ -0,0 +1,177 @@
const chalk = require('chalk');
const common = require('../lib/common');
const inquirer = require('../lib/inquirer');
const shellExec = require('shell-exec')
const files = require('../lib/files')
const fs = require('fs')
const {
DownloaderHelper
} = require('node-downloader-helper');
const getFilesIn = require('get-files-in')
const http = require('http')
module.exports = {
compatibleApps: async () => {
common.header('Install Compatible Apps')
let compatibleApps
let url = "http://kithub.cf/Karl/MiWatchKleaner-APKs/raw/master/compatibleApps.json";
http.get(url, (res) => {
let body = "";
res.on("data", (chunk) => {
body += chunk;
});
res.on("end", () => {
try {
compatibleApps = JSON.parse(body);
// do something with JSON
} catch (error) {
console.error(error.message);
};
});
}).on("error", (error) => {
console.error(error.message);
});
const value = await inquirer.compatibleApps();
await shellExec('rm ./data/apps/*.apk').then(function (result) {});
for (let element of value.removeAppsList) {
for (let element2 of compatibleApps) {
if (element === element2.name) {
const options = {
override: true,
}
const dl = new DownloaderHelper(element2.url, './data/apps/', options);
dl.on('end', () => console.log('Downloading Latest ' + element2.name + ' Complete'))
await dl.start();
}
}
}
const apkList = await getFilesIn('./data/apps', matchFiletypes = ['apk'], checkSubDirectories = false)
for (let element of apkList) {
console.log('Installing ' + element)
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)
module.exports.mainMenu()
},
removeApps: async () => {
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);
});
}
console.log(chalk.green('Removal Complete'))
await common.pause(2000)
module.exports.mainMenu()
},
restoreApps: async () => {
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);
});
}
console.log(chalk.green('Restore Complete'))
await common.pause(2000)
module.exports.mainMenu()
},
connectWifi: async () => {
const miwatchData = JSON.parse(fs.readFileSync('./data/MiWatch.json', 'utf8'));
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()
} 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()
}
},
mainMenu: async () => {
common.header('Main Menu')
const mainMenuSelection = await inquirer.mainMenu();
switch (mainMenuSelection.mainMenu) {
case 'connect to miwatch via wifi':
module.exports.connectWifi()
break;
case 'remove xiaomi apps':
module.exports.removeApps()
break;
case 'restore xiaomi apps':
module.exports.restoreApps()
break;
case 'install compatible apps':
module.exports.compatibleApps()
break;
case 'quit':
break;
default:
// code block
}
}
};