Skip to content
This repository was archived by the owner on Jan 8, 2026. It is now read-only.

Commit 2b64657

Browse files
committed
Simplify the navigator.usb.requestDevice shim.
1 parent c5b5c77 commit 2b64657

1 file changed

Lines changed: 4 additions & 7 deletions

File tree

src/worker.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -133,13 +133,10 @@ const boot = async (initialState: InitialState) => {
133133
if (options?.filters?.length) {
134134
const { filters } = options;
135135
devices = devices.filter((device) => filters.some((filter) => {
136-
if (filter.vendorId !== undefined && device.vendorId !== filter.vendorId) return false;
137-
if (filter.productId !== undefined && device.productId !== filter.productId) return false;
138-
if (filter.classCode !== undefined && device.deviceClass !== filter.classCode) return false;
139-
if (filter.subclassCode !== undefined && device.deviceSubclass !== filter.subclassCode) return false;
140-
if (filter.protocolCode !== undefined && device.deviceProtocol !== filter.protocolCode) return false;
141-
if (filter.serialNumber !== undefined && device.serialNumber !== filter.serialNumber) return false;
142-
return true;
136+
return Object.keys(filter).every((_key) => {
137+
let key = _key as (keyof USBDeviceFilter & keyof USBDevice);
138+
return filter[key] === undefined || device[key] === filter[key];
139+
});
143140
}));
144141
}
145142
if (!devices[0]) {

0 commit comments

Comments
 (0)