diff --git a/network.go b/network.go index 42fc6d87..3a2b24f9 100644 --- a/network.go +++ b/network.go @@ -110,6 +110,13 @@ func triggerTimeSyncOnNetworkStateChange() { }() } +func setPublicIPReadyState(ipv4Ready, ipv6Ready bool) { + if publicIPState == nil { + return + } + publicIPState.SetIPv4AndIPv6(ipv4Ready, ipv6Ready) +} + func networkStateChanged(_ string, state types.InterfaceState) { // do not block the main thread go waitCtrlAndRequestDisplayUpdate(true, "network_state_changed") @@ -121,16 +128,10 @@ func networkStateChanged(_ string, state types.InterfaceState) { if state.Online { networkLogger.Info().Msg("network state changed to online, triggering time sync") triggerTimeSyncOnNetworkStateChange() - - if publicIPState != nil { - publicIPState.SetIPv4AndIPv6(state.IPv4Ready, state.IPv6Ready) - } - } else { - if publicIPState != nil { - publicIPState.SetIPv4AndIPv6(false, false) - } } + setPublicIPReadyState(state.IPv4Ready, state.IPv6Ready) + // always restart mDNS when the network state changes if mDNS != nil { restartMdns() diff --git a/pkg/myip/ip.go b/pkg/myip/ip.go index f414eace..15afc24e 100644 --- a/pkg/myip/ip.go +++ b/pkg/myip/ip.go @@ -92,22 +92,6 @@ func (ps *PublicIPState) SetIPv4AndIPv6(ipv4, ipv6 bool) { ps.ipv6 = ipv6 } -// SetIPv4 sets if we need to track IPv4 public IP addresses -func (ps *PublicIPState) SetIPv4(ipv4 bool) { - ps.mu.Lock() - defer ps.mu.Unlock() - - ps.ipv4 = ipv4 -} - -// SetIPv6 sets if we need to track IPv6 public IP addresses -func (ps *PublicIPState) SetIPv6(ipv6 bool) { - ps.mu.Lock() - defer ps.mu.Unlock() - - ps.ipv6 = ipv6 -} - // SetCloudflareEndpoint sets the Cloudflare endpoint func (ps *PublicIPState) SetCloudflareEndpoint(endpoint string) { ps.mu.Lock() diff --git a/ui/src/components/PublicIPCard.tsx b/ui/src/components/PublicIPCard.tsx index a2671753..041412e5 100644 --- a/ui/src/components/PublicIPCard.tsx +++ b/ui/src/components/PublicIPCard.tsx @@ -21,6 +21,8 @@ export default function PublicIPCard() { return; } const publicIPs = resp.result as PublicIP[]; + // sort the public IPs by IP address + // IPv6 addresses are sorted after IPv4 addresses setPublicIPs(publicIPs.sort(({ ip: aIp }, { ip: bIp }) => { const aIsIPv6 = aIp.includes(":"); const bIsIPv6 = bIp.includes(":");