bluetooth windows, fixes, improvements

This commit is contained in:
Sebastian Hildebrandt
2021-01-18 19:38:20 +01:00
parent 143b1abe86
commit 6fdf5ea2ac
9 changed files with 101 additions and 67 deletions
+3 -1
View File
@@ -172,7 +172,9 @@ function audio(callback) {
if (!error) {
const parts = stdout.toString().split(/\n\s*\n/);
for (let i = 0; i < parts.length; i++) {
result.push(parseWindowsAudio(parts[i].split('\n'), i))
if (util.getValue(parts[i].split('\n'), 'name', '=')) {
result.push(parseWindowsAudio(parts[i].split('\n'), i))
}
}
}
if (callback) {
+9 -7
View File
@@ -101,21 +101,21 @@ function parseDarwinBluetoothDevices(bluetoothObject) {
result.address = bluetoothObject.device_addr || '';
result.batteryPercent = bluetoothObject.device_batteryPercent || null;
result.tyoe = parseDarwinBluetoothTyoe(typeStr);
result.connected = bluetoothObject.device_isconnected === 'attrib_Yes'|| false;
result.connected = bluetoothObject.device_isconnected === 'attrib_Yes' || false;
return result;
}
function parseWindowsAudio(lines) {
function parseWindowsBluetooth(lines) {
const result = {};
const status = util.getValue(lines, 'StatusInfo', '=');
// const description = util.getValue(lines, 'Description', '=');
result.id = util.getValue(lines, 'DeviceID', '='); // PNPDeviceID??
result.device = null;
result.name = util.getValue(lines, 'name', '=');
result.manufacturer = util.getValue(lines, 'manufacturer', '=');
result.revision = null;
result.driver = null
result.address = null;
result.batteryPercent = null
result.default = null
result.in = null
result.out = null
@@ -182,11 +182,13 @@ function bluetoothDevices(callback) {
});
}
if (_windows) {
util.wmic('path Win32_SoundDevice get /value', function (error, stdout) {
util.wmic('path Win32_PNPEntity get /value', function (error, stdout) {
if (!error) {
const parts = stdout.toString().split(/\n\s*\n/);
for (let i = 0; i < parts.length; i++) {
result.push(parseWindowsAudio(parts[i].split('\n'), i))
if (util.getValue(parts[i].split('\n'), 'PNPClass', '=') === 'Bluetooth') {
result.push(parseWindowsBluetooth(parts[i].split('\n'), i))
}
}
}
if (callback) {
+4 -4
View File
@@ -199,12 +199,12 @@ function fsOpenFiles(callback) {
});
}
if (_sunos) {
if (callback) { callback(result); }
resolve(result);
if (callback) { callback(null); }
resolve(null);
}
if (_windows) {
if (callback) { callback(result); }
resolve(result);
if (callback) { callback(null); }
resolve(null);
}
});
});
+1 -1
View File
@@ -178,7 +178,7 @@ function getFQDN() {
if (_windows) {
try {
const stdout = execSync('echo %COMPUTERNAME%.%USERDNSDOMAIN%');
fqdn = stdout.toString().split(os.EOL)[0];
fqdn = stdout.toString().replace('.%USERDNSDOMAIN%', '').split(os.EOL)[0];
} catch (e) {
util.noop();
}
+5 -3
View File
@@ -127,9 +127,11 @@ function printer(callback) {
const printerHeader = parseLinuxCupsHeader(parts[0]);
for (let i = 1; i < parts.length; i++) {
const printers = parseLinuxCupsPrinter(parts[i].split('\n'));
printers.engine = 'CUPS';
printers.engineVersion = printerHeader.cupsVersion;
result.push(printers);
if (printers.name) {
printers.engine = 'CUPS';
printers.engineVersion = printerHeader.cupsVersion;
result.push(printers);
}
}
}
if (result.length === 0) {
+48 -17
View File
@@ -34,7 +34,7 @@ function getLinuxUsbType(type, name) {
if (str.indexOf('camera') >= 0) { result = 'Camera'; }
else if (str.indexOf('hub') >= 0) { result = 'Hub'; }
else if (str.indexOf('keybrd') >= 0) { result = 'Keyboard'; }
else if (str.indexOf('keybroard') >= 0) { result = 'Keyboard'; }
else if (str.indexOf('keyboard') >= 0) { result = 'Keyboard'; }
else if (str.indexOf('mouse') >= 0) { result = 'Mouse'; }
else if (str.indexOf('stora') >= 0) { result = 'Storage'; }
else if (str.indexOf('mic') >= 0) { result = 'Microphone'; }
@@ -164,29 +164,45 @@ function parseDarwinUsb(usb, id) {
}
}
function getWindowsUsbType(service) {
// function getWindowsUsbType(service) {
// let result = ''
// if (service.indexOf('usbhub3') >= 0) { result = 'Hub'; }
// else if (service.indexOf('usbstor') >= 0) { result = 'Storage'; }
// else if (service.indexOf('hidusb') >= 0) { result = 'Input'; }
// else if (service.indexOf('usbccgp') >= 0) { result = 'Controller'; }
// else if (service.indexOf('usbxhci') >= 0) { result = 'Controller'; }
// else if (service.indexOf('usbehci') >= 0) { result = 'Controller'; }
// else if (service.indexOf('kbdhid') >= 0) { result = 'Keyboard'; }
// else if (service.indexOf('keyboard') >= 0) { result = 'Keyboard'; }
// else if (service.indexOf('pointing') >= 0) { result = 'Mouse'; }
// else if (service.indexOf('disk') >= 0) { result = 'Storage'; }
// else if (service.indexOf('usbhub') >= 0) { result = 'Hub'; }
// else if (service.indexOf('bthusb') >= 0) { result = ''; }
// else if (service.indexOf('bth') >= 0) { result = ''; }
// else if (service.indexOf('rfcomm') >= 0) { result = ''; }
// return result;
// }
function getWindowsUsbTypeCreation(creationclass, name) {
let result = ''
if (service.indexOf('usbhub3') >= 0) { result = 'Hub'; }
else if (service.indexOf('usbstor') >= 0) { result = 'Storage'; }
else if (service.indexOf('hidUsb') >= 0) { result = 'Input'; }
else if (service.indexOf('mouhid') >= 0) { result = 'Mouse'; }
else if (service.indexOf('usbccgp') >= 0) { result = 'Controller'; }
else if (service.indexOf('kbdhid') >= 0) { result = 'Keyboard'; }
else if (service.indexOf('disk') >= 0) { result = 'Storage'; }
else if (service.indexOf('bthusb') >= 0) { result = 'Bluetooth'; }
else if (service.indexOf('bth') >= 0) { result = 'Bluetooth'; }
else if (service.indexOf('rfcomm') >= 0) { result = 'Bluetooth'; }
else if (service.indexOf('usbhub') >= 0) { result = 'Hub'; }
if (name.indexOf('storage') >= 0) { result = 'Storage'; }
else if (name.indexOf('speicher') >= 0) { result = 'Storage'; }
else if (creationclass.indexOf('usbhub') >= 0) { result = 'Hub'; }
else if (creationclass.indexOf('storage') >= 0) { result = 'Storage'; }
else if (creationclass.indexOf('usbcontroller') >= 0) { result = 'Controller'; }
else if (creationclass.indexOf('keyboard') >= 0) { result = 'Keyboard'; }
else if (creationclass.indexOf('pointing') >= 0) { result = 'Mouse'; }
else if (creationclass.indexOf('disk') >= 0) { result = 'Storage'; }
return result;
}
function parseWindowsUsb(lines, id) {
const usbType = getWindowsUsbType(util.getValue(lines, 'Service', '=').toLowerCase());
const usbType = getWindowsUsbTypeCreation(util.getValue(lines, 'CreationClassName', '=').toLowerCase(), util.getValue(lines, 'name', '=').toLowerCase());
if (usbType) {
const result = {};
result.bus = null;
result.deviceId = null;
result.deviceId = util.getValue(lines, 'deviceid', '=');
result.id = id;
result.name = util.getValue(lines, 'name', '=');
result.type = usbType;
@@ -226,7 +242,7 @@ function usb(callback) {
}
if (_darwin) {
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) {
const parts = (stdout.toString()).split(' +-o ');
for (let i = 1; i < parts.length; i++) {
@@ -247,7 +263,7 @@ function usb(callback) {
});
}
if (_windows) {
util.powerShell('gwmi Win32_USBControllerDevice |%{[wmi]($_.Dependent)}', function (error, stdout) {
util.wmic('Path CIM_LogicalDevice where "Description like \'USB%\'" get /value', function (error, stdout) {
if (!error) {
const parts = stdout.toString().split(/\n\s*\n/);
for (let i = 0; i < parts.length; i++) {
@@ -262,6 +278,21 @@ function usb(callback) {
}
resolve(result);
});
// util.powerShell("gwmi Win32_USBControllerDevice |\%{[wmi]($_.Dependent)}").then(data => {
// const parts = data.toString().split(/\n\s*\n/);
// for (let i = 0; i < parts.length; i++) {
// const usb = parseWindowsUsb(parts[i].split('\n'), i)
// if (usb) {
// result.push(usb)
// }
// }
// if (callback) {
// callback(result);
// }
// resolve(result);
// });
}
if (_sunos || _freebsd || _openbsd || _netbsd) {
resolve(null);