25 lines
1.2 KiB
Swift
25 lines
1.2 KiB
Swift
import SwiftUI
|
|
|
|
/// Shared by the dashboard and the text-only audit so network work is comparable.
|
|
struct PanelPublicIPRefresh: ViewModifier {
|
|
let metrics: MetricsStore
|
|
@Binding var address: String?
|
|
private var route: String {
|
|
let snapshot = metrics.snapshot
|
|
return "\(snapshot.defaultNetworkInterface ?? ""):\(String(describing: snapshot.networkPath)):\(snapshot.network?.filter { $0.active }.map { $0.addresses.joined(separator: ",") }.joined(separator: ";") ?? "")"
|
|
}
|
|
func body(content: Content) -> some View {
|
|
content.task(id: "\(route):\(metrics.isPaused):\(metrics.isSystemSleeping):\(metrics.isDisplaySleeping):\(metrics.isPanelVisible)") {
|
|
guard !metrics.isPaused, !metrics.isSystemSleeping, !metrics.isDisplaySleeping, metrics.isPanelVisible else { return }
|
|
address = nil
|
|
guard metrics.snapshot.networkPath == .available else { return }
|
|
await PublicIPAddressService.shared.refreshContinuously(route: route) { value in
|
|
await MainActor.run {
|
|
guard !Task.isCancelled else { return }
|
|
address = value
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|