forked from kean/Pulse
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConsoleView-macos.swift
132 lines (117 loc) · 4.48 KB
/
ConsoleView-macos.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
// The MIT License (MIT)
//
// Copyright (c) 2020-2024 Alexander Grebenyuk (github.com/kean).
#if os(macOS)
import SwiftUI
import CoreData
import Pulse
import Combine
public struct ConsoleView: View {
@StateObject private var environment: ConsoleEnvironment
init(environment: ConsoleEnvironment) {
_environment = StateObject(wrappedValue: environment)
}
public var body: some View {
if #available(macOS 13, *) {
NavigationStack {
ConsoleMainView(environment: environment)
}
.injecting(environment)
.navigationTitle("")
} else {
PlaceholderView(imageName: "xmark.octagon", title: "Unsupported", subtitle: "Pulse requires macOS 13 or later").padding()
}
}
}
/// This view contains the console itself along with the details (no sidebar).
@available(macOS 13, *)
@MainActor
private struct ConsoleMainView: View {
let environment: ConsoleEnvironment
@State private var isSharingStore = false
@State private var isShowingFilters = false
@State private var isShowingSessions = false
@State private var isShowingSettings = false
@SceneStorage("com-github-kean-pulse-is-now-enabled") private var isNowEnabled = true
var body: some View {
HSplitView {
contentView
detailsView.layoutPriority(1)
}
}
private var contentView: some View {
ConsoleListView()
.frame(minWidth: 400, idealWidth: 500, minHeight: 120, idealHeight: 480)
.toolbar {
ToolbarItemGroup(placement: .navigation) {
contentToolbarNavigationItems
}
ToolbarItemGroup(placement: .automatic) {
Button(action: { isShowingFilters = true }) {
Label("Show Filters", systemImage: "line.3.horizontal.decrease.circle")
}
.help("Show Filters")
.popover(isPresented: $isShowingFilters) {
ConsoleFiltersView().frame(width: 300).fixedSize()
}
Button(action: { isShowingSessions = true }) {
Label("Show Sessions", systemImage: "list.clipboard")
}
.help("Show Sessions")
.popover(isPresented: $isShowingSessions) {
SessionsView().frame(width: 300, height: 420)
}
Button(action: { isShowingSettings = true }) {
Label("Show Settings", systemImage: "gearshape")
}
.help("Show Settings")
.popover(isPresented: $isShowingSettings, arrowEdge: .bottom) {
SettingsView().frame(width: 300, height: environment.configuration.allowRemoteLogging ? 420 : 175)
}
}
}
}
private var detailsView: some View {
_ConsoleDetailsView()
}
@ViewBuilder
private var contentToolbarNavigationItems: some View {
if !(environment.store.options.contains(.readonly)) {
Toggle(isOn: $isNowEnabled) {
Image(systemName: "clock")
}.help("Now Mode: Automatically scrolls to the top of the view to display newly incoming network requests.")
Button(action: { isSharingStore = true }) {
Image(systemName: "square.and.arrow.up")
}
.help("Share a session")
.popover(isPresented: $isSharingStore, arrowEdge: .bottom) {
ShareStoreView(onDismiss: {})
.frame(width: 240).fixedSize()
}
Button(action: { environment.store.removeAll() }) {
Image(systemName: "trash")
}
.help("Clear current session")
}
}
}
@available(iOS 15, macOS 13, *)
private struct _ConsoleDetailsView: View {
@EnvironmentObject private var router: ConsoleRouter
var body: some View {
if let selection = router.selection {
ConsoleEntityDetailsRouterView(selection: selection)
.background(Color(UXColor.textBackgroundColor))
.frame(minWidth: 400, idealWidth: 700, minHeight: 120, idealHeight: 480)
}
}
}
#if DEBUG
struct ConsoleView_Previews: PreviewProvider {
static var previews: some View {
ConsoleView(store: .mock)
.previewLayout(.fixed(width: 700, height: 400))
}
}
#endif
#endif