修复局域网连接问题

This commit is contained in:
2026-03-28 19:44:00 +08:00
parent 824e1f779c
commit 4be3087de9
2 changed files with 65 additions and 5 deletions

View File

@@ -109,6 +109,11 @@ func (s *DeviceService) SetOnline(deviceID string, online bool) (model.Device, b
func (s *DeviceService) ListCandidates(currentDeviceID string) []model.Device {
current, _ := s.store.GetDevice(currentDeviceID)
currentNetworkGroupKey := strings.TrimSpace(current.NetworkGroupKey)
if currentNetworkGroupKey == "" {
return nil
}
devices := s.store.ListDevices()
s.applyPresence(devices)
candidates := make([]model.Device, 0, len(devices))
@@ -117,15 +122,13 @@ func (s *DeviceService) ListCandidates(currentDeviceID string) []model.Device {
if device.ID == currentDeviceID || !device.IsOnline {
continue
}
if strings.TrimSpace(device.NetworkGroupKey) != currentNetworkGroupKey {
continue
}
candidates = append(candidates, device)
}
sort.SliceStable(candidates, func(i, j int) bool {
leftSameNetwork := current.NetworkGroupKey != "" && candidates[i].NetworkGroupKey == current.NetworkGroupKey
rightSameNetwork := current.NetworkGroupKey != "" && candidates[j].NetworkGroupKey == current.NetworkGroupKey
if leftSameNetwork != rightSameNetwork {
return leftSameNetwork
}
return candidates[i].LastSeenAt.After(candidates[j].LastSeenAt)
})