From c1830371286cb5fcd7a8ae283053accc36902046 Mon Sep 17 00:00:00 2001 From: Sebastian Hildebrandt Date: Thu, 9 Nov 2017 23:06:55 +0100 Subject: [PATCH] code cleanup --- CHANGELOG.md | 1 + lib/graphics.js | 7 ++++++- lib/internet.js | 20 +++++++++++++------- 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fc0a12e..bd325ce 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -99,6 +99,7 @@ Other changes | Version | Date | Comment | | -------------- | -------------- | -------- | +| 3.33.5 | 2017-11-09 | code cleanup | | 3.33.4 | 2017-11-09 | bugfix graphics controller win (bytes) | | 3.33.3 | 2017-11-08 | bugfix cpu speed arm - type | | 3.33.2 | 2017-11-08 | bugfix cpu speed arm | diff --git a/lib/graphics.js b/lib/graphics.js index abe4914..d6527f8 100644 --- a/lib/graphics.js +++ b/lib/graphics.js @@ -327,7 +327,7 @@ function graphics(callback) { if (!error) { let csections = stdout.split(/\n\s*\n/); result.controllers = parseLinesWindowsControllers(csections); - exec('wmic path win32_desktopmonitor get MonitorManufacturer, ScreenWidth, ScreenHeight /value', function (error, stdout) { + exec('wmic path win32_desktopmonitor get Caption, MonitorManufacturer, MonitorType, ScreenWidth, ScreenHeight /value', function (error, stdout) { let dsections = stdout.split(/\n\s*\n/); if (!error) { result.displays = parseLinesWindowsDisplays(dsections); @@ -385,8 +385,13 @@ function graphics(callback) { let lines = sections[i].trim().split('\r\n'); displays.push({ model: util.getValue(lines, 'MonitorManufacturer', '='), + main: false, + builtin: false, + connection: '', resolutionx: toInt(util.getValue(lines, 'ScreenWidth', '=')), resolutiony: toInt(util.getValue(lines, 'ScreenHeight', '=')), + sizex: -1, + sizey: -1 }); } } diff --git a/lib/internet.js b/lib/internet.js index 0bce8d6..c801f27 100644 --- a/lib/internet.js +++ b/lib/internet.js @@ -40,8 +40,8 @@ function inetChecksite(url, callback) { url = url.toLowerCase(); let t = Date.now(); if (_linux || _darwin) { - let args = " -I --connect-timeout 5 -m 5 " + url + " 2>/dev/null | head -n 1 | cut -d ' ' -f2"; - let cmd = "curl"; + let args = ' -I --connect-timeout 5 -m 5 ' + url + ' 2>/dev/null | head -n 1 | cut -d " " -f2'; + let cmd = 'curl'; exec(cmd + args, function (error, stdout) { let statusCode = parseInt(stdout.toString()); result.status = statusCode || 404; @@ -66,12 +66,12 @@ function inetChecksite(url, callback) { if (callback) { callback(result); } resolve(result); } else { - res.on('data', (chunk) => { }); + // res.on('data', (chunk) => { }); res.on('end', () => { result.ms = (result.ok ? Date.now() - t : -1); if (callback) { callback(result); } resolve(result); - }) + }); } }).on('error', err => { if (callback) { callback(result); } @@ -110,16 +110,22 @@ function inetLatency(host, callback) { let cmd; if (_linux || _darwin) { if (_linux) { - cmd = "ping -c 2 -w 3 " + host + " | grep rtt | cut -d'/' -f4 | awk '{ print $3 }'"; + cmd = 'ping -c 2 -w 3 ' + host + ' | grep rtt'; } if (_darwin) { - cmd = "ping -c 2 -t 3 " + host + " | grep avg | cut -d'/' -f4 | awk '{ print $3 }'"; + cmd = 'ping -c 2 -t 3 ' + host + ' | grep avg'; } exec(cmd, function (error, stdout) { let result = -1; if (!error) { - result = parseFloat(stdout.toString()); + const line = stdout.toString().split('='); + if (line.length > 1) { + const parts = line[1].split('/'); + if (parts.length > 1) { + result = parseFloat(parts[1]); + } + } } if (callback) { callback(result); } resolve(result);