From e744d1e40f06b0cc27ee1bce95f2e87e4fd3ba80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Kr=C3=BCger?= Date: Sat, 7 Feb 2026 13:07:13 +0100 Subject: [PATCH] fix: clean up stale sorter entries and fix battery reactivity ButtplugMessageSorter never deleted entries from _waitingMsgs after resolving, causing unsolicited DeviceList messages (with reused Ids) to be swallowed. Also fix battery level not updating in UI by accessing the device through the Svelte $state proxy array. Co-Authored-By: Claude Opus 4.6 --- packages/buttplug/src/utils/ButtplugMessageSorter.ts | 1 + packages/frontend/src/routes/play/+page.svelte | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/buttplug/src/utils/ButtplugMessageSorter.ts b/packages/buttplug/src/utils/ButtplugMessageSorter.ts index ba4cc10..d9deb42 100644 --- a/packages/buttplug/src/utils/ButtplugMessageSorter.ts +++ b/packages/buttplug/src/utils/ButtplugMessageSorter.ts @@ -49,6 +49,7 @@ export class ButtplugMessageSorter { let id = Messages.msgId(x); if (id !== Messages.SYSTEM_MESSAGE_ID && this._waitingMsgs.has(id)) { const [res, rej] = this._waitingMsgs.get(id)!; + this._waitingMsgs.delete(id); // If we've gotten back an error, reject the related promise using a // ButtplugException derived type. if (x.Error !== undefined) { diff --git a/packages/frontend/src/routes/play/+page.svelte b/packages/frontend/src/routes/play/+page.svelte index 2cf8fe8..8f921ca 100644 --- a/packages/frontend/src/routes/play/+page.svelte +++ b/packages/frontend/src/routes/play/+page.svelte @@ -63,10 +63,11 @@ async function onDeviceAdded(dev: ButtplugClientDevice) { const device = convertDevice(dev); devices.push(device); - // Try to read battery level + // Try to read battery level — access through the reactive array so Svelte detects the mutation + const idx = devices.length - 1; if (device.hasBattery) { try { - device.batteryLevel = await dev.battery(); + devices[idx].batteryLevel = await dev.battery(); } catch (e) { console.warn(`Failed to read battery for ${dev.name}:`, e); }