mirror of
https://github.com/microsoft/vscode.git
synced 2026-05-08 17:19:48 +01:00
360c9fd134
For #269213 This adds a new eslint rule for `as any` and `<any>({... })`. We'd like to remove almost all of these, however right now the first goal is to prevent them in new code. That's why with this first PR I simply add `eslint-disable` comments for all breaks Trying to get this change in soon after branching off for release to hopefully minimize disruption during debt week work
112 lines
3.2 KiB
TypeScript
112 lines
3.2 KiB
TypeScript
/*---------------------------------------------------------------------------------------------
|
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
*--------------------------------------------------------------------------------------------*/
|
|
|
|
// https://wicg.github.io/webusb/
|
|
|
|
export interface UsbDeviceData {
|
|
readonly deviceClass: number;
|
|
readonly deviceProtocol: number;
|
|
readonly deviceSubclass: number;
|
|
readonly deviceVersionMajor: number;
|
|
readonly deviceVersionMinor: number;
|
|
readonly deviceVersionSubminor: number;
|
|
readonly manufacturerName?: string;
|
|
readonly productId: number;
|
|
readonly productName?: string;
|
|
readonly serialNumber?: string;
|
|
readonly usbVersionMajor: number;
|
|
readonly usbVersionMinor: number;
|
|
readonly usbVersionSubminor: number;
|
|
readonly vendorId: number;
|
|
}
|
|
|
|
export async function requestUsbDevice(options?: { filters?: unknown[] }): Promise<UsbDeviceData | undefined> {
|
|
// eslint-disable-next-line local/code-no-any-casts
|
|
const usb = (navigator as any).usb;
|
|
if (!usb) {
|
|
return undefined;
|
|
}
|
|
|
|
const device = await usb.requestDevice({ filters: options?.filters ?? [] });
|
|
if (!device) {
|
|
return undefined;
|
|
}
|
|
|
|
return {
|
|
deviceClass: device.deviceClass,
|
|
deviceProtocol: device.deviceProtocol,
|
|
deviceSubclass: device.deviceSubclass,
|
|
deviceVersionMajor: device.deviceVersionMajor,
|
|
deviceVersionMinor: device.deviceVersionMinor,
|
|
deviceVersionSubminor: device.deviceVersionSubminor,
|
|
manufacturerName: device.manufacturerName,
|
|
productId: device.productId,
|
|
productName: device.productName,
|
|
serialNumber: device.serialNumber,
|
|
usbVersionMajor: device.usbVersionMajor,
|
|
usbVersionMinor: device.usbVersionMinor,
|
|
usbVersionSubminor: device.usbVersionSubminor,
|
|
vendorId: device.vendorId,
|
|
};
|
|
}
|
|
|
|
// https://wicg.github.io/serial/
|
|
|
|
export interface SerialPortData {
|
|
readonly usbVendorId?: number | undefined;
|
|
readonly usbProductId?: number | undefined;
|
|
}
|
|
|
|
export async function requestSerialPort(options?: { filters?: unknown[] }): Promise<SerialPortData | undefined> {
|
|
// eslint-disable-next-line local/code-no-any-casts
|
|
const serial = (navigator as any).serial;
|
|
if (!serial) {
|
|
return undefined;
|
|
}
|
|
|
|
const port = await serial.requestPort({ filters: options?.filters ?? [] });
|
|
if (!port) {
|
|
return undefined;
|
|
}
|
|
|
|
const info = port.getInfo();
|
|
return {
|
|
usbVendorId: info.usbVendorId,
|
|
usbProductId: info.usbProductId
|
|
};
|
|
}
|
|
|
|
// https://wicg.github.io/webhid/
|
|
|
|
export interface HidDeviceData {
|
|
readonly opened: boolean;
|
|
readonly vendorId: number;
|
|
readonly productId: number;
|
|
readonly productName: string;
|
|
readonly collections: [];
|
|
}
|
|
|
|
export async function requestHidDevice(options?: { filters?: unknown[] }): Promise<HidDeviceData | undefined> {
|
|
// eslint-disable-next-line local/code-no-any-casts
|
|
const hid = (navigator as any).hid;
|
|
if (!hid) {
|
|
return undefined;
|
|
}
|
|
|
|
const devices = await hid.requestDevice({ filters: options?.filters ?? [] });
|
|
if (!devices.length) {
|
|
return undefined;
|
|
}
|
|
|
|
const device = devices[0];
|
|
return {
|
|
opened: device.opened,
|
|
vendorId: device.vendorId,
|
|
productId: device.productId,
|
|
productName: device.productName,
|
|
collections: device.collections
|
|
};
|
|
}
|