chore(public-ip): use interface state to set public IP ready state

This commit is contained in:
Siyuan 2025-11-10 17:13:27 +00:00
parent 1097deeaf8
commit e9df46baec
3 changed files with 11 additions and 24 deletions

View File

@ -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) { func networkStateChanged(_ string, state types.InterfaceState) {
// do not block the main thread // do not block the main thread
go waitCtrlAndRequestDisplayUpdate(true, "network_state_changed") go waitCtrlAndRequestDisplayUpdate(true, "network_state_changed")
@ -121,15 +128,9 @@ func networkStateChanged(_ string, state types.InterfaceState) {
if state.Online { if state.Online {
networkLogger.Info().Msg("network state changed to online, triggering time sync") networkLogger.Info().Msg("network state changed to online, triggering time sync")
triggerTimeSyncOnNetworkStateChange() triggerTimeSyncOnNetworkStateChange()
}
if publicIPState != nil { setPublicIPReadyState(state.IPv4Ready, state.IPv6Ready)
publicIPState.SetIPv4AndIPv6(state.IPv4Ready, state.IPv6Ready)
}
} else {
if publicIPState != nil {
publicIPState.SetIPv4AndIPv6(false, false)
}
}
// always restart mDNS when the network state changes // always restart mDNS when the network state changes
if mDNS != nil { if mDNS != nil {

View File

@ -92,22 +92,6 @@ func (ps *PublicIPState) SetIPv4AndIPv6(ipv4, ipv6 bool) {
ps.ipv6 = ipv6 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 // SetCloudflareEndpoint sets the Cloudflare endpoint
func (ps *PublicIPState) SetCloudflareEndpoint(endpoint string) { func (ps *PublicIPState) SetCloudflareEndpoint(endpoint string) {
ps.mu.Lock() ps.mu.Lock()

View File

@ -21,6 +21,8 @@ export default function PublicIPCard() {
return; return;
} }
const publicIPs = resp.result as PublicIP[]; 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 }) => { setPublicIPs(publicIPs.sort(({ ip: aIp }, { ip: bIp }) => {
const aIsIPv6 = aIp.includes(":"); const aIsIPv6 = aIp.includes(":");
const bIsIPv6 = bIp.includes(":"); const bIsIPv6 = bIp.includes(":");