mirror of
https://github.com/pybricks/pybricks-code.git
synced 2026-09-12 01:23:52 +00:00
fix bluetooth stuck in connecting state after cancel
This commit is contained in:
+12
-4
@@ -80,12 +80,20 @@ export function connect(): BLEThunkAction {
|
||||
return;
|
||||
}
|
||||
dispatch(beginConnect());
|
||||
device = await navigator.bluetooth.requestDevice({
|
||||
filters: [{ services: [pybricksServiceUUID] }],
|
||||
optionalServices: [bleNusServiceUUID],
|
||||
});
|
||||
try {
|
||||
device = await navigator.bluetooth.requestDevice({
|
||||
filters: [{ services: [pybricksServiceUUID] }],
|
||||
optionalServices: [bleNusServiceUUID],
|
||||
});
|
||||
} catch (err) {
|
||||
// this can happen if the use cancels the dialog
|
||||
console.log(err);
|
||||
dispatch(endDisconnect());
|
||||
return;
|
||||
}
|
||||
if (device.gatt === undefined) {
|
||||
console.error('Device does not support GATT');
|
||||
dispatch(endDisconnect());
|
||||
return;
|
||||
}
|
||||
device.addEventListener('gattserverdisconnected', () => {
|
||||
|
||||
Reference in New Issue
Block a user