1. Added polyfill for Array.findIndex() if missing

2. Added try/catch around indentiers module
This commit is contained in:
Bryan Roe 2021-08-16 12:57:17 -07:00
parent b58d7837a3
commit 1574a9bec9

View File

@ -46,6 +46,27 @@ var MESHRIGHT_CHATNOTIFY = 16384;
var MESHRIGHT_UNINSTALL = 32768; var MESHRIGHT_UNINSTALL = 32768;
var MESHRIGHT_NODESKTOP = 65536; var MESHRIGHT_NODESKTOP = 65536;
try
{
Object.defineProperty(Array.prototype, 'findIndex', {
value: function (func)
{
var i = 0;
for (i = 0; i < this.length; ++i)
{
if (func(this[i], i, this))
{
return (i);
}
}
return (-1);
}
});
}
catch (x)
{
}
if (require('MeshAgent').ARCHID == null) { if (require('MeshAgent').ARCHID == null) {
var id = null; var id = null;
switch (process.platform) { switch (process.platform) {
@ -409,28 +430,35 @@ if ((require('fs').existsSync(process.cwd() + 'batterystate.txt')) && (require('
}, 1000); }, 1000);
}); });
} }
else { else
// Setup normal battery monitoring {
if (require('identifiers').isBatteryPowered && require('identifiers').isBatteryPowered()) { try
require('MeshAgent')._battLevelChanged = function _battLevelChanged(val) { {
_battLevelChanged.self._currentBatteryLevel = val; // Setup normal battery monitoring
_battLevelChanged.self.SendCommand({ action: 'battery', state: _battLevelChanged.self._currentPowerState, level: val }); if (require('identifiers').isBatteryPowered && require('identifiers').isBatteryPowered()) {
}; require('MeshAgent')._battLevelChanged = function _battLevelChanged(val) {
require('MeshAgent')._battLevelChanged.self = require('MeshAgent'); _battLevelChanged.self._currentBatteryLevel = val;
require('MeshAgent')._powerChanged = function _powerChanged(val) { _battLevelChanged.self.SendCommand({ action: 'battery', state: _battLevelChanged.self._currentPowerState, level: val });
_powerChanged.self._currentPowerState = (val == 'AC' ? 'ac' : 'dc'); };
_powerChanged.self.SendCommand({ action: 'battery', state: (val == 'AC' ? 'ac' : 'dc'), level: _powerChanged.self._currentBatteryLevel }); require('MeshAgent')._battLevelChanged.self = require('MeshAgent');
}; require('MeshAgent')._powerChanged = function _powerChanged(val) {
require('MeshAgent')._powerChanged.self = require('MeshAgent'); _powerChanged.self._currentPowerState = (val == 'AC' ? 'ac' : 'dc');
require('MeshAgent').on('Connected', function (status) { _powerChanged.self.SendCommand({ action: 'battery', state: (val == 'AC' ? 'ac' : 'dc'), level: _powerChanged.self._currentBatteryLevel });
if (status == 0) { };
require('power-monitor').removeListener('acdc', this._powerChanged); require('MeshAgent')._powerChanged.self = require('MeshAgent');
require('power-monitor').removeListener('batteryLevel', this._battLevelChanged); require('MeshAgent').on('Connected', function (status) {
} else { if (status == 0) {
require('power-monitor').on('acdc', this._powerChanged); require('power-monitor').removeListener('acdc', this._powerChanged);
require('power-monitor').on('batteryLevel', this._battLevelChanged); require('power-monitor').removeListener('batteryLevel', this._battLevelChanged);
} } else {
}); require('power-monitor').on('acdc', this._powerChanged);
require('power-monitor').on('batteryLevel', this._battLevelChanged);
}
});
}
}
catch(e)
{
} }
} }