common.js 2.3 KB

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