diff --git a/phpmon/Modules/Command History/UI/CommandHistoryRow.swift b/phpmon/Modules/Command History/UI/CommandHistoryRow.swift index 2aeb7dd6..d0bbfb6c 100644 --- a/phpmon/Modules/Command History/UI/CommandHistoryRow.swift +++ b/phpmon/Modules/Command History/UI/CommandHistoryRow.swift @@ -11,7 +11,6 @@ import SwiftUI struct CommandHistoryRow: View { let command: LoggedCommand - let now: Date let isEvenRow: Bool @Binding var visibleCommandIds: Set @@ -33,9 +32,17 @@ struct CommandHistoryRow: View { .lineLimit(2) } - Text(command.durationText(at: now)) - .font(.system(size: 11)) - .foregroundColor(.secondary) + if command.isCompleted { + Text(command.durationText(at: Date())) + .font(.system(size: 11)) + .foregroundColor(.secondary) + } else { + TimelineView(.periodic(from: .now, by: 0.08)) { context in + Text(command.durationText(at: context.date)) + .font(.system(size: 11)) + .foregroundColor(.secondary) + } + } } Spacer() } diff --git a/phpmon/Modules/Command History/UI/CommandHistoryView.swift b/phpmon/Modules/Command History/UI/CommandHistoryView.swift index 8ecc4838..73e7ad8e 100644 --- a/phpmon/Modules/Command History/UI/CommandHistoryView.swift +++ b/phpmon/Modules/Command History/UI/CommandHistoryView.swift @@ -12,12 +12,6 @@ struct CommandHistoryView: View { // Provides access to the tracked command history @ObservedObject var commandTracker: CommandTracker - // Timestamp used to compute duration labels in the list; updated when tick fires - @State private var now = Date() - - // Tracks whether the window view is currently visible - @State private var isWindowVisible = false - // IDs for visible, active rows; used to avoid ticking when none are on-screen @State private var visibleCommandIds: Set = [] @@ -34,7 +28,6 @@ struct CommandHistoryView: View { let isEvenRow = index.isMultiple(of: 2) CommandHistoryRow( command: command, - now: now, isEvenRow: isEvenRow, visibleCommandIds: $visibleCommandIds ) @@ -50,27 +43,6 @@ struct CommandHistoryView: View { } } .frame(minWidth: 400, minHeight: 200) - .onAppear { - // Mark the window as visible so duration ticking can start - isWindowVisible = true - now = Date() - } - .onDisappear { - // Stop ticking when the window disappears - isWindowVisible = false - } - .onReceive(Timer.publish(every: 0.08, on: .main, in: .common).autoconnect()) { _ in - // Only update running commands if the window is visible + there's command IDs that are: - // - visible (in window, based on scroll position) - // - running (so we need to update the timestamp periodically) - if commandTracker.isActive, shouldTick { - now = Date() - } - } } } - - private var shouldTick: Bool { - isWindowVisible && !visibleCommandIds.isEmpty - } }