optimized battery().ischarging for macOS

This commit is contained in:
Sebastian Hildebrandt 2018-04-05 21:37:26 +02:00
parent 0c61ef0443
commit 179d5835fd
3 changed files with 15 additions and 10 deletions

View File

@ -100,6 +100,7 @@ Other changes
| Version | Date | Comment | | 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.9 | 2018-04-03 | optimized `processes()`, bugfix `networkInterfaceDefault()` |
| 3.37.8 | 2018-03-25 | optimized `networkDefaultInterface()` detection, fixed network `operstate` MacOS | | 3.37.8 | 2018-03-25 | optimized `networkDefaultInterface()` detection, fixed network `operstate` MacOS |
| 3.37.7 | 2018-03-13 | celebrating 4th birthday | | 3.37.7 | 2018-03-13 | celebrating 4th birthday |

View File

@ -5,7 +5,7 @@ Fixes #
#### Changes proposed: #### Changes proposed:
* [ ] Fix * [ ] Fix
* [ ] Add * [ ] Enhancement
* [ ] Remove * [ ] Remove
* [ ] Update * [ ] Update

View File

@ -105,7 +105,6 @@ module.exports = function (callback) {
if (stdout) { if (stdout) {
let lines = stdout.toString().replace(/ +/g, '').replace(/"+/g, '').replace(/-/g, '').split('\n'); let lines = stdout.toString().replace(/ +/g, '').replace(/"+/g, '').replace(/-/g, '').split('\n');
result.cyclecount = parseInt('0' + util.getValue(lines, 'cyclecount', '='), 10); 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.maxcapacity = parseInt('0' + util.getValue(lines, 'maxcapacity', '='), 10);
result.currentcapacity = parseInt('0' + util.getValue(lines, 'currentcapacity', '='), 10); result.currentcapacity = parseInt('0' + util.getValue(lines, 'currentcapacity', '='), 10);
let percent = -1; let percent = -1;
@ -117,6 +116,11 @@ module.exports = function (callback) {
percent = parseFloat(parts2[1].trim().replace('%', '')); 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) { if (result.maxcapacity && result.currentcapacity) {
result.hasbattery = true; result.hasbattery = true;
result.percent = percent !== -1 ? percent : Math.round(100.0 * result.currentcapacity / result.maxcapacity); result.percent = percent !== -1 ? percent : Math.round(100.0 * result.currentcapacity / result.maxcapacity);