fix: permission detection on linux (#651)

This commit is contained in:
Róbert Kiss
2018-05-21 11:46:19 +02:00
committed by László Monda
parent daa0e723b1
commit ab8ae31324
2 changed files with 20 additions and 18 deletions

View File

@@ -1,6 +1,8 @@
import { Constants, UsbCommand } from './constants';
import { Device } from 'node-hid';
import { DeviceConnectionState, LogService } from 'uhk-common';
import { Constants, UsbCommand } from './constants';
export const snooze = ms => new Promise(resolve => setTimeout(resolve, ms));
/**
@@ -101,3 +103,12 @@ export const deviceConnectionStateComparer = (a: DeviceConnectionState, b: Devic
&& a.connected === b.connected
&& a.bootloaderActive === b.bootloaderActive;
};
export const isUhkDevice = (dev: Device): boolean => {
return dev.vendorId === Constants.VENDOR_ID &&
dev.productId === Constants.PRODUCT_ID &&
// hidapi can not read the interface number on Mac, so check the usage page and usage
((dev.usagePage === 128 && dev.usage === 129) || // Old firmware
(dev.usagePage === (0xFF00 | 0x00) && dev.usage === 0x01) || // New firmware
dev.interface === 0);
};