From 9be8d41c94abfbdd1e32e15a193903a73db243e2 Mon Sep 17 00:00:00 2001 From: tracer Date: Sun, 19 Apr 2026 23:02:51 +0200 Subject: [PATCH] fix: reduce idle interval indicator work --- CHANGELOG.md | 4 ++++ Sources/Views/ServerDetailView.swift | 16 ++++++++++++---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c712aff..6eea958 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## 26.1.9 +- Reduced idle CPU usage and energy impact by changing the interval indicator from a permanent 60 FPS timer to a 1-second update cadence. +- Reset the interval indicator cleanly when the refresh interval changes or when the indicator is hidden. + ## 26.1.8 - Fixed a crash in `PingService` caused by concurrent mutation of shared ping state from multiple async ping tasks. - Moved ping state tracking and reboot suppression windows into an actor so ping success/failure handling is serialized safely. diff --git a/Sources/Views/ServerDetailView.swift b/Sources/Views/ServerDetailView.swift index ba28cf0..9726173 100644 --- a/Sources/Views/ServerDetailView.swift +++ b/Sources/Views/ServerDetailView.swift @@ -29,7 +29,7 @@ struct ServerDetailView: View { @State private var progress: Double = 0 @State private var showRestartSheet = false @State private var restartFeedback: ServerActionFeedback? - let timer = Timer.publish(every: 1.0 / 60.0, on: .main, in: .common).autoconnect() + private let indicatorTimer = Timer.publish(every: 1, on: .main, in: .common).autoconnect() var body: some View { VStack(spacing: 0) { @@ -85,13 +85,21 @@ struct ServerDetailView: View { .padding() } } - .onReceive(timer) { _ in + .onReceive(indicatorTimer) { _ in guard showIntervalIndicator else { return } - withAnimation(.linear(duration: 1.0 / 60.0)) { - progress += 1.0 / (Double(refreshInterval) * 60.0) + withAnimation(.linear(duration: 1)) { + progress += 1.0 / Double(refreshInterval) if progress >= 1 { progress = 0 } } } + .onChange(of: refreshInterval) { _, _ in + progress = 0 + } + .onChange(of: showIntervalIndicator) { _, isVisible in + if !isVisible { + progress = 0 + } + } .sheet(isPresented: $showRestartSheet) { RestartConfirmationSheet( hostname: server.hostname,