1
0
mirror of https://github.com/Ylianst/MeshAgent synced 2025-12-16 00:03:45 +00:00

Added battery detection for macOS

This commit is contained in:
Bryan Roe
2020-05-30 13:45:23 -07:00
parent c85dde4af1
commit 82d6248bb9
2 changed files with 13 additions and 5 deletions

View File

@@ -296,6 +296,14 @@ module.exports.isBatteryPowered = function isBatteryOperated()
}
}
break;
case 'darwin':
var child = require('child_process').execFile('/bin/sh', ['sh']);
child.stdout.str = ''; child.stdout.on('data', function(c){ this.str += c.toString(); });
child.stderr.str = ''; child.stderr.on('data', function(c){ this.str += c.toString(); });
child.stdin.write("pmset -g batt | tr '\\n' '`' | awk -F'`' '{ if(NF>2) { print \"true\"; }}'\nexit\n");
child.waitExit();
if(child.stdout.str.trim() != '') { ret = true; }
break;
}
return (ret);
};