From 509c635a07d1267d9417601f3929c5675befe080 Mon Sep 17 00:00:00 2001 From: David Lechner Date: Wed, 26 Oct 2022 16:09:57 -0500 Subject: [PATCH] ble/sagas: add workaround for BlueZ quirk The 'gattserverdisconnected' event is called before the device is actually disconnected, so if the user tries to connect again immediately, the web browser will show a still "paired" device, but selecting this devices results in an infinite wait. This is a bug in Chromium, but we can work around it by adding a delay to give BlueZ time to actually disconnect the device. Closes: https://github.com/pybricks/support/issues/600 --- src/ble/sagas.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/ble/sagas.ts b/src/ble/sagas.ts index e0746877..b22c3363 100644 --- a/src/ble/sagas.ts +++ b/src/ble/sagas.ts @@ -60,6 +60,7 @@ import { import { firmwareInstallPybricks } from '../firmware/actions'; import { RootState } from '../reducers'; import { ensureError } from '../utils'; +import { isLinux } from '../utils/os'; import { pythonVersionToSemver } from '../utils/version'; import { bleConnectPybricks as bleConnectPybricks, @@ -433,6 +434,16 @@ function* handleBleConnectPybricks(): Generator { // wait for disconnection yield* take(disconnectChannel); + // HACK: Disconnection event comes early on Linux, so scanning again + // can show that the previous connection is still "paired" and trying + // to select it results in infinite wait. To work around this, we need + // to wait long enough for BlueZ to actually disconnect the device. + // https://github.com/pybricks/support/issues/600#issuecomment-1286606624 + // istanbul ignore if + if (process.env.NODE_ENV !== 'test' && isLinux()) { + yield* delay(5000); + } + yield* put(bleDidDisconnectPybricks()); } catch (err) { // istanbul ignore if