fix: clean up stale sorter entries and fix battery reactivity
All checks were successful
Build and Push Docker Image to Gitea / build-and-push (push) Successful in 5m44s

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 <noreply@anthropic.com>
This commit is contained in:
2026-02-07 13:07:13 +01:00
parent 82be8b8859
commit e744d1e40f
2 changed files with 4 additions and 2 deletions

View File

@@ -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) {

View File

@@ -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);
}