diff --git a/CHANGELOG.md b/CHANGELOG.md index fb56f1c..90e42ad 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -98,6 +98,7 @@ Other changes | Version | Date | Comment | | -------------- | -------------- | -------- | +| 3.23.2 | 2017-06-23 | bug fix `battery` (windows) | | 3.23.1 | 2017-06-22 | updated docs | | 3.23.0 | 2017-06-22 | added `memLayout`, `diskLayout`, extended windows support (`inetChecksite`)| | 3.22.0 | 2017-06-19 | extended windows support (`users`, `inetLatency`) | diff --git a/README.md b/README.md index 64a31c7..5f45f67 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ Simple system and OS information library for [node.js][nodejs-url] ## Quick Start -Collection of 30+ functions to retrieve detailed hardware, system and OS information (Linux, OSX and now partial Windows support) +Collection of 35+ functions to retrieve detailed hardware, system and OS information (Linux, OSX and partial Windows support) ### Installation @@ -110,7 +110,7 @@ I also created a nice little command line tool called [mmon][mmon-github-url] ( | | serial | X | X | X | serial number | | | uuid | X | X | X | UUID | -#### 3. CPU, Memory, Battery, Graphics +#### 3. CPU, Memory, Disks, Battery, Graphics | Function | Result object | Linux | OSX | Win | Comments | | --------------- | ----- | ----- | ---- | ------- | -------- | diff --git a/lib/battery.js b/lib/battery.js index 28233fa..388c6c8 100644 --- a/lib/battery.js +++ b/lib/battery.js @@ -117,14 +117,17 @@ module.exports = function (callback) { } if (_windows) { exec("WMIC Path Win32_Battery Get BatteryStatus, DesignCapacity, EstimatedChargeRemaining /value", function (error, stdout) { - if (!error) { + if (stdout) { let lines = stdout.split('\r\n'); - let status = parseInt(getValue(lines, 'BatteryStatus', '=') || '2'); - result.hasbattery = true; - result.maxcapacity = parseInt(getValue(lines, 'DesignCapacity', '=') || 0); - result.percent = parseInt(getValue(lines, 'EstimatedChargeRemaining', '=') || 0); - result.currentcapacity = parseInt(result.maxcapacity * result.percent / 100); - result.ischarging = (status >= 6 && status <= 9) || (!(status === 3) && !(status === 1) && result.percent < 100); + let status = getValue(lines, 'BatteryStatus', '=').trim(); + if (status) { + status = parseInt(status || '2'); + result.hasbattery = true; + result.maxcapacity = parseInt(getValue(lines, 'DesignCapacity', '=') || 0); + result.percent = parseInt(getValue(lines, 'EstimatedChargeRemaining', '=') || 0); + result.currentcapacity = parseInt(result.maxcapacity * result.percent / 100); + result.ischarging = (status >= 6 && status <= 9) || (!(status === 3) && !(status === 1) && result.percent < 100); + } } if (callback) { callback(result) } resolve(result);