Skip to content

Commit

Permalink
Decomission macOS (1)
Browse files Browse the repository at this point in the history
  • Loading branch information
kean committed Sep 3, 2024
1 parent 598a5e3 commit 57a9481
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 167 deletions.
196 changes: 93 additions & 103 deletions Sources/PulseUI/Features/Console/ConsoleView-macos.swift
Original file line number Diff line number Diff line change
@@ -1,103 +1,93 @@
// 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, *) {
_ConsoleView(environment: environment)
} else {
PlaceholderView(imageName: "xmark.octagon", title: "Unsupported", subtitle: "Pulse requires macOS 13 or later").padding()
}
}
}

@available(macOS 13, *)
private struct _ConsoleView: View {
@StateObject private var environment: ConsoleEnvironment
@State private var columnVisibility = NavigationSplitViewVisibility.all

init(environment: ConsoleEnvironment) {
_environment = StateObject(wrappedValue: environment)
}

public var body: some View {
NavigationSplitView(
columnVisibility: $columnVisibility,
sidebar: {
ConsoleMainView(environment: environment)
.navigationSplitViewColumnWidth(min: 320, ideal: 420, max: 640)
},
detail: {
EmptyView()
}
)
.injecting(environment)
.navigationTitle("")
}
}

/// 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

@EnvironmentObject var router: ConsoleRouter

var body: some View {
ConsoleListView()
.frame(minWidth: 300, idealWidth: 500, minHeight: 120, idealHeight: 480)
.toolbar {
ToolbarItemGroup(placement: .automatic) {
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: { isShowingFilters = true }) {
Label("Show Filters", systemImage: "line.3.horizontal.decrease.circle")
}
.help("Show Filters")
.popover(isPresented: $isShowingFilters) {
ConsoleFiltersView().frame(width: 300).fixedSize()
}

ConsoleContextMenu()
.popover(isPresented: $router.isShowingSessions) {
SessionsView().frame(width: 300, height: 420)
}
}
}
}
}

#if DEBUG
struct ConsoleView_Previews: PreviewProvider {
static var previews: some View {
ConsoleView(store: .mock)
.previewLayout(.fixed(width: 700, height: 400))
}
}
#endif
#endif
//// 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, *) {
// _ConsoleView(environment: environment)
// } else {
// PlaceholderView(imageName: "xmark.octagon", title: "Unsupported", subtitle: "Pulse requires macOS 13 or later").padding()
// }
// }
//}
//
//@available(macOS 13, *)
//private struct _ConsoleView: View {
// @StateObject private var environment: ConsoleEnvironment
// @State private var columnVisibility = NavigationSplitViewVisibility.all
//
// init(environment: ConsoleEnvironment) {
// _environment = StateObject(wrappedValue: environment)
// }
//
// public var body: some View {
// NavigationStack {
// ConsoleMainView(environment: environment)
// .navigationSplitViewColumnWidth(min: 320, ideal: 420, max: 640)
// }
// .injecting(environment)
// .navigationTitle("")
// }
//}
//
///// 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
//
// @EnvironmentObject var router: ConsoleRouter
//
// var body: some View {
// ConsoleListView()
// .frame(minWidth: 300, idealWidth: 500, minHeight: 120, idealHeight: 480)
// .toolbar {
// ToolbarItemGroup(placement: .automatic) {
// 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: { isShowingFilters = true }) {
// Label("Show Filters", systemImage: "line.3.horizontal.decrease.circle")
// }
// .help("Show Filters")
// .popover(isPresented: $isShowingFilters) {
// ConsoleFiltersView().frame(width: 300).fixedSize()
// }
//
//
// }
// }
//}
//
//#if DEBUG
//struct ConsoleView_Previews: PreviewProvider {
// static var previews: some View {
// ConsoleView(store: .mock)
// .previewLayout(.fixed(width: 700, height: 400))
// }
//}
//#endif
//#endif
4 changes: 4 additions & 0 deletions Sources/PulseUI/Features/Console/ConsoleView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
//
// Copyright (c) 2020-2024 Alexander Grebenyuk (github.com/kean).

#if !os(macOS)

import SwiftUI
import CoreData
import Pulse
Expand All @@ -24,3 +26,5 @@ extension ConsoleView {
self.init(environment: .init(store: store, mode: mode))
}
}

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//
// Copyright (c) 2020-2024 Alexander Grebenyuk (github.com/kean).

#if os(iOS) || os(visionOS) || os(macOS)
#if os(iOS) || os(visionOS)

import SwiftUI
import CoreData
Expand All @@ -21,11 +21,9 @@ struct ConsoleContextMenu: View {
Label("Sessions", systemImage: "list.bullet.clipboard")
}
}
#if os(iOS) || os(visionOS)
Section {
ConsoleSortByMenu()
}
#endif
Section {
Button(action: { router.isShowingSettings = true }) {
Label("Settings", systemImage: "gear")
Expand Down Expand Up @@ -60,11 +58,7 @@ struct ConsoleContextMenu: View {
}

private func openURL(_ url: URL) {
#if os(macOS)
NSWorkspace.shared.open(url)
#else
UIApplication.shared.open(url)
#endif
}
}

Expand Down
24 changes: 10 additions & 14 deletions Sources/PulseUI/Features/Inspector/NetworkInspectorView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,17 @@ struct NetworkInspectorView: View {
}
#else
var body: some View {
NavigationSplitView(sidebar: {
List {
contents
.listRowSeparator(.hidden)
}
.scrollContentBackground(.hidden)
.animation(.default, value: task.state)
.toolbar {
ToolbarItemGroup(placement: .automatic) {
trailingNavigationBarItems
}
List {
contents
.listRowSeparator(.hidden)
}
.scrollContentBackground(.hidden)
.animation(.default, value: task.state)
.toolbar {
ToolbarItemGroup(placement: .automatic) {
trailingNavigationBarItems
}
}, detail: {
EmptyView()
})
}
}
#endif

Expand Down
46 changes: 3 additions & 43 deletions Sources/PulseUI/Features/Sessions/SessionsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,13 @@ import SwiftUI
import CoreData
import Combine

#if os(iOS) || os(macOS) || os(visionOS)
#if os(iOS) || os(visionOS)

@available(iOS 15, macOS 13, visionOS 1.0, *)
@available(iOS 15, visionOS 1.0, *)
struct SessionsView: View {
@State private var selection: Set<UUID> = []
@State private var sharedSessions: SelectedSessionsIDs?

#if os(iOS) || os(visionOS)
@State private var editMode: EditMode = .inactive
#endif

@EnvironmentObject private var environment: ConsoleEnvironment
@EnvironmentObject private var filters: ConsoleFiltersViewModel
Expand All @@ -35,7 +32,6 @@ struct SessionsView: View {
@ViewBuilder
private var content: some View {
list
#if os(iOS) || os(visionOS)
.toolbar {
ToolbarItem(placement: .navigationBarTrailing) {
Button(editMode.isEditing ? "Done" : "Edit") {
Expand All @@ -55,29 +51,15 @@ struct SessionsView: View {
ShareStoreView(sessions: sessions.ids, onDismiss: { sharedSessions = nil })
}.backport.presentationDetents([.medium, .large])
}
#else
.popover(item: $sharedSessions, arrowEdge: .leading) { sessions in
ShareStoreView(sessions: sessions.ids, onDismiss: { sharedSessions = nil })
.frame(width: 240).fixedSize()
}
#endif
}

private var list: some View {
SessionListView(selection: $selection, sharedSessions: $sharedSessions)
#if os(iOS) || os(visionOS)
.environment(\.editMode, $editMode)
.onChange(of: selection) {
guard !editMode.isEditing, !$0.isEmpty else { return }
showInConsole(sessions: $0)
}
#else
.contextMenu(forSelectionType: UUID.self, menu: contextMenu)
.onChange(of: selection) {
guard filters.criteria.shared.sessions.selection != $0 else { return }
filters.select(sessions: $0)
}
#endif
}

#if os(iOS) || os(visionOS)
Expand Down Expand Up @@ -121,40 +103,18 @@ struct SessionsView: View {
router.isShowingSessions = false
}
#endif

#if os(macOS)
@ViewBuilder
private func contextMenu(for selection: Set<UUID>) -> some View {
Button(action: { sharedSessions = SelectedSessionsIDs(ids: selection) }, label: {
Label("Share", systemImage: "square.and.arrow.up")
})
.disabled(selection.isEmpty)

if !(store.options.contains(.readonly)) {
Button(role: .destructive, action: {
store.removeSessions(withIDs: selection)
self.selection = []
}, label: { Label("Remove", systemImage: "trash") })
}
}
#endif
}

#if DEBUG
@available(iOS 15.0, macOS 13, visionOS 1.0, *)
@available(iOS 15.0, visionOS 1.0, *)
struct Previews_SessionsView_Previews: PreviewProvider {
static let environment = ConsoleEnvironment(store: .mock)

static var previews: some View {
#if os(iOS) || os(visionOS)
NavigationView {
SessionsView()
.injecting(environment)
}
#else
SessionsView()
.injecting(environment)
#endif
}
}
#endif
Expand Down

0 comments on commit 57a9481

Please sign in to comment.