mirror of
https://github.com/Ylianst/MeshAgent
synced 2026-01-02 00:23:17 +00:00
fix macos battery level
This commit is contained in:
@@ -143,15 +143,27 @@ function powerMonitor()
|
||||
child.stdin.write(' printf "{\\"ac\\": %s,\\"level\\": %s}",power, chg[1]; ');
|
||||
child.stdin.write("}'\nexit\n");
|
||||
child.waitExit();
|
||||
|
||||
try
|
||||
{
|
||||
try {
|
||||
var info = JSON.parse(child.stdout.str.trim());
|
||||
return (info);
|
||||
}
|
||||
catch (e)
|
||||
{
|
||||
return ({ ac: 1, level: -1 });
|
||||
} catch (e) {
|
||||
child = require('child_process').execFile('/bin/sh', ['sh']);
|
||||
child.stderr.str = ''; child.stderr.on('data', function (c) { this.str += c.toString(); });
|
||||
child.stdout.str = ''; child.stdout.on('data', function (c) { this.str += c.toString(); });
|
||||
child.stdin.write("pmset -g batt | tr '\\n' '`' | awk -F'`' '");
|
||||
child.stdin.write('{');
|
||||
child.stdin.write(' power=split($1,pwr,"AC")>1?"1":"0";');
|
||||
child.stdin.write(' split($2, batt, " ");');
|
||||
child.stdin.write(' split(batt[3],chg,"%");');
|
||||
child.stdin.write(' printf "{\\"ac\\": %s,\\"level\\": %s}",power, chg[1]; ');
|
||||
child.stdin.write("}'\nexit\n");
|
||||
child.waitExit();
|
||||
try {
|
||||
var info = JSON.parse(child.stdout.str.trim());
|
||||
return (info);
|
||||
} catch (er) {
|
||||
return ({ ac: 1, level: -1 });
|
||||
}
|
||||
}
|
||||
};
|
||||
this._batteryLevelCheck = function _batteryLevelCheck()
|
||||
|
||||
Reference in New Issue
Block a user