perf(efficiency): 接入真实CPU能量并隔离展示与采样需求
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user