fix: reduce idle interval indicator work

This commit is contained in:
2026-04-19 23:02:51 +02:00
parent d978c51fbd
commit 9be8d41c94
2 changed files with 16 additions and 4 deletions

View File

@@ -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,