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
This commit is contained in:
David Lechner
2022-10-26 16:20:08 -05:00
committed by David Lechner
parent 57c87da464
commit 509c635a07
+11
View File
@@ -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