Browse Source

working code update

karl.hudgell 4 years ago
parent
commit
b00973036b
4 changed files with 41 additions and 84 deletions
  1. 16 8
      lib/common.js
  2. 10 73
      package-lock.json
  3. 3 0
      package.json
  4. 12 3
      pages/pages.js

+ 16 - 8
lib/common.js

@@ -1,11 +1,21 @@
 const chalk = require('chalk');
 const clear = require('clear');
 const figlet = require('figlet');
+const pathExists = require('path-exists');
+const fs = require('fs')
+const path = require("path");
 
 
 module.exports = {
-    storeIp: (value) => {
-       let miWatchIpaddress = value
+    writeIpAddress: (value) => {
+        const data = {
+            ipAddress: value
+        }
+        try {
+            fs.writeFileSync('./data/MiWatch.json', JSON.stringify(data))
+        } catch (err) {
+            console.log(err)
+        }
     },
     header: (page) => {
         clear();
@@ -16,15 +26,12 @@ module.exports = {
                 })
             )
         );
-
         console.log(chalk.red('                                                                                     2.0.0'));
-
         console.log(
             chalk.red(
                 '-------------------------------------------------------------------------------------------------------'
             )
         )
-
         console.log(chalk.blue(page))
         module.exports.ipCheck()
         console.log(chalk.red('----------'))
@@ -33,10 +40,11 @@ module.exports = {
         await new Promise(resolve => setTimeout(resolve, time));
     },
     ipCheck: async () => {
-        if (module.exports.storeIp.miWatchIpaddress === undefined) {
-            console.log(chalk.white('Connected IP: ') + chalk.red('Not Connected'))
+        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('Connected IP: ' + chalk.green(module.defaults.storeIp.miWatchIpaddress)))
+            console.log(chalk.white('MiWatch IP: ' + chalk.green(miwatchData.ipAddress)))
         }
     }
 }

+ 10 - 73
package-lock.json

@@ -45,33 +45,6 @@
       "resolved": "https://registry.npmjs.org/@types/color-name/-/color-name-1.1.1.tgz",
       "integrity": "sha512-rr+OQyAjxze7GgWrSaJwydHStIhHq2lvY3BOC2Mj7KnzI7XK0Uw1TOOdI9lDoajEbSWLiYgoo4f1R51erQfhPQ=="
     },
-    "adbkit": {
-      "version": "2.11.1",
-      "resolved": "https://registry.npmjs.org/adbkit/-/adbkit-2.11.1.tgz",
-      "integrity": "sha512-hDTiRg9NX3HQt7WoDAPCplUpvzr4ZzQa2lq7BdTTJ/iOZ6O7YNAs6UYD8sFAiBEcYHDRIyq3cm9sZP6uZnhvXw==",
-      "requires": {
-        "adbkit-logcat": "^1.1.0",
-        "adbkit-monkey": "~1.0.1",
-        "bluebird": "~2.9.24",
-        "commander": "^2.3.0",
-        "debug": "~2.6.3",
-        "node-forge": "^0.7.1",
-        "split": "~0.3.3"
-      }
-    },
-    "adbkit-logcat": {
-      "version": "1.1.0",
-      "resolved": "https://registry.npmjs.org/adbkit-logcat/-/adbkit-logcat-1.1.0.tgz",
-      "integrity": "sha1-Adf5sM75CTowvLOwB+//MBUIli8="
-    },
-    "adbkit-monkey": {
-      "version": "1.0.1",
-      "resolved": "https://registry.npmjs.org/adbkit-monkey/-/adbkit-monkey-1.0.1.tgz",
-      "integrity": "sha1-8pG+cBou/FZ6Y/x6pq/N7TFDC+E=",
-      "requires": {
-        "async": "~0.2.9"
-      }
-    },
     "ajv": {
       "version": "6.12.2",
       "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.12.2.tgz",
@@ -123,11 +96,6 @@
       "resolved": "https://registry.npmjs.org/assert-plus/-/assert-plus-1.0.0.tgz",
       "integrity": "sha1-8S4PPF13sLHN2RRpQuTpbB5N1SU="
     },
-    "async": {
-      "version": "0.2.10",
-      "resolved": "https://registry.npmjs.org/async/-/async-0.2.10.tgz",
-      "integrity": "sha1-trvgsGdLnXGXCMo43owjfLUmw9E="
-    },
     "asynckit": {
       "version": "0.4.0",
       "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz",
@@ -151,11 +119,6 @@
         "tweetnacl": "^0.14.3"
       }
     },
-    "bluebird": {
-      "version": "2.9.34",
-      "resolved": "https://registry.npmjs.org/bluebird/-/bluebird-2.9.34.tgz",
-      "integrity": "sha1-L3tOyAIWMoqf3evfacjUlC/v99g="
-    },
     "braces": {
       "version": "3.0.2",
       "resolved": "https://registry.npmjs.org/braces/-/braces-3.0.2.tgz",
@@ -246,11 +209,6 @@
         "delayed-stream": "~1.0.0"
       }
     },
-    "commander": {
-      "version": "2.20.3",
-      "resolved": "https://registry.npmjs.org/commander/-/commander-2.20.3.tgz",
-      "integrity": "sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ=="
-    },
     "core-util-is": {
       "version": "1.0.2",
       "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz",
@@ -272,14 +230,6 @@
         "assert-plus": "^1.0.0"
       }
     },
-    "debug": {
-      "version": "2.6.9",
-      "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz",
-      "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==",
-      "requires": {
-        "ms": "2.0.0"
-      }
-    },
     "deep-is": {
       "version": "0.1.3",
       "resolved": "https://registry.npmjs.org/deep-is/-/deep-is-0.1.3.tgz",
@@ -577,6 +527,11 @@
         "readable-stream": "^2.0.0"
       }
     },
+    "fs": {
+      "version": "0.0.1-security",
+      "resolved": "https://registry.npmjs.org/fs/-/fs-0.0.1-security.tgz",
+      "integrity": "sha1-invTcYa23d84E/I4WLV+yq9eQdQ="
+    },
     "fs-extra": {
       "version": "8.1.0",
       "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-8.1.0.tgz",
@@ -878,11 +833,6 @@
         "minimist": "^1.2.5"
       }
     },
-    "ms": {
-      "version": "2.0.0",
-      "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
-      "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g="
-    },
     "multistream": {
       "version": "2.1.1",
       "resolved": "https://registry.npmjs.org/multistream/-/multistream-2.1.1.tgz",
@@ -902,16 +852,6 @@
       "resolved": "https://registry.npmjs.org/next-tick/-/next-tick-1.0.0.tgz",
       "integrity": "sha1-yobR/ogoFpsBICCOPchCS524NCw="
     },
-    "node-adb": {
-      "version": "0.1.6",
-      "resolved": "https://registry.npmjs.org/node-adb/-/node-adb-0.1.6.tgz",
-      "integrity": "sha512-wai4LqO1NQJVeGerMTSln/Sp0vwuPmod9G0aRJJmgo0tk5wBAmyqUQ74wgcZIn0Ja9BCkBOmyz0LEA6nE8dWIg=="
-    },
-    "node-forge": {
-      "version": "0.7.6",
-      "resolved": "https://registry.npmjs.org/node-forge/-/node-forge-0.7.6.tgz",
-      "integrity": "sha512-sol30LUpz1jQFBjOKwbjxijiE3b6pjd74YwfD0fJOKPjF+fONKb2Yg8rYgS6+bK6VDl+/wfr4IYpC7jDzLUIfw=="
-    },
     "oauth-sign": {
       "version": "0.9.0",
       "resolved": "https://registry.npmjs.org/oauth-sign/-/oauth-sign-0.9.0.tgz",
@@ -957,6 +897,11 @@
         "util": "^0.10.3"
       }
     },
+    "path-exists": {
+      "version": "4.0.0",
+      "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-4.0.0.tgz",
+      "integrity": "sha512-ak9Qy5Q7jYb2Wwcey5Fpvg2KoAc/ZIhLSLOSBmRmygPsGwkVVt0fZa0qrtMz+m6tJTAHfZQ8FnmB4MG4LWy7/w=="
+    },
     "path-parse": {
       "version": "1.0.6",
       "resolved": "https://registry.npmjs.org/path-parse/-/path-parse-1.0.6.tgz",
@@ -1217,14 +1162,6 @@
       "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==",
       "optional": true
     },
-    "split": {
-      "version": "0.3.3",
-      "resolved": "https://registry.npmjs.org/split/-/split-0.3.3.tgz",
-      "integrity": "sha1-zQ7qXmOiEd//frDwkcQTPi0N0o8=",
-      "requires": {
-        "through": "2"
-      }
-    },
     "sshpk": {
       "version": "1.16.1",
       "resolved": "https://registry.npmjs.org/sshpk/-/sshpk-1.16.1.tgz",

+ 3 - 0
package.json

@@ -18,9 +18,12 @@
     "clui": "^0.3.6",
     "download-file-with-progressbar": "^1.2.3",
     "figlet": "^1.3.0",
+    "fs": "0.0.1-security",
     "inquirer": "^7.1.0",
     "lodash": "^4.17.15",
     "minimist": "^1.2.5",
+    "path": "^0.12.7",
+    "path-exists": "^4.0.0",
     "pkg": "^4.4.7",
     "promise-android-tools": "^2.0.4",
     "shell-exec": "^1.0.2"

+ 12 - 3
pages/pages.js

@@ -7,15 +7,24 @@ const shellExec = require('shell-exec')
 module.exports = {
     connectWifi: async () => {
         common.header('Connect Wifi')
-        const miWatchIpaddress = await inquirer.connectWifi();
-        this.miWatchIpaddress = miWatchIpaddress.connectWifi
+        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(3000)
+                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 {
                 console.log(chalk.green('MiWatch Connected'))
+                common.writeIpAddress(miWatchIpaddress)
                 await common.pause(3000)
                 module.exports.mainMenu()
             }