diff --git a/Sources/PulseUI/Features/Console/ConsoleDelegate.swift b/Sources/PulseUI/Features/Console/ConsoleDelegate.swift index fb390337b..b174ba90d 100644 --- a/Sources/PulseUI/Features/Console/ConsoleDelegate.swift +++ b/Sources/PulseUI/Features/Console/ConsoleDelegate.swift @@ -5,26 +5,18 @@ import Foundation import Pulse -/// Allows you to customize the console behavior. -public protocol ConsoleViewDelegate { - /// Returns a title for the given task. - func getTitle(for task: NetworkTaskEntity) -> String? -} - -extension ConsoleViewDelegate { - func getTitle(for task: NetworkTaskEntity) -> String? { +enum ConsoleViewDelegate { + static func getTitle(for task: NetworkTaskEntity) -> String? { if let taskDescription = task.taskDescription, !taskDescription.isEmpty { return taskDescription } return task.url } - func getShortTitle(for task: NetworkTaskEntity) -> String { + static func getShortTitle(for task: NetworkTaskEntity) -> String { guard let title = getTitle(for: task) else { return "" } return URL(string: title)?.lastPathComponent ?? title } } - -struct DefaultConsoleViewDelegate: ConsoleViewDelegate {} diff --git a/Sources/PulseUI/Features/Console/ConsoleEnvironment.swift b/Sources/PulseUI/Features/Console/ConsoleEnvironment.swift index 54b90330e..eea266466 100644 --- a/Sources/PulseUI/Features/Console/ConsoleEnvironment.swift +++ b/Sources/PulseUI/Features/Console/ConsoleEnvironment.swift @@ -23,7 +23,6 @@ final class ConsoleEnvironment: ObservableObject { let router = ConsoleRouter() let initialMode: ConsoleMode - let delegate: ConsoleViewDelegate @Published var mode: ConsoleMode @Published var listOptions: ConsoleListOptions = .init() @@ -38,7 +37,7 @@ final class ConsoleEnvironment: ObservableObject { private var cancellables: [AnyCancellable] = [] - init(store: LoggerStore, mode: ConsoleMode = .all, delegate: ConsoleViewDelegate = DefaultConsoleViewDelegate()) { + init(store: LoggerStore, mode: ConsoleMode = .all) { self.store = store switch mode { case .all: self.title = "Console" @@ -53,8 +52,6 @@ final class ConsoleEnvironment: ObservableObject { case .network: self.mode = .network } - self.delegate = delegate - func makeDefaultOptions() -> ConsoleDataSource.PredicateOptions { var options = ConsoleDataSource.PredicateOptions() options.filters.shared.sessions.selection = [store.session.id] diff --git a/Sources/PulseUI/Features/Console/ConsoleView-ios.swift b/Sources/PulseUI/Features/Console/ConsoleView-ios.swift index 26ed3c4a1..635cecdc4 100644 --- a/Sources/PulseUI/Features/Console/ConsoleView-ios.swift +++ b/Sources/PulseUI/Features/Console/ConsoleView-ios.swift @@ -70,7 +70,7 @@ struct ConsoleView_Previews: PreviewProvider { static var previews: some View { Group { NavigationView { - ConsoleView(environment: .init(store: .mock, delegate: DefaultConsoleViewDelegate())) + ConsoleView(environment: .init(store: .mock)) }.previewDisplayName("Console") NavigationView { ConsoleView(store: .mock, mode: .network) diff --git a/Sources/PulseUI/Features/Console/ConsoleView.swift b/Sources/PulseUI/Features/Console/ConsoleView.swift index aa49f03ce..e5bb0548d 100644 --- a/Sources/PulseUI/Features/Console/ConsoleView.swift +++ b/Sources/PulseUI/Features/Console/ConsoleView.swift @@ -19,9 +19,8 @@ extension ConsoleView { /// of the console view. public init( store: LoggerStore = .shared, - mode: ConsoleMode = .all, - delegate: ConsoleViewDelegate? = nil + mode: ConsoleMode = .all ) { - self.init(environment: .init(store: store, mode: mode, delegate: delegate ?? DefaultConsoleViewDelegate())) + self.init(environment: .init(store: store, mode: mode)) } } diff --git a/Sources/PulseUI/Features/Console/Views/ConsoleTaskCell.swift b/Sources/PulseUI/Features/Console/Views/ConsoleTaskCell.swift index 15bf8df23..e61bfdbb8 100644 --- a/Sources/PulseUI/Features/Console/Views/ConsoleTaskCell.swift +++ b/Sources/PulseUI/Features/Console/Views/ConsoleTaskCell.swift @@ -14,7 +14,6 @@ struct ConsoleTaskCell: View { @ObservedObject private var settings: UserSettings = .shared @Environment(\.store) private var store: LoggerStore - @EnvironmentObject var environment: ConsoleEnvironment var body: some View { #if os(macOS) @@ -82,7 +81,7 @@ struct ConsoleTaskCell: View { private var message: some View { VStack(spacing: 3) { HStack { - Text(environment.delegate.getTitle(for: task) ?? "–") + Text(ConsoleViewDelegate.getTitle(for: task) ?? "–") .font(ConsoleConstants.fontBody) .foregroundColor(.primary) .lineLimit(settings.lineLimit) diff --git a/Sources/PulseUI/Features/Inspector/NetworkInspectorView.swift b/Sources/PulseUI/Features/Inspector/NetworkInspectorView.swift index 53b49a27d..ef5e4fb62 100644 --- a/Sources/PulseUI/Features/Inspector/NetworkInspectorView.swift +++ b/Sources/PulseUI/Features/Inspector/NetworkInspectorView.swift @@ -16,7 +16,6 @@ struct NetworkInspectorView: View { @State private var shareItems: ShareItems? @State private var sharedTask: NetworkTaskEntity? @ObservedObject private var settings: UserSettings = .shared - @EnvironmentObject private var environment: ConsoleEnvironment @Environment(\.store) private var store #if os(iOS) || os(visionOS) @@ -29,7 +28,7 @@ struct NetworkInspectorView: View { .safeAreaInset(edge: .bottom) { OpenOnMacOverlay(entity: task) } - .inlineNavigationTitle(environment.delegate.getShortTitle(for: task)) + .inlineNavigationTitle(ConsoleViewDelegate.getShortTitle(for: task)) .sheet(item: $shareItems, content: ShareView.init) .toolbar { ToolbarItemGroup(placement: .automatic) { diff --git a/Sources/PulseUI/Features/Search/Views/ConsoleSearchSuggestionsView.swift b/Sources/PulseUI/Features/Search/Views/ConsoleSearchSuggestionsView.swift index df0eee9a4..dfb461e84 100644 --- a/Sources/PulseUI/Features/Search/Views/ConsoleSearchSuggestionsView.swift +++ b/Sources/PulseUI/Features/Search/Views/ConsoleSearchSuggestionsView.swift @@ -64,7 +64,7 @@ struct ConsoleSearchSuggestionsView: View { #if DEBUG @available(iOS 15, visionOS 1.0, *) struct Previews_ConsoleSearchSuggestionsView_Previews: PreviewProvider { - static let environment = ConsoleEnvironment(store: .mock, delegate: DefaultConsoleViewDelegate()) + static let environment = ConsoleEnvironment(store: .mock) static var previews: some View { List { diff --git a/Sources/PulseUI/PulseUI.docc/PulseUI.md b/Sources/PulseUI/PulseUI.docc/PulseUI.md index f170f9e85..9aed84e83 100644 --- a/Sources/PulseUI/PulseUI.docc/PulseUI.md +++ b/Sources/PulseUI/PulseUI.docc/PulseUI.md @@ -24,8 +24,6 @@ NavigationLink(destination: ConsoleView()) { > tip: If you use Pulse to log only network requests, and not text messages, use `ConsoleView(mode: .network)` to show a view specialized to only display network requests. -The console can be customized using ``ConsoleViewDelegate`` and ``UserSettings``. - ## UIKit To present the console from `UIKit`, use `UIHostingController`: