Skip to content

Commit 37f4c11

Browse files
afaragodlech
authored andcommitted
usb/sagas: always set configuration
On some OSes, like macOS, the configuration may not be selected, so we need to make sure it is always set.
1 parent 75dc627 commit 37f4c11

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

src/usb/sagas.ts

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -161,17 +161,16 @@ function* handleUsbConnectPybricks(hotPlugDevice?: USBDevice): Generator {
161161
return;
162162
}
163163

164-
// REVISIT: For now, we are making the assumption that there is only one
165-
// configuration and it is already selected and that it contains a Pybricks
166-
// interface.
167-
assert(
168-
usbDevice.configuration !== undefined,
169-
'USB device configuration is undefined',
170-
);
171-
assert(
172-
usbDevice.configuration.interfaces.length > 0,
173-
'USB device has no interfaces',
174-
);
164+
const [, selectErr] = yield* call(() => maybe(usbDevice.selectConfiguration(1)));
165+
if (selectErr) {
166+
// TODO: show error message to user here
167+
console.error('Failed to select USB device configuration:', selectErr);
168+
yield* put(usbDidFailToConnectPybricks());
169+
yield* cleanup();
170+
return;
171+
}
172+
173+
assert(usbDevice.configuration !== null, 'USB device configuration is null');
175174

176175
const iface = usbDevice.configuration.interfaces.find(
177176
(iface) =>

0 commit comments

Comments
 (0)