mirror of
https://github.com/gesellix/Bose-SoundTouch.git
synced 2026-08-18 08:36:13 +00:00
fix(admin): only auto-discover on load when no devices are known (refs #451)
The admin console ran a full discovery sweep on every page load whenever discovery was enabled (DOMContentLoaded -> triggerDiscovery). With devices already in the datastore, that re-probed every host (including offline ones) on each visit, which felt slow and surprising. Gate the on-load sweep on a cold start only: fetch the cached device list first, and trigger discovery just when it is empty. With devices known, rely on the cached list, the periodic sweep, and the explicit Discover button. fetchDevices now returns the device count for that check. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.8
parent
09113afd87
commit
c97f760153
@@ -588,8 +588,11 @@ async function fetchDevices() {
|
||||
devices.forEach((d) => updateDeviceInfo(d.device_id, d.ip_address));
|
||||
fetchSpotifyStatus();
|
||||
}
|
||||
|
||||
return devices.length;
|
||||
} catch (error) {
|
||||
document.getElementById("device-list").textContent = "Error loading devices: " + error;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1719,11 +1722,15 @@ function formatXML(xml) {
|
||||
|
||||
document.addEventListener("DOMContentLoaded", async () => {
|
||||
const cfg = await fetchSettings();
|
||||
if (cfg?.discovery_enabled !== false) {
|
||||
fetchVersion();
|
||||
const deviceCount = await fetchDevices();
|
||||
// Only sweep automatically on a cold start (no devices known yet). When
|
||||
// devices are already in the store, rely on the cached list plus the
|
||||
// periodic sweep and the explicit Discover button — re-probing offline
|
||||
// speakers on every admin page load was slow and surprising.
|
||||
if (deviceCount === 0 && cfg?.discovery_enabled !== false) {
|
||||
triggerDiscovery();
|
||||
}
|
||||
fetchVersion();
|
||||
await fetchDevices();
|
||||
|
||||
const hash = window.location.hash.slice(1);
|
||||
const [tabId, extra] = hash.split('?');
|
||||
|
||||
Reference in New Issue
Block a user