code cleanup
This commit is contained in:
parent
d7662cbac4
commit
b9a5570680
178
pages/pages.js
178
pages/pages.js
@ -11,6 +11,7 @@ const getFilesIn = require('get-files-in')
|
|||||||
const http = require('http')
|
const http = require('http')
|
||||||
var shell = require('shelljs');
|
var shell = require('shelljs');
|
||||||
|
|
||||||
|
let adbRun
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
removeCompatibleApps: async () => {
|
removeCompatibleApps: async () => {
|
||||||
@ -36,30 +37,17 @@ module.exports = {
|
|||||||
}).on("error", (error) => {
|
}).on("error", (error) => {
|
||||||
console.error(error.message);
|
console.error(error.message);
|
||||||
});
|
});
|
||||||
|
|
||||||
const value = await inquirer.compatibleApps();
|
const value = await inquirer.compatibleApps();
|
||||||
|
|
||||||
for (let element of value.removeAppsList) {
|
for (let element of value.removeAppsList) {
|
||||||
console.log('Installing ' + element)
|
console.log('Installing ' + element)
|
||||||
if (process.platform === 'win32' || process.platform === 'win64') {
|
await shellExec(adbRun + ' install -r ' + element).then(async function (result) {
|
||||||
await shellExec('adb install -r ' + element).then(async function (result) {
|
console.log(element + ' - ' + result.stdout);
|
||||||
console.log(element + ' - ' + result.stdout);
|
if (element === "data\\apps\\MoreLocale.apk") {
|
||||||
if (element === "data\\apps\\MoreLocale.apk") {
|
await shellExec(adbRun + ' shell pm grant jp.co.c_lis.ccl.morelocale android.permission.CHANGE_CONFIGURATION').then(function (result) {
|
||||||
await shellExec('adb shell pm grant jp.co.c_lis.ccl.morelocale android.permission.CHANGE_CONFIGURATION').then(function (result) {
|
console.log('moreLocale Activated On Watch');
|
||||||
console.log('moreLocale Activated On Watch');
|
});
|
||||||
});
|
}
|
||||||
}
|
});
|
||||||
});
|
|
||||||
} else {
|
|
||||||
await shellExec('./adb install -r ' + element).then(async function (result) {
|
|
||||||
console.log(element + ' - ' + result.stdout);
|
|
||||||
if (element === "data\\apps\\MoreLocale.apk") {
|
|
||||||
await shellExec('./adb shell pm grant jp.co.c_lis.ccl.morelocale android.permission.CHANGE_CONFIGURATION').then(function (result) {
|
|
||||||
console.log('moreLocale Activated On Watch');
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
console.log(chalk.green('Compatible Apps Installed'))
|
console.log(chalk.green('Compatible Apps Installed'))
|
||||||
await common.pause(2000)
|
await common.pause(2000)
|
||||||
@ -110,25 +98,14 @@ module.exports = {
|
|||||||
|
|
||||||
for (let element of apkList) {
|
for (let element of apkList) {
|
||||||
console.log('Installing ' + element)
|
console.log('Installing ' + element)
|
||||||
if (process.platform === 'win32' || process.platform === 'win64') {
|
await shellExec(adbRun + ' install -r ' + element).then(async function (result) {
|
||||||
await shellExec('adb install -r ' + element).then(async function (result) {
|
console.log(element + ' - ' + result.stdout);
|
||||||
console.log(element + ' - ' + result.stdout);
|
if (element === "data\\apps\\MoreLocale.apk") {
|
||||||
if (element === "data\\apps\\MoreLocale.apk") {
|
await shellExec(adbRun + ' shell pm grant jp.co.c_lis.ccl.morelocale android.permission.CHANGE_CONFIGURATION').then(function (result) {
|
||||||
await shellExec('adb shell pm grant jp.co.c_lis.ccl.morelocale android.permission.CHANGE_CONFIGURATION').then(function (result) {
|
console.log('moreLocale Activated On Watch');
|
||||||
console.log('moreLocale Activated On Watch');
|
});
|
||||||
});
|
}
|
||||||
}
|
});
|
||||||
});
|
|
||||||
} else {
|
|
||||||
await shellExec('./adb install -r ' + element).then(async function (result) {
|
|
||||||
console.log(element + ' - ' + result.stdout);
|
|
||||||
if (element === "data\\apps\\MoreLocale.apk") {
|
|
||||||
await shellExec('./adb shell pm grant jp.co.c_lis.ccl.morelocale android.permission.CHANGE_CONFIGURATION').then(function (result) {
|
|
||||||
console.log('moreLocale Activated On Watch');
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
console.log(chalk.green('Compatible Apps Installed'))
|
console.log(chalk.green('Compatible Apps Installed'))
|
||||||
await common.pause(2000)
|
await common.pause(2000)
|
||||||
@ -138,15 +115,9 @@ 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) {
|
||||||
if (process.platform === 'win32' || process.platform === 'win64') {
|
await shellExec(adbRun + ' shell pm uninstall -k --user 0 ' + element).then(function (result) {
|
||||||
await shellExec('adb shell pm uninstall -k --user 0 ' + element).then(function (result) {
|
console.log('Removing ' + element + ' - ' + result.stdout);
|
||||||
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)
|
||||||
@ -156,15 +127,9 @@ 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) {
|
||||||
if (process.platform === 'win32' || process.platform === 'win64') {
|
await shellExec(adbRun + ' shell cmd package install-existing ' + element).then(function (result) {
|
||||||
await shellExec('adb shell cmd package install-existing ' + element).then(function (result) {
|
console.log('Restoring ' + element + ' - ' + result.stdout);
|
||||||
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)
|
||||||
@ -175,74 +140,45 @@ 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')
|
||||||
if (process.platform === 'win32' || process.platform === 'win64') {
|
shellExec(adbRun + ' connect ' + miwatchData.ipAddress).then(async function (result) {
|
||||||
shellExec('adb connect ' + miwatchData.ipAddress).then(async function (result) {
|
if (result.stdout.includes('already connected') || result.stdout.includes('connected to ')) {
|
||||||
if (result.stdout.includes('already connected') || result.stdout.includes('connected to ')) {
|
console.log(chalk.green('MiWatch Connected'))
|
||||||
console.log(chalk.green('MiWatch Connected'))
|
await common.pause(3000)
|
||||||
await common.pause(3000)
|
module.exports.mainMenu()
|
||||||
module.exports.mainMenu()
|
} else {
|
||||||
} else {
|
console.log(chalk.red('MiWatch not found'))
|
||||||
console.log(chalk.red('MiWatch not found'))
|
await common.pause(2000)
|
||||||
await common.pause(2000)
|
console.log(chalk.white('Try Again'))
|
||||||
console.log(chalk.white('Try Again'))
|
await common.pause(1000)
|
||||||
await common.pause(1000)
|
module.exports.connectWifi()
|
||||||
module.exports.connectWifi()
|
}
|
||||||
}
|
}).catch()
|
||||||
}).catch()
|
|
||||||
} else {
|
|
||||||
shellExec('./adb connect ' + miwatchData.ipAddress).then(async function (result) {
|
|
||||||
if (result.stdout.includes('already connected') || result.stdout.includes('connected to ')) {
|
|
||||||
console.log(chalk.green('MiWatch Connected'))
|
|
||||||
files.writeIpAddress(miWatchIpaddress)
|
|
||||||
await common.pause(3000)
|
|
||||||
module.exports.mainMenu()
|
|
||||||
} else {
|
|
||||||
console.log(chalk.red('MiWatch not found'))
|
|
||||||
await common.pause(2000)
|
|
||||||
console.log(chalk.white('Try Again'))
|
|
||||||
await common.pause(1000)
|
|
||||||
module.exports.connectWifi()
|
|
||||||
}
|
|
||||||
}).catch()
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
const value = await inquirer.connectWifi();
|
const value = await inquirer.connectWifi();
|
||||||
const miWatchIpaddress = value.connectWifi
|
const miWatchIpaddress = value.connectWifi
|
||||||
if (process.platform === 'win32' || process.platform === 'win64') {
|
shellExec(adbRun + ' connect ' + miWatchIpaddress).then(async function (result) {
|
||||||
shellExec('adb connect ' + miWatchIpaddress).then(async function (result) {
|
if (result.stdout.includes('already connected') || result.stdout.includes('connected to ')) {
|
||||||
if (result.stdout.includes('already connected') || result.stdout.includes('connected to ')) {
|
console.log(chalk.green('MiWatch Connected'))
|
||||||
console.log(chalk.green('MiWatch Connected'))
|
files.writeIpAddress(miWatchIpaddress)
|
||||||
files.writeIpAddress(miWatchIpaddress)
|
await common.pause(3000)
|
||||||
await common.pause(3000)
|
module.exports.mainMenu()
|
||||||
module.exports.mainMenu()
|
} else {
|
||||||
} else {
|
console.log(chalk.red('MiWatch not found'))
|
||||||
console.log(chalk.red('MiWatch not found'))
|
await common.pause(2000)
|
||||||
await common.pause(2000)
|
console.log(chalk.white('Try Again'))
|
||||||
console.log(chalk.white('Try Again'))
|
await common.pause(1000)
|
||||||
await common.pause(1000)
|
module.exports.connectWifi()
|
||||||
module.exports.connectWifi()
|
}
|
||||||
}
|
}).catch()
|
||||||
}).catch()
|
|
||||||
} else {
|
|
||||||
shellExec('./adb connect ' + miWatchIpaddress).then(async function (result) {
|
|
||||||
if (result.stdout.includes('already connected') || result.stdout.includes('connected to ')) {
|
|
||||||
console.log(chalk.green('MiWatch Connected'))
|
|
||||||
files.writeIpAddress(miWatchIpaddress)
|
|
||||||
await common.pause(3000)
|
|
||||||
module.exports.mainMenu()
|
|
||||||
} else {
|
|
||||||
console.log(chalk.red('MiWatch not found'))
|
|
||||||
await common.pause(2000)
|
|
||||||
console.log(chalk.white('Try Again'))
|
|
||||||
await common.pause(1000)
|
|
||||||
module.exports.connectWifi()
|
|
||||||
}
|
|
||||||
}).catch()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
mainMenu: async () => {
|
mainMenu: async () => {
|
||||||
common.header('Main Menu')
|
common.header('Main Menu')
|
||||||
|
if (process.platform === 'win32' || process.platform === 'win64') {
|
||||||
|
adbRun = 'adb'
|
||||||
|
} else {
|
||||||
|
adbRun = './adb'
|
||||||
|
}
|
||||||
const mainMenuSelection = await inquirer.mainMenu();
|
const mainMenuSelection = await inquirer.mainMenu();
|
||||||
switch (mainMenuSelection.mainMenu) {
|
switch (mainMenuSelection.mainMenu) {
|
||||||
case 'connect to miwatch via wifi':
|
case 'connect to miwatch via wifi':
|
||||||
@ -257,9 +193,9 @@ module.exports = {
|
|||||||
case 'install compatible apps':
|
case 'install compatible apps':
|
||||||
module.exports.compatibleApps()
|
module.exports.compatibleApps()
|
||||||
break;
|
break;
|
||||||
case 'remove compatible apps' :
|
case 'remove compatible apps':
|
||||||
module.exports.removeCompatibleApps()
|
module.exports.removeCompatibleApps()
|
||||||
break;
|
break;
|
||||||
case 'quit':
|
case 'quit':
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user