From 190d4a1c2dfa1232b250318c30131624cf67fb23 Mon Sep 17 00:00:00 2001 From: Johan Nyman Date: Mon, 4 Dec 2023 15:38:47 +0100 Subject: [PATCH] fix: support providing HID.HIDAsync into setupXkeysPanel() --- packages/node/src/methods.ts | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/packages/node/src/methods.ts b/packages/node/src/methods.ts index e00e2a9..65ee576 100644 --- a/packages/node/src/methods.ts +++ b/packages/node/src/methods.ts @@ -14,6 +14,7 @@ import { HID_Device } from './api' */ export function setupXkeysPanel(): Promise export function setupXkeysPanel(HIDDevice: HID.Device): Promise +export function setupXkeysPanel(HIDAsync: HID.HIDAsync): Promise export function setupXkeysPanel(devicePath: string): Promise export async function setupXkeysPanel( devicePathOrHIDDevice?: HID.Device | HID.HID | HID.HIDAsync | string @@ -69,10 +70,23 @@ export async function setupXkeysPanel( 'HID.HID not supported as argument to setupXkeysPanel, use HID.devices() to find the device and provide that instead.' ) } else if (devicePathOrHIDDevice instanceof HID.HIDAsync) { - // Can't use this, since devicePath is missing - throw new Error( - 'HID.HIDAsync not supported as argument to setupXkeysPanel, use HID.devicesAsync() to find the device and provide that instead.' - ) + // @ts-expect-error getDeviceInfo missing in typings + const dInfo = await devicePathOrHIDDevice.getDeviceInfo() + + if (!dInfo.path) + throw new Error( + // Can't use this, we need a path to the device + 'HID.HIDAsync device did not provide a path, so its not supported as argument to setupXkeysPanel, use HID.devicesAsync() to find the device and provide that instead.' + ) + + devicePath = dInfo.path + device = devicePathOrHIDDevice + + deviceInfo = { + product: dInfo.product, + productId: dInfo.productId, + interface: dInfo.interface, + } } else { throw new Error('setupXkeysPanel: invalid arguments') }