From 706c4db28cac0aa269dc3598a830ec976e246402 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Bures=CC=8C?= Date: Mon, 4 Nov 2024 21:25:28 +0100 Subject: [PATCH] + First broken implementation --- Cork/Views/Maintenance/Maintenance View.swift | 102 +++++++++------- .../Sub-Views/Maintenance Running View.swift | 4 +- .../Maintenance/Sub-Views/Ready View.swift | 113 +++++++++--------- .../Settings/Panes/Maintenance Pane.swift | 3 - 4 files changed, 122 insertions(+), 100 deletions(-) diff --git a/Cork/Views/Maintenance/Maintenance View.swift b/Cork/Views/Maintenance/Maintenance View.swift index d4f19be8..ba10f652 100644 --- a/Cork/Views/Maintenance/Maintenance View.swift +++ b/Cork/Views/Maintenance/Maintenance View.swift @@ -7,17 +7,27 @@ import SwiftUI -enum MaintenanceSteps +enum MaintenanceSteps: Hashable { case ready, maintenanceRunning, finished } struct MaintenanceView: View { + class MaintenanceNavigationManager: ObservableObject + { + @Published var navigationPath: NavigationPath = .init() + + func navigate(to screen: MaintenanceSteps) + { + self.navigationPath.append(screen) + } + } + @EnvironmentObject var brewData: BrewDataStorage @EnvironmentObject var appState: AppState - @State var maintenanceSteps: MaintenanceSteps = .ready + @StateObject var navigationManager: MaintenanceNavigationManager = .init() @State var shouldPurgeCache: Bool = true @State var shouldDeleteDownloads: Bool = true @@ -38,47 +48,57 @@ struct MaintenanceView: View var body: some View { - VStack(alignment: .leading, spacing: 10) + NavigationStack(path: $navigationManager.navigationPath) { - switch maintenanceSteps - { - case .ready: - MaintenanceReadyView( - shouldUninstallOrphans: $shouldUninstallOrphans, - shouldPurgeCache: $shouldPurgeCache, - shouldDeleteDownloads: $shouldDeleteDownloads, - shouldPerformHealthCheck: $shouldPerformHealthCheck, - maintenanceSteps: $maintenanceSteps, - isShowingControlButtons: true, - forcedOptions: forcedOptions! - ) - - case .maintenanceRunning: - MaintenanceRunningView( - shouldUninstallOrphans: shouldUninstallOrphans, - shouldPurgeCache: shouldPurgeCache, - shouldDeleteDownloads: shouldDeleteDownloads, - shouldPerformHealthCheck: shouldPerformHealthCheck, - numberOfOrphansRemoved: $numberOfOrphansRemoved, - packagesHoldingBackCachePurge: $packagesHoldingBackCachePurge, - reclaimedSpaceAfterCachePurge: $reclaimedSpaceAfterCachePurge, - brewHealthCheckFoundNoProblems: $brewHealthCheckFoundNoProblems, - maintenanceSteps: $maintenanceSteps - ) - - case .finished: - MaintenanceFinishedView( - shouldUninstallOrphans: shouldUninstallOrphans, - shouldPurgeCache: shouldPurgeCache, - shouldDeleteDownloads: shouldDeleteDownloads, - shouldPerformHealthCheck: shouldPerformHealthCheck, - packagesHoldingBackCachePurge: packagesHoldingBackCachePurge, - numberOfOrphansRemoved: numberOfOrphansRemoved, - reclaimedSpaceAfterCachePurge: reclaimedSpaceAfterCachePurge, - brewHealthCheckFoundNoProblems: brewHealthCheckFoundNoProblems, - maintenanceFoundNoProblems: $maintenanceFoundNoProblems - ) + MaintenanceReadyView( + shouldUninstallOrphans: $shouldUninstallOrphans, + shouldPurgeCache: $shouldPurgeCache, + shouldDeleteDownloads: $shouldDeleteDownloads, + shouldPerformHealthCheck: $shouldPerformHealthCheck, + isShowingControlButtons: true, + forcedOptions: forcedOptions! + ) + .navigationDestination(for: MaintenanceSteps.self) + { step in + switch step + { + case .maintenanceRunning: + MaintenanceRunningView( + shouldUninstallOrphans: shouldUninstallOrphans, + shouldPurgeCache: shouldPurgeCache, + shouldDeleteDownloads: shouldDeleteDownloads, + shouldPerformHealthCheck: shouldPerformHealthCheck, + numberOfOrphansRemoved: $numberOfOrphansRemoved, + packagesHoldingBackCachePurge: $packagesHoldingBackCachePurge, + reclaimedSpaceAfterCachePurge: $reclaimedSpaceAfterCachePurge, + brewHealthCheckFoundNoProblems: $brewHealthCheckFoundNoProblems + ) + .toolbar(.hidden, for: .windowToolbar) + case .finished: + MaintenanceFinishedView( + shouldUninstallOrphans: shouldUninstallOrphans, + shouldPurgeCache: shouldPurgeCache, + shouldDeleteDownloads: shouldDeleteDownloads, + shouldPerformHealthCheck: shouldPerformHealthCheck, + packagesHoldingBackCachePurge: packagesHoldingBackCachePurge, + numberOfOrphansRemoved: numberOfOrphansRemoved, + reclaimedSpaceAfterCachePurge: reclaimedSpaceAfterCachePurge, + brewHealthCheckFoundNoProblems: brewHealthCheckFoundNoProblems, + maintenanceFoundNoProblems: $maintenanceFoundNoProblems + ) + .toolbar(.hidden, for: .windowToolbar) + default: + MaintenanceReadyView( + shouldUninstallOrphans: $shouldUninstallOrphans, + shouldPurgeCache: $shouldPurgeCache, + shouldDeleteDownloads: $shouldDeleteDownloads, + shouldPerformHealthCheck: $shouldPerformHealthCheck, + isShowingControlButtons: true, + forcedOptions: forcedOptions! + ) + } } } + .environmentObject(navigationManager) } } diff --git a/Cork/Views/Maintenance/Sub-Views/Maintenance Running View.swift b/Cork/Views/Maintenance/Sub-Views/Maintenance Running View.swift index 15b4c6ad..aad66b88 100644 --- a/Cork/Views/Maintenance/Sub-Views/Maintenance Running View.swift +++ b/Cork/Views/Maintenance/Sub-Views/Maintenance Running View.swift @@ -12,6 +12,7 @@ struct MaintenanceRunningView: View { @EnvironmentObject var appState: AppState @EnvironmentObject var brewData: BrewDataStorage + @EnvironmentObject var navigationManager: MaintenanceView.MaintenanceNavigationManager @State var currentMaintenanceStepText: LocalizedStringKey = "maintenance.step.initial" @@ -24,7 +25,6 @@ struct MaintenanceRunningView: View @Binding var packagesHoldingBackCachePurge: [String] @Binding var reclaimedSpaceAfterCachePurge: Int @Binding var brewHealthCheckFoundNoProblems: Bool - @Binding var maintenanceSteps: MaintenanceSteps var body: some View { @@ -111,7 +111,7 @@ struct MaintenanceRunningView: View AppConstants.shared.logger.info("Will not perform health check") } - maintenanceSteps = .finished + navigationManager.navigate(to: .finished) } } .padding() diff --git a/Cork/Views/Maintenance/Sub-Views/Ready View.swift b/Cork/Views/Maintenance/Sub-Views/Ready View.swift index 98e257df..20c7d51c 100644 --- a/Cork/Views/Maintenance/Sub-Views/Ready View.swift +++ b/Cork/Views/Maintenance/Sub-Views/Ready View.swift @@ -14,14 +14,16 @@ struct MaintenanceReadyView: View @AppStorage("default_shouldPurgeCache") var default_shouldPurgeCache: Bool = true @AppStorage("default_shouldDeleteDownloads") var default_shouldDeleteDownloads: Bool = true @AppStorage("default_shouldPerformHealthCheck") var default_shouldPerformHealthCheck: Bool = false + + @EnvironmentObject var navigationManager: MaintenanceView.MaintenanceNavigationManager + + @Environment(\.dismiss) var dismiss: DismissAction @Binding var shouldUninstallOrphans: Bool @Binding var shouldPurgeCache: Bool @Binding var shouldDeleteDownloads: Bool @Binding var shouldPerformHealthCheck: Bool - @Binding var maintenanceSteps: MaintenanceSteps - @State var isShowingControlButtons: Bool @State var forcedOptions: Bool @@ -30,80 +32,83 @@ struct MaintenanceReadyView: View var body: some View { - SheetWithTitle(title: "maintenance.title") + VStack(alignment: .leading, spacing: 10) { - VStack(alignment: .leading, spacing: 10) + Form { - Form + LabeledContent("maintenance.steps.packages") { - LabeledContent("maintenance.steps.packages") + VStack(alignment: .leading) { - VStack(alignment: .leading) + Toggle(isOn: $shouldUninstallOrphans) { - Toggle(isOn: $shouldUninstallOrphans) - { - Text("maintenance.steps.packages.uninstall-orphans") - } + Text("maintenance.steps.packages.uninstall-orphans") } } - - LabeledContent("maintenance.steps.downloads") + } + + LabeledContent("maintenance.steps.downloads") + { + VStack(alignment: .leading) { - VStack(alignment: .leading) + Toggle(isOn: $shouldPurgeCache) { - Toggle(isOn: $shouldPurgeCache) - { - Text("maintenance.steps.downloads.purge-cache") - } - Toggle(isOn: $shouldDeleteDownloads) - { - Text("maintenance.steps.downloads.delete-cached-downloads") - } + Text("maintenance.steps.downloads.purge-cache") } - } - - LabeledContent("maintenance.steps.other") - { - Toggle(isOn: $shouldPerformHealthCheck) + Toggle(isOn: $shouldDeleteDownloads) { - Text("maintenance.steps.other.health-check") + Text("maintenance.steps.downloads.delete-cached-downloads") } } } - - if isShowingControlButtons + + LabeledContent("maintenance.steps.other") { - HStack + Toggle(isOn: $shouldPerformHealthCheck) { - DismissSheetButton() - - Spacer() - - Button - { - AppConstants.shared.logger.debug("Start") - - maintenanceSteps = .maintenanceRunning - } label: { - Text("maintenance.steps.start") - } - .keyboardShortcut(.defaultAction) - .disabled(isStartDisabled) + Text("maintenance.steps.other.health-check") } - // .padding(.top) } } - .onAppear + .toolbar { - if !forcedOptions + ToolbarItem(placement: .cancellationAction) { - /// Replace the provided values with those from AppStorage - /// I have to do this because I don't want the settings in the sheet itself to affect those in the defaults - shouldUninstallOrphans = default_shouldUninstallOrphans - shouldPurgeCache = default_shouldPurgeCache - shouldDeleteDownloads = default_shouldDeleteDownloads - shouldPerformHealthCheck = default_shouldPerformHealthCheck + Button + { + dismiss() + } label: { + Text("action.cancel") + } + .keyboardShortcut(.cancelAction) } + + ToolbarItem(placement: .primaryAction) + { + Button + { + AppConstants.shared.logger.debug("Start") + + navigationManager.navigate(to: .maintenanceRunning) + } label: { + Text("maintenance.steps.start") + } + .keyboardShortcut(.defaultAction) + .disabled(isStartDisabled) + } + } + .navigationTitle("maintenance.title") + } + .onAppear + { + if !forcedOptions + { + /// Replace the provided values with those from AppStorage + /// I have to do this because I don't want the settings in the sheet itself to affect those in the defaults + shouldUninstallOrphans = default_shouldUninstallOrphans + shouldPurgeCache = default_shouldPurgeCache + shouldDeleteDownloads = default_shouldDeleteDownloads + shouldPerformHealthCheck = default_shouldPerformHealthCheck } } .if(enablePadding, transform: { viewProxy in diff --git a/Cork/Views/Settings/Panes/Maintenance Pane.swift b/Cork/Views/Settings/Panes/Maintenance Pane.swift index ab6c190a..abeacd95 100644 --- a/Cork/Views/Settings/Panes/Maintenance Pane.swift +++ b/Cork/Views/Settings/Panes/Maintenance Pane.swift @@ -14,8 +14,6 @@ struct MaintenancePane: View @AppStorage("default_shouldDeleteDownloads") var default_shouldDeleteDownloads: Bool = true @AppStorage("default_shouldPerformHealthCheck") var default_shouldPerformHealthCheck: Bool = false - @State var maintenanceStepsDummy: MaintenanceSteps = .ready - var body: some View { SettingsPaneTemplate @@ -29,7 +27,6 @@ struct MaintenancePane: View shouldPurgeCache: $default_shouldPurgeCache, shouldDeleteDownloads: $default_shouldDeleteDownloads, shouldPerformHealthCheck: $default_shouldPerformHealthCheck, - maintenanceSteps: $maintenanceStepsDummy, isShowingControlButtons: false, forcedOptions: false, enablePadding: false