fix: trigger discovery when all registered devices are offline

This commit is contained in:
tian 2026-05-06 15:13:50 +08:00
parent 853b5612d7
commit 8f1d6cfbe7
2 changed files with 25 additions and 5 deletions

View File

@ -128,8 +128,18 @@ func (h *Handler) ensureDevicesLoaded() {
if h.registry == nil || h.discovery == nil {
return
}
if len(h.registry.GetDevices()) > 0 {
return
devices := h.registry.GetDevices()
if len(devices) > 0 {
hasOnline := false
for _, d := range devices {
if d.Online {
hasOnline = true
break
}
}
if hasOnline {
return
}
}
_, _ = h.discovery.SearchDefault()
if len(h.registry.GetDevices()) == 0 {

View File

@ -700,11 +700,21 @@ func (u *UI) ensureDevicesLoaded() {
if u.registry == nil || u.discovery == nil {
return
}
if len(u.registry.GetDevices()) > 0 {
return
devices := u.registry.GetDevices()
if len(devices) > 0 {
// Check if any device is online; if not, try discovery to refresh
hasOnline := false
for _, d := range devices {
if d.Online {
hasOnline = true
break
}
}
if hasOnline {
return
}
}
_, _ = u.discovery.SearchDefault()
// Retry once if discovery returned nothing (UDP broadcast can be lossy on some networks)
if len(u.registry.GetDevices()) == 0 {
_, _ = u.discovery.SearchDefault()
}