diff --git a/src/device/controller.ts b/src/device/controller.ts index 3c5ec76..2b30459 100644 --- a/src/device/controller.ts +++ b/src/device/controller.ts @@ -2021,9 +2021,20 @@ async function waitForControllerIdle(): Promise { } } +/** A wedged OpenMouse Bridge rejects getDevices(); toast it instead of failing silently. */ +async function authorizedDeviceGroups(): Promise { + try { + return logicalDeviceGroups(await navigator.hid?.getDevices() ?? []); + } catch (error) { + toastForError("Connection failed", error); + return null; + } +} + export async function selectAuthorizedDevice(index: number): Promise { await waitForControllerIdle(); - const groups = logicalDeviceGroups(await navigator.hid?.getDevices() ?? []); + const groups = await authorizedDeviceGroups(); + if (!groups) return; const group = groups[index]; if (!group) return; if (group.some((device) => device === activeDevice) && latestDeviceStatus !== null) return; @@ -2057,7 +2068,8 @@ export async function selectAuthorizedDevice(index: number): Promise { /** Open the given device's dashboard from the picker, connecting it first when needed. */ export async function openDeviceOverview(index: number): Promise { await waitForControllerIdle(); - const groups = logicalDeviceGroups(await navigator.hid?.getDevices() ?? []); + const groups = await authorizedDeviceGroups(); + if (!groups) return; const group = groups[index]; if (!group) { await connect();