optimized OSX battery

This commit is contained in:
Sebastian Hildebrandt
2018-01-21 14:57:18 +01:00
parent 6eb98db668
commit 369b3c0f3f
2 changed files with 11 additions and 2 deletions
+10 -2
View File
@@ -80,7 +80,7 @@ module.exports = function (callback) {
}
}
if (_darwin) {
exec("ioreg -n AppleSmartBattery -r | grep '\"CycleCount\"';ioreg -n AppleSmartBattery -r | grep '\"IsCharging\"';ioreg -n AppleSmartBattery -r | grep '\"MaxCapacity\"';ioreg -n AppleSmartBattery -r | grep '\"CurrentCapacity\"'", function (error, stdout) {
exec("ioreg -n AppleSmartBattery -r | grep '\"CycleCount\"';ioreg -n AppleSmartBattery -r | grep '\"IsCharging\"';ioreg -n AppleSmartBattery -r | grep '\"MaxCapacity\"';ioreg -n AppleSmartBattery -r | grep '\"CurrentCapacity\"';pmset -g batt | grep %", function (error, stdout) {
if (!error) {
let lines = stdout.toString().replace(/ +/g, '').replace(/"+/g, '').split('\n');
lines.forEach(function (line) {
@@ -88,7 +88,15 @@ module.exports = function (callback) {
if (line.toLowerCase().indexOf('cyclecount') !== -1) result.cyclecount = parseFloat(line.split('=')[1].trim());
if (line.toLowerCase().indexOf('ischarging') !== -1) result.ischarging = (line.split('=')[1].trim().toLowerCase() === 'yes');
if (line.toLowerCase().indexOf('maxcapacity') !== -1) result.maxcapacity = parseFloat(line.split('=')[1].trim());
if (line.toLowerCase().indexOf('currentcapacity') !== -1) result.currentcapacity = parseFloat(line.split('=')[1].trim());
if (line.toLowerCase().indexOf('internalbattery') !== -1) {
let parts = line.split(';');
if (parts && parts[0]) {
let parts2 = parts[0].split('\t');
if (parts2 && parts2[1]) {
result.percent = parseFloat(parts2[1].trim().replace('%', ''));
}
}
}
}
});
}