fix: trigger discovery when all registered devices are offline
This commit is contained in:
parent
853b5612d7
commit
8f1d6cfbe7
@ -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 {
|
||||
|
||||
@ -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()
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user