perf(efficiency): 接入真实CPU能量并隔离展示与采样需求

This commit is contained in:
2026-11-04 01:11:24 +08:00
parent a96d188abe
commit 1c26fc18f3
37 changed files with 1249 additions and 179 deletions
@@ -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
}
}
}
}
}