Skip to content

Commit

Permalink
+ First broken implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
buresdv committed Nov 10, 2024
1 parent ad904d7 commit 706c4db
Show file tree
Hide file tree
Showing 4 changed files with 122 additions and 100 deletions.
102 changes: 61 additions & 41 deletions Cork/Views/Maintenance/Maintenance View.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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
{
Expand Down Expand Up @@ -111,7 +111,7 @@ struct MaintenanceRunningView: View
AppConstants.shared.logger.info("Will not perform health check")
}

maintenanceSteps = .finished
navigationManager.navigate(to: .finished)
}
}
.padding()
Expand Down
113 changes: 59 additions & 54 deletions Cork/Views/Maintenance/Sub-Views/Ready View.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
3 changes: 0 additions & 3 deletions Cork/Views/Settings/Panes/Maintenance Pane.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -29,7 +27,6 @@ struct MaintenancePane: View
shouldPurgeCache: $default_shouldPurgeCache,
shouldDeleteDownloads: $default_shouldDeleteDownloads,
shouldPerformHealthCheck: $default_shouldPerformHealthCheck,
maintenanceSteps: $maintenanceStepsDummy,
isShowingControlButtons: false,
forcedOptions: false,
enablePadding: false
Expand Down

0 comments on commit 706c4db

Please sign in to comment.