From 6778c73046daef564c70b41638722b033dee2847 Mon Sep 17 00:00:00 2001 From: ydw1904 Date: Tue, 29 Sep 2026 23:31:13 +0800 Subject: [PATCH] fix(device): toast when opening a device fails to list devices Clicking a Home device card runs `void control.openDeviceOverview()`, which calls navigator.hid.getDevices() first. When OpenMouse Bridge is wedged that call rejects with "OpenMouse Bridge did not answer list in time.", the rejection is dropped by `void`, and nothing happens on screen. openDeviceOverview and selectAuthorizedDevice now read the device groups through one helper that catches the rejection and shows the same "Connection failed" toast the Hardware Test connect button already shows. Co-Authored-By: Claude Opus 5.5 --- src/device/controller.ts | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) 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();