diff --git a/Cork/App State.swift b/Cork/App State.swift index 71a4b7a5..cd2e39f8 100644 --- a/Cork/App State.swift +++ b/Cork/App State.swift @@ -22,7 +22,7 @@ class AppState: ObservableObject // MARK: - Navigation - @Published var navigationTarget: NavigationTargetMainWindow? + @Published var navigationTargetId: UUID? // MARK: - Notifications diff --git a/Cork/ContentView.swift b/Cork/ContentView.swift index c58d5c80..80234050 100644 --- a/Cork/ContentView.swift +++ b/Cork/ContentView.swift @@ -122,91 +122,89 @@ struct ContentView: View, Sendable var body: some View { - VStack + NavigationSplitView(columnVisibility: $columnVisibility) { - NavigationSplitView(columnVisibility: $columnVisibility) - { - SidebarView() - } detail: { - if let navigationTarget = appState.navigationTarget - { - switch navigationTarget - { - case .package(let brewPackage): - PackageDetailView(package: brewPackage) - case .tap(let brewTap): - TapDetailView(tap: brewTap) - } - } - else + SidebarView() + .navigationDestination(for: NavigationTargetMainWindow.self) + { navigationTarget in + switch navigationTarget { - StartPage() - .frame(minWidth: 600, minHeight: 500) + case .package(let brewPackage): + PackageDetailView(package: brewPackage) + .id(brewPackage.id) + case .tap(let brewTap): + TapDetailView(tap: brewTap) + .id(brewTap.id) } } - .navigationTitle("app-name") - .navigationSubtitle("navigation.installed-packages.count-\((displayOnlyIntentionallyInstalledPackagesByDefault ? brewData.installedFormulae.filter(\.installedIntentionally).count : brewData.installedFormulae.count) + brewData.installedCasks.count)") - .toolbar(id: "PackageActions") + } detail: { + NavigationStack { + StartPage() + .frame(minWidth: 600, minHeight: 500) + } + } + .navigationTitle("app-name") + .navigationSubtitle("navigation.installed-packages.count-\((displayOnlyIntentionallyInstalledPackagesByDefault ? brewData.installedFormulae.filter(\.installedIntentionally).count : brewData.installedFormulae.count) + brewData.installedCasks.count)") + .toolbar(id: "PackageActions") + { + ToolbarItem(id: "upgradePackages", placement: .primaryAction) { - ToolbarItem(id: "upgradePackages", placement: .primaryAction) - { - upgradePackagesButton - } + upgradePackagesButton + } - ToolbarItem(id: "addTap", placement: .primaryAction) - { - addTapButton - } + ToolbarItem(id: "addTap", placement: .primaryAction) + { + addTapButton + } - ToolbarItem(id: "installPackage", placement: .primaryAction) - { - installPackageButton - } + ToolbarItem(id: "installPackage", placement: .primaryAction) + { + installPackageButton + } - ToolbarItem(id: "maintenance", placement: .primaryAction) - { - performMaintenanceButton - } - .defaultCustomization(.hidden) + ToolbarItem(id: "maintenance", placement: .primaryAction) + { + performMaintenanceButton + } + .defaultCustomization(.hidden) - ToolbarItem(id: "manageServices", placement: .primaryAction) - { - manageServicesButton - } - .defaultCustomization(.hidden) + ToolbarItem(id: "manageServices", placement: .primaryAction) + { + manageServicesButton + } + .defaultCustomization(.hidden) - ToolbarItem(id: "spacer", placement: .primaryAction) - { - Spacer() - } - .defaultCustomization(.hidden) + ToolbarItem(id: "spacer", placement: .primaryAction) + { + Spacer() + } + .defaultCustomization(.hidden) - ToolbarItem(id: "divider", placement: .primaryAction) - { - Divider() - } - .defaultCustomization(.hidden) + ToolbarItem(id: "divider", placement: .primaryAction) + { + Divider() + } + .defaultCustomization(.hidden) - // TODO: Implement this button - /* - ToolbarItem(id: "installPackageDirectly", placement: .automatic) + // TODO: Implement this button + /* + ToolbarItem(id: "installPackageDirectly", placement: .automatic) + { + Button { - Button + AppConstants.logger.info("Ahoj") + } label: { + Label { - AppConstants.logger.info("Ahoj") - } label: { - Label - { - Text("navigation.install-package.direct") - } icon: { - Image(systemName: "plus.viewfinder") - } + Text("navigation.install-package.direct") + } icon: { + Image(systemName: "plus.viewfinder") } - .help("navigation.install-package.direct.help") } - .defaultCustomization(.hidden) - */ - } + .help("navigation.install-package.direct.help") + } + .defaultCustomization(.hidden) + */ } .onAppear { diff --git a/Cork/CorkApp.swift b/Cork/CorkApp.swift index 858e1fbd..12117719 100644 --- a/Cork/CorkApp.swift +++ b/Cork/CorkApp.swift @@ -509,11 +509,11 @@ struct CorkApp: App { Button { - appDelegate.appState.navigationTarget = nil + appDelegate.appState.navigationTargetId = nil } label: { Text("action.go-to-status-page.menu-bar") } - .disabled(appDelegate.appState.navigationTarget == nil) + .disabled(appDelegate.appState.navigationTargetId == nil) Divider() } diff --git a/Cork/Logic/Installation & Removal/Removal/Uninstall Packages.swift b/Cork/Logic/Installation & Removal/Removal/Uninstall Packages.swift index a2c27283..5e0e16c6 100644 --- a/Cork/Logic/Installation & Removal/Removal/Uninstall Packages.swift +++ b/Cork/Logic/Installation & Removal/Removal/Uninstall Packages.swift @@ -21,7 +21,7 @@ extension BrewDataStorage ) async throws { /// Store the old navigation selection to see if it got updated in the middle of switching - let oldNavigationSelectionID: NavigationTargetMainWindow? = appState.navigationTarget + let oldNavigationSelectionId: UUID? = appState.navigationTargetId if shouldApplyUninstallSpinnerToRelevantItemInSidebar { @@ -120,12 +120,12 @@ extension BrewDataStorage } } - if appState.navigationTarget != nil + if appState.navigationTargetId != nil { /// Switch to the status page only if the user didn't open another details window in the middle of the uninstall process - if oldNavigationSelectionID == appState.navigationTarget + if oldNavigationSelectionId == appState.navigationTargetId { - appState.navigationTarget = nil + appState.navigationTargetId = nil } } } diff --git a/Cork/Logic/Taps/Remove Tap.swift b/Cork/Logic/Taps/Remove Tap.swift index 3498f191..c1fab9cb 100644 --- a/Cork/Logic/Taps/Remove Tap.swift +++ b/Cork/Logic/Taps/Remove Tap.swift @@ -29,7 +29,7 @@ func removeTap(name: String, availableTaps: AvailableTaps, appState: AppState, s var indexToReplaceGlobal: Int? /// Store the old navigation selection to see if it got updated in the middle of switching - let oldNavigationTarget: NavigationTargetMainWindow? = appState.navigationTarget + let oldNavigationTargetId: UUID? = appState.navigationTargetId if shouldApplyUninstallSpinnerToRelevantItemInSidebar { @@ -64,12 +64,12 @@ func removeTap(name: String, availableTaps: AvailableTaps, appState: AppState, s } } - if appState.navigationTarget != nil + if appState.navigationTargetId != nil { /// Switch to the status page only if the user didn't open another details window in the middle of the tap removal process - if oldNavigationTarget == appState.navigationTarget + if oldNavigationTargetId == appState.navigationTargetId { - appState.navigationTarget = nil + appState.navigationTargetId = nil } } } diff --git a/Cork/Views/Sidebar/Sidebar View.swift b/Cork/Views/Sidebar/Sidebar View.swift index 3c09d81f..1765f5ef 100644 --- a/Cork/Views/Sidebar/Sidebar View.swift +++ b/Cork/Views/Sidebar/Sidebar View.swift @@ -20,7 +20,7 @@ struct SidebarView: View ] @State private var currentTokens: [PackageSearchToken] = .init() - @State private var localNavigationTraget: NavigationTargetMainWindow? + @State private var localNavigationTragetId: UUID? var suggestedTokens: [PackageSearchToken] { @@ -37,7 +37,7 @@ struct SidebarView: View var body: some View { /// Navigation selection enables "Home" button behaviour. [2023.09] - List(selection: $localNavigationTraget) + List(selection: $localNavigationTragetId) { if currentTokens.isEmpty || currentTokens.contains(.formula) || currentTokens.contains(.intentionallyInstalledPackage) { @@ -54,16 +54,16 @@ struct SidebarView: View TapsSection(searchText: searchText) } } - .onChange(of: localNavigationTraget) + .onChange(of: localNavigationTragetId) { newValue in - if appState.navigationTarget != newValue { - appState.navigationTarget = newValue + if appState.navigationTargetId != newValue { + appState.navigationTargetId = newValue } } - .onReceive(appState.$navigationTarget.receive(on: DispatchQueue.main)) + .onReceive(appState.$navigationTargetId.receive(on: DispatchQueue.main)) { newValue in - if localNavigationTraget != newValue { - localNavigationTraget = newValue + if localNavigationTragetId != newValue { + localNavigationTragetId = newValue } } .listStyle(.sidebar) @@ -105,12 +105,14 @@ struct SidebarView: View { Button { - appState.navigationTarget = nil + appState.navigationTargetId = nil } label: { Label("action.go-to-status-page", systemImage: "house") } .help("action.go-to-status-page") - .disabled(appState.navigationTarget == nil || !searchText.isEmpty || !currentTokens.isEmpty) + .disabled( + appState.navigationTargetId == nil || !searchText.isEmpty || !currentTokens.isEmpty + ) } .defaultCustomization(.visible, options: .alwaysAvailable) }