optimized battery().ischarging for macOS
This commit is contained in:
parent
0c61ef0443
commit
179d5835fd
@ -100,6 +100,7 @@ Other changes
|
||||
|
||||
| Version | Date | Comment |
|
||||
| -------------- | -------------- | -------- |
|
||||
| 3.37.10 | 2018-04-05 | `battery().ischarging` optimized for macOS |
|
||||
| 3.37.9 | 2018-04-03 | optimized `processes()`, bugfix `networkInterfaceDefault()` |
|
||||
| 3.37.8 | 2018-03-25 | optimized `networkDefaultInterface()` detection, fixed network `operstate` MacOS |
|
||||
| 3.37.7 | 2018-03-13 | celebrating 4th birthday |
|
||||
|
||||
@ -5,7 +5,7 @@ Fixes #
|
||||
#### Changes proposed:
|
||||
|
||||
* [ ] Fix
|
||||
* [ ] Add
|
||||
* [ ] Enhancement
|
||||
* [ ] Remove
|
||||
* [ ] Update
|
||||
|
||||
|
||||
@ -105,7 +105,6 @@ module.exports = function (callback) {
|
||||
if (stdout) {
|
||||
let lines = stdout.toString().replace(/ +/g, '').replace(/"+/g, '').replace(/-/g, '').split('\n');
|
||||
result.cyclecount = parseInt('0' + util.getValue(lines, 'cyclecount', '='), 10);
|
||||
result.ischarging = util.getValue(lines,'ischarging', '=').toLowerCase() === 'yes';
|
||||
result.maxcapacity = parseInt('0' + util.getValue(lines, 'maxcapacity', '='), 10);
|
||||
result.currentcapacity = parseInt('0' + util.getValue(lines, 'currentcapacity', '='), 10);
|
||||
let percent = -1;
|
||||
@ -117,6 +116,11 @@ module.exports = function (callback) {
|
||||
percent = parseFloat(parts2[1].trim().replace('%', ''));
|
||||
}
|
||||
}
|
||||
if (parts && parts[1]) {
|
||||
result.ischarging = parts[1].trim() !== 'discharging';
|
||||
} else {
|
||||
result.ischarging = util.getValue(lines, 'ischarging', '=').toLowerCase() === 'yes';
|
||||
}
|
||||
if (result.maxcapacity && result.currentcapacity) {
|
||||
result.hasbattery = true;
|
||||
result.percent = percent !== -1 ? percent : Math.round(100.0 * result.currentcapacity / result.maxcapacity);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user