common.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. const chalk = require('chalk');
  2. const clear = require('clear');
  3. const figlet = require('figlet');
  4. const fs = require('fs')
  5. var pjson = require('../package.json');
  6. const fetch = require('node-fetch');
  7. var shell = require('shelljs');
  8. const globalVariables = require('../lib/globalVars');
  9. module.exports = {
  10. header: (page) => {
  11. clear();
  12. console.log(
  13. chalk.red(
  14. figlet.textSync('MiWatch Kleaner', {
  15. horizontalLayout: 'full'
  16. })
  17. )
  18. );
  19. console.log(chalk.red(' ' + pjson.version));
  20. console.log();
  21. console.log(
  22. chalk.red(
  23. '-------------------------------------------------------------------------------------------------------'
  24. )
  25. )
  26. console.log(chalk.blue(page))
  27. module.exports.connectionCheck()
  28. console.log(chalk.red('----------'))
  29. },
  30. pause: async (time) => {
  31. await new Promise(resolve => setTimeout(resolve, time));
  32. },
  33. connectionCheck: async () => {
  34. if (globalVariables.localUSB === "X") {
  35. console.log(chalk.white('MiWatch: ') + chalk.green('Connected via USB'))
  36. }
  37. if (globalVariables.miWatchIpaddress != "") {
  38. console.log(chalk.white('MiWatch: ') + chalk.green('Connected via Wifi - ' + chalk.white(globalVariables.miWatchIpaddress)))
  39. }
  40. if (globalVariables.localUSB === "" && globalVariables.miWatchIpaddress === "") {
  41. console.log(chalk.white('MiWatch: ') + chalk.red('Not Connected'))
  42. }
  43. },
  44. downloadFile: async (url, path) => {
  45. const res = await fetch(url);
  46. await new Promise((resolve, reject) => {
  47. const fileStream = fs.createWriteStream(path);
  48. res.body.pipe(fileStream);
  49. res.body.on("error", (err) => {
  50. reject(err);
  51. });
  52. fileStream.on("finish", function () {
  53. resolve();
  54. });
  55. });
  56. },
  57. getCompatibleAppsList: async () => {
  58. let settings = { method: "Get" };
  59. const response = await fetch("http://kithub.cf/Karl/MiWatchKleaner-APKs/raw/master/compatibleApps.json", settings)
  60. .then(res => res.json())
  61. return response
  62. },
  63. clearApkFolder: async () => {
  64. await shell.rm('-rf', './data/apps/*.apk');
  65. },
  66. }