mirror of
https://github.com/Ylianst/MeshAgent
synced 2026-02-21 20:03:30 +00:00
Unified battery detection across platforms, and added support for linux.
This commit is contained in:
@@ -2591,6 +2591,17 @@ void MeshServer_SendAgentInfo(MeshAgentHostContainer* agent, ILibWebClient_State
|
||||
}
|
||||
}
|
||||
duk_pop(agent->meshCoreCtx);
|
||||
if (info->platformType != htonl(MeshCommand_AuthInfo_PlatformType_VIRTUAL))
|
||||
{
|
||||
if (duk_peval_string(agent->meshCoreCtx, "require('identifiers').isBatteryPowered();") == 0)
|
||||
{
|
||||
if (duk_get_boolean(agent->meshCoreCtx, -1))
|
||||
{
|
||||
info->platformType = htonl(MeshCommand_AuthInfo_PlatformType_LAPTOP);
|
||||
}
|
||||
}
|
||||
duk_pop(agent->meshCoreCtx);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -265,6 +265,39 @@ module.exports.isDocker = function isDocker()
|
||||
child.waitExit();
|
||||
return (child.stdout.str != '');
|
||||
};
|
||||
module.exports.isBatteryPowered = function isBatteryOperated()
|
||||
{
|
||||
var ret = false;
|
||||
switch(process.platform)
|
||||
{
|
||||
default:
|
||||
break;
|
||||
case 'linux':
|
||||
var devices = require('fs').readdirSync('/sys/class/power_supply');
|
||||
for (var i in devices)
|
||||
{
|
||||
if(require('fs').readFileSync('/sys/class/power_supply/' + devices[i] + '/type').toString().trim()=='Battery')
|
||||
{
|
||||
ret = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
case 'win32':
|
||||
var GM = require('_GenericMarshal');
|
||||
var stats = GM.CreateVariable(12);
|
||||
var kernel32 = GM.CreateNativeProxy('Kernel32.dll');
|
||||
kernel32.CreateMethod('GetSystemPowerStatus');
|
||||
if (kernel32.GetSystemPowerStatus(stats).Val != 0)
|
||||
{
|
||||
if(stats.toBuffer()[1] != 128 && stats.toBuffer()[1] != 255)
|
||||
{
|
||||
ret = true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
return (ret);
|
||||
};
|
||||
module.exports.isVM = function isVM()
|
||||
{
|
||||
var ret = false;
|
||||
|
||||
Reference in New Issue
Block a user