mirror of
https://github.com/Ylianst/MeshAgent
synced 2026-02-05 03:03:34 +00:00
Updated formatting.
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -46,7 +46,7 @@ function powerMonitor()
|
||||
delete self._i;
|
||||
}, this);
|
||||
|
||||
if(process.platform == 'linux')
|
||||
if (process.platform == 'linux')
|
||||
{
|
||||
this._ACPath = null;
|
||||
this._BatteryPath = [];
|
||||
@@ -67,11 +67,11 @@ function powerMonitor()
|
||||
this._BatteryPath.push('/sys/class/power_supply/' + devices[i] + '/');
|
||||
}
|
||||
}
|
||||
if(this._ACPath != null)
|
||||
if (this._ACPath != null)
|
||||
{
|
||||
this._ACState = parseInt(require('fs').readFileSync(this._ACPath + 'online').toString().trim());
|
||||
}
|
||||
if(this._BatteryPath.length>0)
|
||||
if (this._BatteryPath.length > 0)
|
||||
{
|
||||
this._getBatteryLevel = function _getBatteryLevel()
|
||||
{
|
||||
@@ -103,7 +103,7 @@ function powerMonitor()
|
||||
}
|
||||
this._acpiSink = function _acpiSink(acpiEvent)
|
||||
{
|
||||
if(acpiEvent.name == 'ac_adapter')
|
||||
if (acpiEvent.name == 'ac_adapter')
|
||||
{
|
||||
_acpiSink.self._ACState = acpiEvent.value;
|
||||
_acpiSink.self.emit('acdc', acpiEvent.value == 1 ? 'AC' : 'BATTERY');
|
||||
@@ -113,57 +113,57 @@ function powerMonitor()
|
||||
this._acpiSink.self = this;
|
||||
require('linux-acpi').on('acpi', this._acpiSink);
|
||||
}
|
||||
if(process.platform == 'darwin')
|
||||
if (process.platform == 'darwin')
|
||||
{
|
||||
this._getBatteryLevel = function _getBatteryLevel()
|
||||
{
|
||||
var 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[2],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(e)
|
||||
{
|
||||
return({ac: 1, level: -1});
|
||||
}
|
||||
};
|
||||
this._batteryLevelCheck = function _batteryLevelCheck()
|
||||
{
|
||||
var newLevel = this._getBatteryLevel();
|
||||
if(newLevel.ac != this._ACState)
|
||||
{
|
||||
this._ACState = newLevel.ac;
|
||||
this.emit('acdc', this._ACState==1?'AC':'BATTERY');
|
||||
}
|
||||
if(newLevel.level != this._BatteryLevel)
|
||||
{
|
||||
this._BatteryLevel = newLevel.level;
|
||||
this.emit('batteryLevel', this._BatteryLevel);
|
||||
}
|
||||
};
|
||||
var tmp = this._getBatteryLevel();
|
||||
this._ACState = tmp.ac;
|
||||
this._BatteryLevel = tmp.level;
|
||||
this._getBatteryLevel = function _getBatteryLevel()
|
||||
{
|
||||
var 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[2],chg,"%");');
|
||||
child.stdin.write(' printf "{\\"ac\\": %s,\\"level\\": %s}",power, chg[1]; ');
|
||||
child.stdin.write("}'\nexit\n");
|
||||
child.waitExit();
|
||||
|
||||
if(this._BatteryLevel >= 0)
|
||||
{
|
||||
this._BattCheckInterval = setInterval(function (self)
|
||||
{
|
||||
self._batteryLevelCheck.call(self);
|
||||
}, 300000, this);
|
||||
}
|
||||
try
|
||||
{
|
||||
var info = JSON.parse(child.stdout.str.trim());
|
||||
return (info);
|
||||
}
|
||||
catch (e)
|
||||
{
|
||||
return ({ ac: 1, level: -1 });
|
||||
}
|
||||
};
|
||||
this._batteryLevelCheck = function _batteryLevelCheck()
|
||||
{
|
||||
var newLevel = this._getBatteryLevel();
|
||||
if (newLevel.ac != this._ACState)
|
||||
{
|
||||
this._ACState = newLevel.ac;
|
||||
this.emit('acdc', this._ACState == 1 ? 'AC' : 'BATTERY');
|
||||
}
|
||||
if (newLevel.level != this._BatteryLevel)
|
||||
{
|
||||
this._BatteryLevel = newLevel.level;
|
||||
this.emit('batteryLevel', this._BatteryLevel);
|
||||
}
|
||||
};
|
||||
var tmp = this._getBatteryLevel();
|
||||
this._ACState = tmp.ac;
|
||||
this._BatteryLevel = tmp.level;
|
||||
|
||||
if (this._BatteryLevel >= 0)
|
||||
{
|
||||
this._BattCheckInterval = setInterval(function (self)
|
||||
{
|
||||
self._batteryLevelCheck.call(self);
|
||||
}, 300000, this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user