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
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:
@@ -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) {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user