code cleanup

This commit is contained in:
Sebastian Hildebrandt 2021-01-22 17:14:00 +01:00
parent 2b0885220b
commit eb7c8993b8
10 changed files with 130 additions and 128 deletions

View File

@ -597,7 +597,7 @@ function getCpu() {
if (_linux) { if (_linux) {
let modelline = ''; let modelline = '';
let lines = []; let lines = [];
if (os.cpus()[0] && os.cpus()[0].model) modelline = os.cpus()[0].model; if (os.cpus()[0] && os.cpus()[0].model) { modelline = os.cpus()[0].model; }
exec('export LC_ALL=C; lscpu; echo -n "Governor: "; cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor 2>/dev/null; echo; unset LC_ALL', function (error, stdout) { exec('export LC_ALL=C; lscpu; echo -n "Governor: "; cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor 2>/dev/null; echo; unset LC_ALL', function (error, stdout) {
if (!error) { if (!error) {
lines = stdout.toString().split('\n'); lines = stdout.toString().split('\n');
@ -611,7 +611,7 @@ function getCpu() {
} }
if (result.speed === 0) { if (result.speed === 0) {
const current = getCpuCurrentSpeedSync(); const current = getCpuCurrentSpeedSync();
if (current.avg !== 0) result.speed = current.avg; if (current.avg !== 0) { result.speed = current.avg; }
} }
_cpu_speed = result.speed; _cpu_speed = result.speed;
result.speedMin = Math.round(parseFloat(util.getValue(lines, 'cpu min mhz').replace(/,/g, '.')) / 10.0) / 100; result.speedMin = Math.round(parseFloat(util.getValue(lines, 'cpu min mhz').replace(/,/g, '.')) / 10.0) / 100;
@ -672,7 +672,7 @@ function getCpu() {
if (_freebsd || _openbsd || _netbsd) { if (_freebsd || _openbsd || _netbsd) {
let modelline = ''; let modelline = '';
let lines = []; let lines = [];
if (os.cpus()[0] && os.cpus()[0].model) modelline = os.cpus()[0].model; if (os.cpus()[0] && os.cpus()[0].model) { modelline = os.cpus()[0].model; }
exec('export LC_ALL=C; dmidecode -t 4; dmidecode -t 7 unset LC_ALL', function (error, stdout) { exec('export LC_ALL=C; dmidecode -t 4; dmidecode -t 7 unset LC_ALL', function (error, stdout) {
let cache = []; let cache = [];
if (!error) { if (!error) {
@ -689,7 +689,7 @@ function getCpu() {
} }
if (result.speed === 0) { if (result.speed === 0) {
const current = getCpuCurrentSpeedSync(); const current = getCpuCurrentSpeedSync();
if (current.avg !== 0) result.speed = current.avg; if (current.avg !== 0) { result.speed = current.avg; }
} }
_cpu_speed = result.speed; _cpu_speed = result.speed;
result.speedMin = result.speed; result.speedMin = result.speed;
@ -829,7 +829,7 @@ function getCpu() {
resolve(result); resolve(result);
} }
} }
}) });
}); });
}); });
} }
@ -867,8 +867,8 @@ function getCpuCurrentSpeedSync() {
if ({}.hasOwnProperty.call(cpus, i)) { if ({}.hasOwnProperty.call(cpus, i)) {
let freq = cpus[i].speed > 100 ? (cpus[i].speed + 1) / 1000 : cpus[i].speed / 10; let freq = cpus[i].speed > 100 ? (cpus[i].speed + 1) / 1000 : cpus[i].speed / 10;
avgFreq = avgFreq + freq; avgFreq = avgFreq + freq;
if (freq > maxFreq) maxFreq = freq; if (freq > maxFreq) { maxFreq = freq; }
if (freq < minFreq) minFreq = freq; if (freq < minFreq) { minFreq = freq; }
cores.push(parseFloat(freq.toFixed(2))); cores.push(parseFloat(freq.toFixed(2)));
} }
} }
@ -1035,7 +1035,7 @@ function cpuTemperature(callback) {
const parts = line.split(':'); const parts = line.split(':');
if (parts.length > 1) { if (parts.length > 1) {
const temp = parseFloat(parts[1].replace(',', '.')); const temp = parseFloat(parts[1].replace(',', '.'));
if (temp > result.max) result.max = temp; if (temp > result.max) { result.max = temp; }
sum = sum + temp; sum = sum + temp;
result.cores.push(temp); result.cores.push(temp);
} }
@ -1075,7 +1075,7 @@ function cpuTemperature(callback) {
lines.forEach(function (line) { lines.forEach(function (line) {
let value = (parseInt(line, 10) - 2732) / 10; let value = (parseInt(line, 10) - 2732) / 10;
sum = sum + value; sum = sum + value;
if (value > result.max) result.max = value; if (value > result.max) { result.max = value; }
result.cores.push(value); result.cores.push(value);
}); });
if (result.cores.length) { if (result.cores.length) {

View File

@ -127,7 +127,7 @@ function dockerContainers(all, callback) {
// GC in _docker_container_stats // GC in _docker_container_stats
for (let key in _docker_container_stats) { for (let key in _docker_container_stats) {
if ({}.hasOwnProperty.call(_docker_container_stats, key)) { if ({}.hasOwnProperty.call(_docker_container_stats, key)) {
if (!inContainers(docker_containers, key)) delete _docker_container_stats[key]; if (!inContainers(docker_containers, key)) { delete _docker_container_stats[key]; }
} }
} }
@ -170,7 +170,7 @@ function dockerContainers(all, callback) {
// GC in _docker_container_stats // GC in _docker_container_stats
for (let key in _docker_container_stats) { for (let key in _docker_container_stats) {
if ({}.hasOwnProperty.call(_docker_container_stats, key)) { if ({}.hasOwnProperty.call(_docker_container_stats, key)) {
if (!inContainers(docker_containers, key)) delete _docker_container_stats[key]; if (!inContainers(docker_containers, key)) { delete _docker_container_stats[key]; }
} }
} }
if (callback) { callback(result); } if (callback) { callback(result); }
@ -276,7 +276,7 @@ function docker_calcNetworkIO(networks) {
let wx; let wx;
for (let key in networks) { for (let key in networks) {
// skip loop if the property is from prototype // skip loop if the property is from prototype
if (!{}.hasOwnProperty.call(networks, key)) continue; if (!{}.hasOwnProperty.call(networks, key)) { continue; }
/** /**
* @namespace * @namespace
@ -414,8 +414,8 @@ function dockerContainerStatsSingle(containerID) {
result.cpuPercent = (stats.cpu_stats && stats.precpu_stats ? docker_calcCPUPercent(stats.cpu_stats, stats.precpu_stats) : 0); result.cpuPercent = (stats.cpu_stats && stats.precpu_stats ? docker_calcCPUPercent(stats.cpu_stats, stats.precpu_stats) : 0);
result.pids = (stats.pids_stats && stats.pids_stats.current ? stats.pids_stats.current : 0); result.pids = (stats.pids_stats && stats.pids_stats.current ? stats.pids_stats.current : 0);
result.restartCount = (dataInspect.RestartCount ? dataInspect.RestartCount : 0); result.restartCount = (dataInspect.RestartCount ? dataInspect.RestartCount : 0);
if (stats.networks) result.netIO = docker_calcNetworkIO(stats.networks); if (stats.networks) { result.netIO = docker_calcNetworkIO(stats.networks); }
if (stats.blkio_stats) result.blockIO = docker_calcBlockIO(stats.blkio_stats); if (stats.blkio_stats) { result.blockIO = docker_calcBlockIO(stats.blkio_stats); }
result.cpuStats = (stats.cpu_stats ? stats.cpu_stats : {}); result.cpuStats = (stats.cpu_stats ? stats.cpu_stats : {});
result.precpuStats = (stats.precpu_stats ? stats.precpu_stats : {}); result.precpuStats = (stats.precpu_stats ? stats.precpu_stats : {});
result.memoryStats = (stats.memory_stats ? stats.memory_stats : {}); result.memoryStats = (stats.memory_stats ? stats.memory_stats : {});

View File

@ -42,8 +42,8 @@ function fsSize(callback) {
if (!fs.startsWith('/')) { return 'NFS'; } if (!fs.startsWith('/')) { return 'NFS'; }
const parts = fs.split('/'); const parts = fs.split('/');
const fsShort = parts[parts.length - 1]; const fsShort = parts[parts.length - 1];
const macOsDisksSingle = macOsDisks.filter(item => item.indexOf(fsShort) >= 0) const macOsDisksSingle = macOsDisks.filter(item => item.indexOf(fsShort) >= 0);
if (macOsDisksSingle.length === 1 && macOsDisksSingle[0].indexOf('APFS') >= 0) { return 'APFS' } if (macOsDisksSingle.length === 1 && macOsDisksSingle[0].indexOf('APFS') >= 0) { return 'APFS'; }
return 'HFS'; return 'HFS';
} }
@ -86,14 +86,14 @@ function fsSize(callback) {
cmd = 'df -kP'; cmd = 'df -kP';
try { try {
macOsDisks = execSync('diskutil list').toString().split('\n').filter(line => { macOsDisks = execSync('diskutil list').toString().split('\n').filter(line => {
return !line.startsWith('/') && line.indexOf(':') > 0 return !line.startsWith('/') && line.indexOf(':') > 0;
}); });
} catch (e) { } catch (e) {
macOsDisks = []; macOsDisks = [];
} }
} }
if (_linux) cmd = 'df -lkPTx squashfs | grep ^/'; if (_linux) { cmd = 'df -lkPTx squashfs | grep ^/'; }
if (_freebsd || _openbsd || _netbsd) cmd = 'df -lkPT'; if (_freebsd || _openbsd || _netbsd) { cmd = 'df -lkPT'; }
exec(cmd, function (error, stdout) { exec(cmd, function (error, stdout) {
if (!error) { if (!error) {
let lines = stdout.toString().split('\n'); let lines = stdout.toString().split('\n');
@ -231,39 +231,41 @@ function parseDevices(lines) {
} else { } else {
let parts = line.split(':'); let parts = line.split(':');
if (parts.length > 1) { if (parts.length > 1) {
if (!devices[i]) devices[i] = { if (!devices[i]) {
name: '', devices[i] = {
identifier: '', name: '',
type: 'disk', identifier: '',
fsType: '', type: 'disk',
mount: '', fsType: '',
size: 0, mount: '',
physical: 'HDD', size: 0,
uuid: '', physical: 'HDD',
label: '', uuid: '',
model: '', label: '',
serial: '', model: '',
removable: false, serial: '',
protocol: '' removable: false,
}; protocol: ''
};
}
parts[0] = parts[0].trim().toUpperCase().replace(/ +/g, ''); parts[0] = parts[0].trim().toUpperCase().replace(/ +/g, '');
parts[1] = parts[1].trim(); parts[1] = parts[1].trim();
if ('DEVICEIDENTIFIER' === parts[0]) devices[i].identifier = parts[1]; if ('DEVICEIDENTIFIER' === parts[0]) { devices[i].identifier = parts[1]; }
if ('DEVICENODE' === parts[0]) devices[i].name = parts[1]; if ('DEVICENODE' === parts[0]) { devices[i].name = parts[1]; }
if ('VOLUMENAME' === parts[0]) { if ('VOLUMENAME' === parts[0]) {
if (parts[1].indexOf('Not applicable') === -1) devices[i].label = parts[1]; if (parts[1].indexOf('Not applicable') === -1) { devices[i].label = parts[1]; }
} }
if ('PROTOCOL' === parts[0]) devices[i].protocol = parts[1]; if ('PROTOCOL' === parts[0]) { devices[i].protocol = parts[1]; }
if ('DISKSIZE' === parts[0]) devices[i].size = parseBytes(parts[1]); if ('DISKSIZE' === parts[0]) { devices[i].size = parseBytes(parts[1]); }
if ('FILESYSTEMPERSONALITY' === parts[0]) devices[i].fsType = parts[1]; if ('FILESYSTEMPERSONALITY' === parts[0]) { devices[i].fsType = parts[1]; }
if ('MOUNTPOINT' === parts[0]) devices[i].mount = parts[1]; if ('MOUNTPOINT' === parts[0]) { devices[i].mount = parts[1]; }
if ('VOLUMEUUID' === parts[0]) devices[i].uuid = parts[1]; if ('VOLUMEUUID' === parts[0]) { devices[i].uuid = parts[1]; }
if ('READ-ONLYMEDIA' === parts[0] && parts[1] === 'Yes') devices[i].physical = 'CD/DVD'; if ('READ-ONLYMEDIA' === parts[0] && parts[1] === 'Yes') { devices[i].physical = 'CD/DVD'; }
if ('SOLIDSTATE' === parts[0] && parts[1] === 'Yes') devices[i].physical = 'SSD'; if ('SOLIDSTATE' === parts[0] && parts[1] === 'Yes') { devices[i].physical = 'SSD'; }
if ('VIRTUAL' === parts[0]) devices[i].type = 'virtual'; if ('VIRTUAL' === parts[0]) { devices[i].type = 'virtual'; }
if ('REMOVABLEMEDIA' === parts[0]) devices[i].removable = (parts[1] === 'Removable'); if ('REMOVABLEMEDIA' === parts[0]) { devices[i].removable = (parts[1] === 'Removable'); }
if ('PARTITIONTYPE' === parts[0]) devices[i].type = 'part'; if ('PARTITIONTYPE' === parts[0]) { devices[i].type = 'part'; }
if ('DEVICE/MEDIANAME' === parts[0]) devices[i].model = parts[1]; if ('DEVICE/MEDIANAME' === parts[0]) { devices[i].model = parts[1]; }
} }
} }
} }
@ -496,7 +498,7 @@ function fsStats(callback) {
lines.forEach(function (line) { lines.forEach(function (line) {
if (line !== '') { if (line !== '') {
line = line.replace(/[├─│└]+/g, '').trim().split(' '); line = line.replace(/[├─│└]+/g, '').trim().split(' ');
if (fs_filter.indexOf(line[0]) === -1) fs_filter.push(line[0]); if (fs_filter.indexOf(line[0]) === -1) { fs_filter.push(line[0]); }
} }
}); });
@ -643,7 +645,7 @@ function disksIO(callback) {
let lines = stdout.split('\n'); let lines = stdout.split('\n');
lines.forEach(function (line) { lines.forEach(function (line) {
// ignore empty lines // ignore empty lines
if (!line) return; if (!line) { return; }
// sum r/wIO of all disks to compute all disks IO // sum r/wIO of all disks to compute all disks IO
let stats = line.split(';'); let stats = line.split(';');

View File

@ -132,8 +132,8 @@ function graphics(callback) {
lastlevel = level; lastlevel = level;
let parts = lines[i].split(':'); let parts = lines[i].split(':');
if (2 === level) { // grafics controller level if (2 === level) { // grafics controller level
if (parts.length > 1 && parts[0].replace(/ +/g, '').toLowerCase().indexOf('chipsetmodel') !== -1) currentController.model = parts[1].trim(); if (parts.length > 1 && parts[0].replace(/ +/g, '').toLowerCase().indexOf('chipsetmodel') !== -1) { currentController.model = parts[1].trim(); }
if (parts.length > 1 && parts[0].replace(/ +/g, '').toLowerCase().indexOf('vendor') !== -1) currentController.vendor = parts[1].split('(')[0].trim(); if (parts.length > 1 && parts[0].replace(/ +/g, '').toLowerCase().indexOf('vendor') !== -1) { currentController.vendor = parts[1].split('(')[0].trim(); }
if (parts.length > 1 && parts[0].replace(/ +/g, '').toLowerCase().indexOf('vram(total)') !== -1) { if (parts.length > 1 && parts[0].replace(/ +/g, '').toLowerCase().indexOf('vram(total)') !== -1) {
currentController.vram = parseInt(parts[1]); // in MB currentController.vram = parseInt(parts[1]); // in MB
if (parts[1].toLowerCase().indexOf('gb') !== -1) { if (parts[1].toLowerCase().indexOf('gb') !== -1) {
@ -177,9 +177,9 @@ function graphics(callback) {
currentDisplay.currentResX = currentDisplay.resolutionX; currentDisplay.currentResX = currentDisplay.resolutionX;
currentDisplay.currentResY = currentDisplay.resolutionY; currentDisplay.currentResY = currentDisplay.resolutionY;
} }
if (parts.length > 1 && parts[0].replace(/ +/g, '').toLowerCase().indexOf('pixeldepth') !== -1) currentDisplay.pixelDepth = parseInt(parts[1]); // in BIT if (parts.length > 1 && parts[0].replace(/ +/g, '').toLowerCase().indexOf('pixeldepth') !== -1) { currentDisplay.pixelDepth = parseInt(parts[1]); } // in BIT
if (parts.length > 1 && parts[0].replace(/ +/g, '').toLowerCase().indexOf('framebufferdepth') !== -1) currentDisplay.pixelDepth = parseInt(parts[1]); // in BIT if (parts.length > 1 && parts[0].replace(/ +/g, '').toLowerCase().indexOf('framebufferdepth') !== -1) { currentDisplay.pixelDepth = parseInt(parts[1]); } // in BIT
if (parts.length > 1 && parts[0].replace(/ +/g, '').toLowerCase().indexOf('maindisplay') !== -1 && parts[1].replace(/ +/g, '').toLowerCase() === 'yes') currentDisplay.main = true; if (parts.length > 1 && parts[0].replace(/ +/g, '').toLowerCase().indexOf('maindisplay') !== -1 && parts[1].replace(/ +/g, '').toLowerCase() === 'yes') { currentDisplay.main = true; }
if (parts.length > 1 && parts[0].replace(/ +/g, '').toLowerCase().indexOf('built-in') !== -1 && parts[1].replace(/ +/g, '').toLowerCase() === 'yes') { if (parts.length > 1 && parts[0].replace(/ +/g, '').toLowerCase().indexOf('built-in') !== -1 && parts[1].replace(/ +/g, '').toLowerCase() === 'yes') {
currentDisplay.vendor = 'Apple'; currentDisplay.vendor = 'Apple';
currentDisplay.builtin = true; currentDisplay.builtin = true;
@ -299,7 +299,7 @@ function graphics(callback) {
} }
if (isGraphicsController) { // within VGA details if (isGraphicsController) { // within VGA details
let parts = lines[i].split(':'); let parts = lines[i].split(':');
if (parts.length > 1 && parts[0].replace(/ +/g, '').toLowerCase().indexOf('devicename') !== -1 && parts[1].toLowerCase().indexOf('onboard') !== -1) currentController.bus = 'Onboard'; if (parts.length > 1 && parts[0].replace(/ +/g, '').toLowerCase().indexOf('devicename') !== -1 && parts[1].toLowerCase().indexOf('onboard') !== -1) { currentController.bus = 'Onboard'; }
if (parts.length > 1 && parts[0].replace(/ +/g, '').toLowerCase().indexOf('region') !== -1 && parts[1].toLowerCase().indexOf('memory') !== -1) { if (parts.length > 1 && parts[0].replace(/ +/g, '').toLowerCase().indexOf('region') !== -1 && parts[1].toLowerCase().indexOf('memory') !== -1) {
let memparts = parts[1].split('='); let memparts = parts[1].split('=');
if (memparts.length > 1) { if (memparts.length > 1) {
@ -325,7 +325,7 @@ function graphics(callback) {
} }
devices[field[1]][field[2]] = field[3]; devices[field[1]][field[2]] = field[3];
} }
return devices return devices;
}, {}); }, {});
for (let deviceId in devices) { for (let deviceId in devices) {
const device = devices[deviceId]; const device = devices[deviceId];
@ -398,7 +398,7 @@ function graphics(callback) {
_nvidiaSmiPath = [basePath, targetDir, 'nvidia-smi.exe'].join('/'); _nvidiaSmiPath = [basePath, targetDir, 'nvidia-smi.exe'].join('/');
} }
} catch (e) { } catch (e) {
util.noop() util.noop();
} }
} else if (_linux) { } else if (_linux) {
_nvidiaSmiPath = 'nvidia-smi'; _nvidiaSmiPath = 'nvidia-smi';
@ -409,7 +409,7 @@ function graphics(callback) {
function nvidiaSmi(options) { function nvidiaSmi(options) {
const nvidiaSmiExe = getNvidiaSmi(); const nvidiaSmiExe = getNvidiaSmi();
if (nvidiaSmiExe) { if (nvidiaSmiExe) {
const nvidiaSmiOpts = '--query-gpu=driver_version,pci.sub_device_id,name,pci.bus_id,fan.speed,memory.total,memory.used,memory.free,utilization.gpu,utilization.memory,temperature.gpu,temperature.memory,power.draw,power.limit,clocks.gr,clocks.mem --format=csv,noheader,nounits' const nvidiaSmiOpts = '--query-gpu=driver_version,pci.sub_device_id,name,pci.bus_id,fan.speed,memory.total,memory.used,memory.free,utilization.gpu,utilization.memory,temperature.gpu,temperature.memory,power.draw,power.limit,clocks.gr,clocks.mem --format=csv,noheader,nounits';
const cmd = nvidiaSmiExe + ' ' + nvidiaSmiOpts + (_linux ? ' 2>/dev/null' : ''); const cmd = nvidiaSmiExe + ' ' + nvidiaSmiOpts + (_linux ? ' 2>/dev/null' : '');
try { try {
const res = execSync(cmd, options).toString(); const res = execSync(cmd, options).toString();
@ -456,7 +456,7 @@ function graphics(callback) {
powerLimit: safeParseNumber(splittedData[13]), powerLimit: safeParseNumber(splittedData[13]),
clockCore: safeParseNumber(splittedData[14]), clockCore: safeParseNumber(splittedData[14]),
clockMemory: safeParseNumber(splittedData[15]), clockMemory: safeParseNumber(splittedData[15]),
} };
} }
}); });
@ -728,9 +728,9 @@ function graphics(callback) {
// needs to be rewritten ... using no spread operators // needs to be rewritten ... using no spread operators
result.controllers = result.controllers.map((controller) => { // match by busAddress result.controllers = result.controllers.map((controller) => { // match by busAddress
return mergeControllerNvidia(controller, nvidiaData.find(({ pciBus }) => pciBus.endsWith(controller.busAddress)) || {}); return mergeControllerNvidia(controller, nvidiaData.find(({ pciBus }) => pciBus.endsWith(controller.busAddress)) || {});
}) });
} }
let cmd = "clinfo --raw"; let cmd = 'clinfo --raw';
exec(cmd, function (error, stdout) { exec(cmd, function (error, stdout) {
if (!error) { if (!error) {
let lines = stdout.toString().split('\n'); let lines = stdout.toString().split('\n');

View File

@ -145,9 +145,9 @@ function getDynamicData(srv, iface, callback) {
// use closure to track ƒ completion // use closure to track ƒ completion
let functionProcessed = (function () { let functionProcessed = (function () {
let totalFunctions = 15; let totalFunctions = 15;
if (_windows) totalFunctions = 11; if (_windows) { totalFunctions = 11; }
if (_freebsd || _openbsd || _netbsd) totalFunctions = 11; if (_freebsd || _openbsd || _netbsd) { totalFunctions = 11; }
if (_sunos) totalFunctions = 6; if (_sunos) { totalFunctions = 6; }
return function () { return function () {
if (--totalFunctions === 0) { if (--totalFunctions === 0) {
@ -329,9 +329,9 @@ function get(valueObject, callback) {
let funcWithoutParams = func.indexOf(')') >= 0 ? func.split(')')[1].trim() : func; let funcWithoutParams = func.indexOf(')') >= 0 ? func.split(')')[1].trim() : func;
funcWithoutParams = func.indexOf('|') >= 0 ? func.split('|')[0].trim() : funcWithoutParams; funcWithoutParams = func.indexOf('|') >= 0 ? func.split('|')[0].trim() : funcWithoutParams;
if (params) { if (params) {
return exports[funcWithoutParams](params) return exports[funcWithoutParams](params);
} else { } else {
return exports[funcWithoutParams]('') return exports[funcWithoutParams]('');
} }
}); });

View File

@ -184,7 +184,7 @@ function mem(callback) {
const cache = parseInt(util.getValue(lines, 'vm.stats.vm.v_cache_count'), 10) * pagesize; const cache = parseInt(util.getValue(lines, 'vm.stats.vm.v_cache_count'), 10) * pagesize;
result.total = parseInt(util.getValue(lines, 'hw.realmem'), 10); result.total = parseInt(util.getValue(lines, 'hw.realmem'), 10);
if (isNaN(result.total)) result.total = parseInt(util.getValue(lines, 'hw.physmem'), 10); if (isNaN(result.total)) { result.total = parseInt(util.getValue(lines, 'hw.physmem'), 10); }
result.free = parseInt(util.getValue(lines, 'vm.stats.vm.v_free_count'), 10) * pagesize; result.free = parseInt(util.getValue(lines, 'vm.stats.vm.v_free_count'), 10) * pagesize;
result.buffcache = inactive + cache; result.buffcache = inactive + cache;
result.available = result.buffcache + result.free; result.available = result.buffcache + result.free;
@ -219,9 +219,9 @@ function mem(callback) {
let line = lines[0].replace(/,/g, '.').replace(/M/g, ''); let line = lines[0].replace(/,/g, '.').replace(/M/g, '');
line = line.trim().split(' '); line = line.trim().split(' ');
for (let i = 0; i < line.length; i++) { for (let i = 0; i < line.length; i++) {
if (line[i].toLowerCase().indexOf('total') !== -1) result.swaptotal = parseFloat(line[i].split('=')[1].trim()) * 1024 * 1024; if (line[i].toLowerCase().indexOf('total') !== -1) { result.swaptotal = parseFloat(line[i].split('=')[1].trim()) * 1024 * 1024; }
if (line[i].toLowerCase().indexOf('used') !== -1) result.swapused = parseFloat(line[i].split('=')[1].trim()) * 1024 * 1024; if (line[i].toLowerCase().indexOf('used') !== -1) { result.swapused = parseFloat(line[i].split('=')[1].trim()) * 1024 * 1024; }
if (line[i].toLowerCase().indexOf('free') !== -1) result.swapfree = parseFloat(line[i].split('=')[1].trim()) * 1024 * 1024; if (line[i].toLowerCase().indexOf('free') !== -1) { result.swapfree = parseFloat(line[i].split('=')[1].trim()) * 1024 * 1024; }
} }
} }
} }

View File

@ -36,10 +36,10 @@ const winPrinterStatus = {
5: 'Warmup', 5: 'Warmup',
6: 'Stopped Printing', 6: 'Stopped Printing',
7: 'Offline', 7: 'Offline',
} };
function parseLinuxCupsHeader(lines) { function parseLinuxCupsHeader(lines) {
const result = {} const result = {};
if (lines && lines.length) { if (lines && lines.length) {
if (lines[0].indexOf(' CUPS v') > 0) { if (lines[0].indexOf(' CUPS v') > 0) {
const parts = lines[0].split(' CUPS v'); const parts = lines[0].split(' CUPS v');
@ -67,12 +67,12 @@ function parseLinuxCupsPrinter(lines) {
function parseLinuxLpstatPrinter(lines, id) { function parseLinuxLpstatPrinter(lines, id) {
const result = {}; const result = {};
result.id = id result.id = id;
result.name = util.getValue(lines, 'Description', ':', true); result.name = util.getValue(lines, 'Description', ':', true);
result.model = lines.length > 0 && lines[0] ? lines[0].split(' ')[0] : ''; result.model = lines.length > 0 && lines[0] ? lines[0].split(' ')[0] : '';
result.uri = null; result.uri = null;
result.uuid = null result.uuid = null;
result.status = lines.length > 0 && lines[0] ? (lines[0].indexOf(' idle') > 0 ? 'idle' : (lines[0].indexOf(' printing') > 0 ? 'printing' : 'unknown')) : null result.status = lines.length > 0 && lines[0] ? (lines[0].indexOf(' idle') > 0 ? 'idle' : (lines[0].indexOf(' printing') > 0 ? 'printing' : 'unknown')) : null;
result.local = util.getValue(lines, 'Location', ':', true).toLowerCase().startsWith('local'); result.local = util.getValue(lines, 'Location', ':', true).toLowerCase().startsWith('local');
result.default = null; result.default = null;
result.shared = util.getValue(lines, 'Shared', ' ').toLowerCase().startsWith('yes'); result.shared = util.getValue(lines, 'Shared', ' ').toLowerCase().startsWith('yes');
@ -84,10 +84,10 @@ function parseDarwinPrinters(printerObject, id) {
const result = {}; const result = {};
const uriParts = printerObject.uri.split('/'); const uriParts = printerObject.uri.split('/');
result.id = id; result.id = id;
result.name = printerObject._name result.name = printerObject._name;
result.model = uriParts.length ? uriParts[uriParts.length - 1] : ''; result.model = uriParts.length ? uriParts[uriParts.length - 1] : '';
result.uri = printerObject.uri; result.uri = printerObject.uri;
result.uuid = null result.uuid = null;
result.status = printerObject.status; result.status = printerObject.status;
result.local = printerObject.printserver === 'local'; result.local = printerObject.printserver === 'local';
result.default = printerObject.default === 'yes'; result.default = printerObject.default === 'yes';
@ -104,7 +104,7 @@ function parseWindowsPrinters(lines, id) {
result.name = util.getValue(lines, 'name', '='); result.name = util.getValue(lines, 'name', '=');
result.model = util.getValue(lines, 'DriverName', '='); result.model = util.getValue(lines, 'DriverName', '=');
result.uri = null; result.uri = null;
result.uuid = null result.uuid = null;
result.status = winPrinterStatus[status] ? winPrinterStatus[status] : null; result.status = winPrinterStatus[status] ? winPrinterStatus[status] : null;
result.local = util.getValue(lines, 'Local', '=') === 'TRUE'; result.local = util.getValue(lines, 'Local', '=') === 'TRUE';
result.default = util.getValue(lines, 'Default', '=') === 'TRUE'; result.default = util.getValue(lines, 'Default', '=') === 'TRUE';
@ -119,7 +119,7 @@ function printer(callback) {
process.nextTick(() => { process.nextTick(() => {
let result = []; let result = [];
if (_linux || _freebsd || _openbsd || _netbsd) { if (_linux || _freebsd || _openbsd || _netbsd) {
let cmd = 'cat /etc/cups/printers.conf 2>/dev/null' let cmd = 'cat /etc/cups/printers.conf 2>/dev/null';
exec(cmd, function (error, stdout) { exec(cmd, function (error, stdout) {
// printers.conf // printers.conf
if (!error) { if (!error) {
@ -164,7 +164,7 @@ function printer(callback) {
}); });
} }
if (_darwin) { if (_darwin) {
let cmd = 'system_profiler SPPrintersDataType -json' let cmd = 'system_profiler SPPrintersDataType -json';
exec(cmd, function (error, stdout) { exec(cmd, function (error, stdout) {
if (!error) { if (!error) {
try { try {
@ -176,7 +176,7 @@ function printer(callback) {
} }
} }
} catch (e) { } catch (e) {
util.noop() util.noop();
} }
} }
if (callback) { if (callback) {
@ -190,7 +190,7 @@ function printer(callback) {
if (!error) { if (!error) {
const parts = stdout.toString().split(/\n\s*\n/); const parts = stdout.toString().split(/\n\s*\n/);
for (let i = 0; i < parts.length; i++) { for (let i = 0; i < parts.length; i++) {
result.push(parseWindowsPrinters(parts[i].split('\n'), i)) result.push(parseWindowsPrinters(parts[i].split('\n'), i));
} }
} }
if (callback) { if (callback) {

View File

@ -519,7 +519,7 @@ function processes(callback) {
state = (state[0] === 'R' ? 'running' : (state[0] === 'S' ? 'sleeping' : (state[0] === 'T' ? 'stopped' : (state[0] === 'W' ? 'paging' : (state[0] === 'X' ? 'dead' : (state[0] === 'Z' ? 'zombie' : ((state[0] === 'D' || state[0] === 'U') ? 'blocked' : 'unknown'))))))); state = (state[0] === 'R' ? 'running' : (state[0] === 'S' ? 'sleeping' : (state[0] === 'T' ? 'stopped' : (state[0] === 'W' ? 'paging' : (state[0] === 'X' ? 'dead' : (state[0] === 'Z' ? 'zombie' : ((state[0] === 'D' || state[0] === 'U') ? 'blocked' : 'unknown')))))));
checkColumn(10); checkColumn(10);
let tty = line.substring(parsedhead[10].from + offset, parsedhead[10].to + offset2).trim(); let tty = line.substring(parsedhead[10].from + offset, parsedhead[10].to + offset2).trim();
if (tty === '?' || tty === '??') tty = ''; if (tty === '?' || tty === '??') { tty = ''; }
checkColumn(11); checkColumn(11);
const user = line.substring(parsedhead[11].from + offset, parsedhead[11].to + offset2).trim(); const user = line.substring(parsedhead[11].from + offset, parsedhead[11].to + offset2).trim();
checkColumn(12); checkColumn(12);
@ -652,10 +652,10 @@ function processes(callback) {
if ((_processes_cpu.ms && Date.now() - _processes_cpu.ms >= 500) || _processes_cpu.ms === 0) { if ((_processes_cpu.ms && Date.now() - _processes_cpu.ms >= 500) || _processes_cpu.ms === 0) {
if (_linux || _freebsd || _openbsd || _netbsd || _darwin || _sunos) { if (_linux || _freebsd || _openbsd || _netbsd || _darwin || _sunos) {
if (_linux) cmd = 'export LC_ALL=C; ps -axo pid:11,ppid:11,pcpu:6,pmem:6,pri:5,vsz:11,rss:11,ni:5,lstart:30,state:5,tty:15,user:20,command; unset LC_ALL'; if (_linux) { cmd = 'export LC_ALL=C; ps -axo pid:11,ppid:11,pcpu:6,pmem:6,pri:5,vsz:11,rss:11,ni:5,lstart:30,state:5,tty:15,user:20,command; unset LC_ALL'; }
if (_freebsd || _openbsd || _netbsd) cmd = 'export LC_ALL=C; ps -axo pid,ppid,pcpu,pmem,pri,vsz,rss,ni,lstart,state,tty,user,command; unset LC_ALL'; if (_freebsd || _openbsd || _netbsd) { cmd = 'export LC_ALL=C; ps -axo pid,ppid,pcpu,pmem,pri,vsz,rss,ni,lstart,state,tty,user,command; unset LC_ALL'; }
if (_darwin) cmd = 'export LC_ALL=C; ps -axo pid,ppid,pcpu,pmem,pri,vsz,rss,nice,lstart,state,tty,user,command -r; unset LC_ALL'; if (_darwin) { cmd = 'export LC_ALL=C; ps -axo pid,ppid,pcpu,pmem,pri,vsz,rss,nice,lstart,state,tty,user,command -r; unset LC_ALL'; }
if (_sunos) cmd = 'ps -Ao pid,ppid,pcpu,pmem,pri,vsz,rss,nice,stime,s,tty,user,comm'; if (_sunos) { cmd = 'ps -Ao pid,ppid,pcpu,pmem,pri,vsz,rss,nice,stime,s,tty,user,comm'; }
exec(cmd, { maxBuffer: 1024 * 20000 }, function (error, stdout) { exec(cmd, { maxBuffer: 1024 * 20000 }, function (error, stdout) {
if (!error) { if (!error) {
result.list = (parseProcesses(stdout.toString().split('\n'))).slice(); result.list = (parseProcesses(stdout.toString().split('\n'))).slice();
@ -955,7 +955,7 @@ function processLoad(proc, callback) {
inList = true; inList = true;
pname = proc; pname = proc;
} }
}) });
if (processesString === '*' || inList) { if (processesString === '*' || inList) {
let processFound = false; let processFound = false;
@ -965,7 +965,7 @@ function processLoad(proc, callback) {
item.mem += mem / os.totalmem() * 100; item.mem += mem / os.totalmem() * 100;
processFound = true; processFound = true;
} }
}) });
if (!processFound) { if (!processFound) {
result.push({ result.push({
proc: pname, proc: pname,
@ -973,7 +973,7 @@ function processLoad(proc, callback) {
pids: [pid], pids: [pid],
cpu: 0, cpu: 0,
mem: mem / os.totalmem() * 100 mem: mem / os.totalmem() * 100
}) });
} }
} }
} }
@ -982,7 +982,7 @@ function processLoad(proc, callback) {
if (processesString !== '*') { if (processesString !== '*') {
let processesMissing = processes.filter(function (name) { let processesMissing = processes.filter(function (name) {
// return procStats.filter(function(item) { return item.name.toLowerCase() === name }).length === 0; // return procStats.filter(function(item) { return item.name.toLowerCase() === name }).length === 0;
return procStats.filter(function (item) { return item.name.toLowerCase().indexOf(name) >= 0 }).length === 0; return procStats.filter(function (item) { return item.name.toLowerCase().indexOf(name) >= 0; }).length === 0;
}); });
processesMissing.forEach(function (procName) { processesMissing.forEach(function (procName) {
@ -1040,12 +1040,12 @@ function processLoad(proc, callback) {
if (!error) { if (!error) {
let procStats = []; let procStats = [];
let lines = stdout.toString().split('\n').filter(function (line) { let lines = stdout.toString().split('\n').filter(function (line) {
if (processesString === '*') return true; if (processesString === '*') { return true; }
if (line.toLowerCase().indexOf('grep') !== -1) return false; // remove this?? if (line.toLowerCase().indexOf('grep') !== -1) { return false; } // remove this??
let found = false; let found = false;
processes.forEach(function (item) { processes.forEach(function (item) {
found = found || (line.toLowerCase().indexOf(item.toLowerCase()) >= 0) found = found || (line.toLowerCase().indexOf(item.toLowerCase()) >= 0);
}) });
return found; return found;
}); });
@ -1057,14 +1057,14 @@ function processLoad(proc, callback) {
pid: parseInt(data[0]) || 0, pid: parseInt(data[0]) || 0,
cpu: parseFloat(data[1].replace(',', '.')), cpu: parseFloat(data[1].replace(',', '.')),
mem: parseFloat(data[2].replace(',', '.')) mem: parseFloat(data[2].replace(',', '.'))
}) });
} }
}); });
procStats.forEach(function (item) { procStats.forEach(function (item) {
let listPos = -1; let listPos = -1;
let inList = false; let inList = false;
let name = '' let name = '';
for (let j = 0; j < result.length; j++) { for (let j = 0; j < result.length; j++) {
// if (result[j].proc.toLowerCase() === item.name.toLowerCase()) { // if (result[j].proc.toLowerCase() === item.name.toLowerCase()) {
// if (result[j].proc.toLowerCase().indexOf(item.name.toLowerCase()) >= 0) { // if (result[j].proc.toLowerCase().indexOf(item.name.toLowerCase()) >= 0) {
@ -1081,7 +1081,7 @@ function processLoad(proc, callback) {
inList = true; inList = true;
name = proc; name = proc;
} }
}) });
// console.log(item); // console.log(item);
// console.log(listPos); // console.log(listPos);
if ((processesString === '*') || inList) { if ((processesString === '*') || inList) {
@ -1092,19 +1092,19 @@ function processLoad(proc, callback) {
pids: [item.pid], pids: [item.pid],
cpu: item.cpu, cpu: item.cpu,
mem: item.mem mem: item.mem
}) });
} else { } else {
result[listPos].pids.push(item.pid); result[listPos].pids.push(item.pid);
result[listPos].cpu += item.cpu; result[listPos].cpu += item.cpu;
result[listPos].mem += item.mem; result[listPos].mem += item.mem;
} }
} }
}) });
if (processesString !== '*') { if (processesString !== '*') {
// add missing processes // add missing processes
let processesMissing = processes.filter(function (name) { let processesMissing = processes.filter(function (name) {
return procStats.filter(function (item) { return item.name.toLowerCase().indexOf(name) >= 0 }).length === 0; return procStats.filter(function (item) { return item.name.toLowerCase().indexOf(name) >= 0; }).length === 0;
}); });
processesMissing.forEach(function (procName) { processesMissing.forEach(function (procName) {
result.push({ result.push({
@ -1120,7 +1120,7 @@ function processLoad(proc, callback) {
// calc process_cpu - ps is not accurate in linux! // calc process_cpu - ps is not accurate in linux!
result.forEach(function (item) { result.forEach(function (item) {
item.cpu = 0; item.cpu = 0;
}) });
let cmd = 'cat /proc/stat | grep "cpu "'; let cmd = 'cat /proc/stat | grep "cpu "';
for (let i in result) { for (let i in result) {
for (let j in result[i].pids) { for (let j in result[i].pids) {
@ -1168,7 +1168,7 @@ function processLoad(proc, callback) {
result.forEach(function (item) { result.forEach(function (item) {
item.cpu = Math.round(item.cpu * 100) / 100; item.cpu = Math.round(item.cpu * 100) / 100;
}) });
_process_cpu.all = all; _process_cpu.all = all;
// _process_cpu.list = list_new; // _process_cpu.list = list_new;

View File

@ -70,11 +70,11 @@ function system(callback) {
} catch (e) { } catch (e) {
util.noop(); util.noop();
} }
if (!result.serial || result.serial.toLowerCase().indexOf('o.e.m.') !== -1) result.serial = '-'; if (!result.serial || result.serial.toLowerCase().indexOf('o.e.m.') !== -1) { result.serial = '-'; }
if (!result.manufacturer || result.manufacturer.toLowerCase().indexOf('o.e.m.') !== -1) result.manufacturer = ''; if (!result.manufacturer || result.manufacturer.toLowerCase().indexOf('o.e.m.') !== -1) { result.manufacturer = ''; }
if (!result.model || result.model.toLowerCase().indexOf('o.e.m.') !== -1) result.model = 'Computer'; if (!result.model || result.model.toLowerCase().indexOf('o.e.m.') !== -1) { result.model = 'Computer'; }
if (!result.version || result.version.toLowerCase().indexOf('o.e.m.') !== -1) result.version = ''; if (!result.version || result.version.toLowerCase().indexOf('o.e.m.') !== -1) { result.version = ''; }
if (!result.sku || result.sku.toLowerCase().indexOf('o.e.m.') !== -1) result.sku = '-'; if (!result.sku || result.sku.toLowerCase().indexOf('o.e.m.') !== -1) { result.sku = '-'; }
// detect virtual (1) // detect virtual (1)
if (result.model.toLowerCase() === 'virtualbox' || result.model.toLowerCase() === 'kvm' || result.model.toLowerCase() === 'virtual machine' || result.model.toLowerCase() === 'bochs' || result.model.toLowerCase().startsWith('vmware') || result.model.toLowerCase().startsWith('droplet')) { if (result.model.toLowerCase() === 'virtualbox' || result.model.toLowerCase() === 'kvm' || result.model.toLowerCase() === 'virtual machine' || result.model.toLowerCase() === 'bochs' || result.model.toLowerCase().startsWith('vmware') || result.model.toLowerCase().startsWith('droplet')) {
@ -117,7 +117,7 @@ function system(callback) {
result.virtualHost = 'VirtualBox'; result.virtualHost = 'VirtualBox';
} }
} catch (e) { } catch (e) {
util.noop(); util.noop();
} }
} }
if ((_freebsd || _openbsd || _netbsd) && !result.virtualHost) { if ((_freebsd || _openbsd || _netbsd) && !result.virtualHost) {
@ -148,7 +148,7 @@ function system(callback) {
result.model = 'Docker Container'; result.model = 'Docker Container';
} }
try { try {
const stdout = execSync('dmesg | grep -iE "virtual|hypervisor" | grep -iE "vmware|qemu|kvm|xen"') const stdout = execSync('dmesg | grep -iE "virtual|hypervisor" | grep -iE "vmware|qemu|kvm|xen"');
// detect virtual machines // detect virtual machines
let lines = stdout.toString().split('\n'); let lines = stdout.toString().split('\n');
if (lines.length > 0) { if (lines.length > 0) {
@ -405,7 +405,7 @@ function system(callback) {
if (callback) { callback(result); } if (callback) { callback(result); }
resolve(result); resolve(result);
} }
}) });
} else { } else {
if (callback) { callback(result); } if (callback) { callback(result); }
resolve(result); resolve(result);
@ -478,11 +478,11 @@ function bios(callback) {
const hardwareData = JSON.parse(stdout.toString()); const hardwareData = JSON.parse(stdout.toString());
if (hardwareData && hardwareData.SPHardwareDataType && hardwareData.SPHardwareDataType.length) { if (hardwareData && hardwareData.SPHardwareDataType && hardwareData.SPHardwareDataType.length) {
let bootRomVersion = hardwareData.SPHardwareDataType[0].boot_rom_version; let bootRomVersion = hardwareData.SPHardwareDataType[0].boot_rom_version;
bootRomVersion = bootRomVersion ? bootRomVersion.split('(')[0].trim() : null bootRomVersion = bootRomVersion ? bootRomVersion.split('(')[0].trim() : null;
result.version = bootRomVersion; result.version = bootRomVersion;
} }
} catch (e) { } catch (e) {
util.noop() util.noop();
} }
if (callback) { callback(result); } if (callback) { callback(result); }
resolve(result); resolve(result);
@ -575,8 +575,8 @@ function baseboard(callback) {
} catch (e) { } catch (e) {
util.noop(); util.noop();
} }
if (result.serial.toLowerCase().indexOf('o.e.m.') !== -1) result.serial = '-'; if (result.serial.toLowerCase().indexOf('o.e.m.') !== -1) { result.serial = '-'; }
if (result.assetTag.toLowerCase().indexOf('o.e.m.') !== -1) result.assetTag = '-'; if (result.assetTag.toLowerCase().indexOf('o.e.m.') !== -1) { result.assetTag = '-'; }
if (callback) { callback(result); } if (callback) { callback(result); }
resolve(result); resolve(result);
@ -699,8 +699,8 @@ function chassis(callback) {
result.version = util.getValue(lines, 'chassis_version'); result.version = util.getValue(lines, 'chassis_version');
result.serial = util.getValue(lines, 'chassis_serial'); result.serial = util.getValue(lines, 'chassis_serial');
result.assetTag = util.getValue(lines, 'chassis_asset_tag'); result.assetTag = util.getValue(lines, 'chassis_asset_tag');
if (result.serial.toLowerCase().indexOf('o.e.m.') !== -1) result.serial = '-'; if (result.serial.toLowerCase().indexOf('o.e.m.') !== -1) { result.serial = '-'; }
if (result.assetTag.toLowerCase().indexOf('o.e.m.') !== -1) result.assetTag = '-'; if (result.assetTag.toLowerCase().indexOf('o.e.m.') !== -1) { result.assetTag = '-'; }
if (callback) { callback(result); } if (callback) { callback(result); }
resolve(result); resolve(result);

View File

@ -80,11 +80,11 @@ function parseLinuxUsb(usb) {
const manufacturer = iManufacturerParts.join(' '); const manufacturer = iManufacturerParts.join(' ');
result.id = (idVendor.startsWith('0x') ? idVendor.split(' ')[0].substr(2, 10) : '') + ':' + (idProduct.startsWith('0x') ? idProduct.split(' ')[0].substr(2, 10) : ''); result.id = (idVendor.startsWith('0x') ? idVendor.split(' ')[0].substr(2, 10) : '') + ':' + (idProduct.startsWith('0x') ? idProduct.split(' ')[0].substr(2, 10) : '');
result.name = product result.name = product;
result.type = getLinuxUsbType(usbType, product); result.type = getLinuxUsbType(usbType, product);
result.removable = null; result.removable = null;
result.vendor = vendor; result.vendor = vendor;
result.manufacturer = manufacturer result.manufacturer = manufacturer;
result.maxPower = util.getValue(lines, 'MaxPower', ' ', true); result.maxPower = util.getValue(lines, 'MaxPower', ' ', true);
result.serialNumber = null; result.serialNumber = null;
@ -102,7 +102,7 @@ function parseLinuxUsb(usb) {
// maxpower(linux) // maxpower(linux)
function getDarwinUsbType(name) { function getDarwinUsbType(name) {
let result = '' let result = '';
if (name.indexOf('camera') >= 0) { result = 'Camera'; } if (name.indexOf('camera') >= 0) { result = 'Camera'; }
else if (name.indexOf('touch bar') >= 0) { result = 'Touch Bar'; } else if (name.indexOf('touch bar') >= 0) { result = 'Touch Bar'; }
else if (name.indexOf('controller') >= 0) { result = 'Controller'; } else if (name.indexOf('controller') >= 0) { result = 'Controller'; }
@ -126,7 +126,7 @@ function parseDarwinUsb(usb, id) {
const result = {}; const result = {};
result.id = id; result.id = id;
usb = usb.replace(/ \|/g, '') usb = usb.replace(/ \|/g, '');
usb = usb.trim(); usb = usb.trim();
let lines = usb.split('\n'); let lines = usb.split('\n');
lines.shift(); lines.shift();
@ -184,7 +184,7 @@ function parseDarwinUsb(usb, id) {
// } // }
function getWindowsUsbTypeCreation(creationclass, name) { function getWindowsUsbTypeCreation(creationclass, name) {
let result = '' let result = '';
if (name.indexOf('storage') >= 0) { result = 'Storage'; } if (name.indexOf('storage') >= 0) { result = 'Storage'; }
else if (name.indexOf('speicher') >= 0) { result = 'Storage'; } else if (name.indexOf('speicher') >= 0) { result = 'Storage'; }
else if (creationclass.indexOf('usbhub') >= 0) { result = 'Hub'; } else if (creationclass.indexOf('usbhub') >= 0) { result = 'Hub'; }
@ -214,7 +214,7 @@ function parseWindowsUsb(lines, id) {
return result; return result;
} else { } else {
return null return null;
} }
} }
@ -241,14 +241,14 @@ function usb(callback) {
}); });
} }
if (_darwin) { if (_darwin) {
let cmd = 'ioreg -p IOUSB -c AppleUSBRootHubDevice -w0 -l' let cmd = 'ioreg -p IOUSB -c AppleUSBRootHubDevice -w0 -l';
exec(cmd, { maxBuffer: 1024 * 1024 * 128 }, function (error, stdout) { exec(cmd, { maxBuffer: 1024 * 1024 * 128 }, function (error, stdout) {
if (!error) { if (!error) {
const parts = (stdout.toString()).split(' +-o '); const parts = (stdout.toString()).split(' +-o ');
for (let i = 1; i < parts.length; i++) { for (let i = 1; i < parts.length; i++) {
const usb = parseDarwinUsb(parts[i]); const usb = parseDarwinUsb(parts[i]);
if (usb) { if (usb) {
result.push(usb) result.push(usb);
} }
} }
if (callback) { if (callback) {
@ -267,9 +267,9 @@ function usb(callback) {
if (!error) { if (!error) {
const parts = stdout.toString().split(/\n\s*\n/); const parts = stdout.toString().split(/\n\s*\n/);
for (let i = 0; i < parts.length; i++) { for (let i = 0; i < parts.length; i++) {
const usb = parseWindowsUsb(parts[i].split('\n'), i) const usb = parseWindowsUsb(parts[i].split('\n'), i);
if (usb) { if (usb) {
result.push(usb) result.push(usb);
} }
} }
} }