From 57a948138a984cf93ac4a612915ff9f2d7110b41 Mon Sep 17 00:00:00 2001 From: kean Date: Tue, 3 Sep 2024 18:09:42 -0400 Subject: [PATCH] Decomission macOS (1) --- .../Features/Console/ConsoleView-macos.swift | 196 +++++++++--------- .../Features/Console/ConsoleView.swift | 4 + .../Console/Views/ConsoleContextMenu.swift | 8 +- .../Inspector/NetworkInspectorView.swift | 24 +-- .../Features/Sessions/SessionsView.swift | 46 +--- 5 files changed, 111 insertions(+), 167 deletions(-) diff --git a/Sources/PulseUI/Features/Console/ConsoleView-macos.swift b/Sources/PulseUI/Features/Console/ConsoleView-macos.swift index ee64684fa..b61d16dc0 100644 --- a/Sources/PulseUI/Features/Console/ConsoleView-macos.swift +++ b/Sources/PulseUI/Features/Console/ConsoleView-macos.swift @@ -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 diff --git a/Sources/PulseUI/Features/Console/ConsoleView.swift b/Sources/PulseUI/Features/Console/ConsoleView.swift index e5bb0548d..550f35c8b 100644 --- a/Sources/PulseUI/Features/Console/ConsoleView.swift +++ b/Sources/PulseUI/Features/Console/ConsoleView.swift @@ -2,6 +2,8 @@ // // Copyright (c) 2020-2024 Alexander Grebenyuk (github.com/kean). +#if !os(macOS) + import SwiftUI import CoreData import Pulse @@ -24,3 +26,5 @@ extension ConsoleView { self.init(environment: .init(store: store, mode: mode)) } } + +#endif diff --git a/Sources/PulseUI/Features/Console/Views/ConsoleContextMenu.swift b/Sources/PulseUI/Features/Console/Views/ConsoleContextMenu.swift index 6fb0a7ec4..88e4fce8c 100644 --- a/Sources/PulseUI/Features/Console/Views/ConsoleContextMenu.swift +++ b/Sources/PulseUI/Features/Console/Views/ConsoleContextMenu.swift @@ -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 @@ -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") @@ -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 } } diff --git a/Sources/PulseUI/Features/Inspector/NetworkInspectorView.swift b/Sources/PulseUI/Features/Inspector/NetworkInspectorView.swift index 2b2ad2c2b..ef5e4fb62 100644 --- a/Sources/PulseUI/Features/Inspector/NetworkInspectorView.swift +++ b/Sources/PulseUI/Features/Inspector/NetworkInspectorView.swift @@ -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 diff --git a/Sources/PulseUI/Features/Sessions/SessionsView.swift b/Sources/PulseUI/Features/Sessions/SessionsView.swift index f2a807804..01a76038b 100644 --- a/Sources/PulseUI/Features/Sessions/SessionsView.swift +++ b/Sources/PulseUI/Features/Sessions/SessionsView.swift @@ -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 = [] @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 @@ -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") { @@ -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) @@ -121,40 +103,18 @@ struct SessionsView: View { router.isShowingSessions = false } #endif - -#if os(macOS) - @ViewBuilder - private func contextMenu(for selection: Set) -> 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