bug fix (battery - windows)
This commit is contained in:
+10
-7
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user