Skip to content

Commit eb37665

Browse files
committed
~ More rewrites * Maintenance doesn't work
1 parent d3ad29b commit eb37665

File tree

8 files changed

+98
-82
lines changed

8 files changed

+98
-82
lines changed

Cork/ContentView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ private extension View
447447
case false:
448448
MaintenanceView()
449449
case true:
450-
MaintenanceView(shouldPurgeCache: false, shouldUninstallOrphans: false, shouldPerformHealthCheck: false, forcedOptions: true)
450+
MaintenanceView(forcedOptions: true)
451451
}
452452
}
453453
}

Cork/Localizable.xcstrings

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39257,6 +39257,22 @@
3925739257
}
3925839258
}
3925939259
},
39260+
"maintenance.results.health-check.problems.show-list" : {
39261+
"comment" : "A button to show a list of health check problems.",
39262+
"isCommentAutoGenerated" : true,
39263+
"localizations" : {
39264+
"en" : {
39265+
"stringUnit" : {
39266+
"state" : "translated",
39267+
"value" : "Show problems"
39268+
}
39269+
}
39270+
}
39271+
},
39272+
"maintenance.results.orphans-count-%@" : {
39273+
"comment" : "A label that describes the number of orphaned packages. The argument is the number of orphaned packages.",
39274+
"isCommentAutoGenerated" : true
39275+
},
3926039276
"maintenance.results.orphans-count-%lld" : {
3926139277
"extractionState" : "manual",
3926239278
"localizations" : {

Cork/Views/Maintenance/Maintenance View.swift

Lines changed: 48 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -51,17 +51,23 @@ struct MaintenanceView: View
5151
case problemsFound(problems: [String])
5252
}
5353

54+
@Observable
55+
class SelectedMaintenanceStepsTracker
56+
{
57+
var shouldPurgeCache: Bool = true
58+
var shouldDeleteDownloads: Bool = true
59+
var shouldUninstallOrphans: Bool = true
60+
var shouldPerformHealthCheck: Bool = false
61+
}
62+
5463
@Environment(\.dismiss) var dismiss: DismissAction
5564

5665
@Environment(BrewPackagesTracker.self) var brewPackagesTracker: BrewPackagesTracker
5766
@InjectedObservable(\.appState) var appState: AppState
5867

5968
@State var maintenanceSteps: MaintenanceStage = .ready
6069

61-
@State var shouldPurgeCache: Bool = true
62-
@State var shouldDeleteDownloads: Bool = true
63-
@State var shouldUninstallOrphans: Bool = true
64-
@State var shouldPerformHealthCheck: Bool = false
70+
@State private var selectedMaintenanceStepsTracker: SelectedMaintenanceStepsTracker = .init()
6571

6672
@State var numberOfOrphansRemoved: Int = 0
6773

@@ -107,60 +113,53 @@ struct MaintenanceView: View
107113
{
108114
SheetTemplate(isShowingTitle: maintenanceSteps.shouldShowTitle)
109115
{
110-
Group
111-
{
112-
switch maintenanceSteps
116+
maintenanceStepsViews
117+
.navigationTitle(sheetTitle)
118+
.toolbar
113119
{
114-
case .ready:
115-
MaintenanceReadyView(
116-
shouldUninstallOrphans: $shouldUninstallOrphans,
117-
shouldPurgeCache: $shouldPurgeCache,
118-
shouldDeleteDownloads: $shouldDeleteDownloads,
119-
shouldPerformHealthCheck: $shouldPerformHealthCheck,
120-
maintenanceSteps: $maintenanceSteps,
121-
isShowingControlButtons: true,
122-
forcedOptions: forcedOptions!
123-
)
124-
125-
case .maintenanceRunning:
126-
MaintenanceRunningView(
127-
shouldUninstallOrphans: shouldUninstallOrphans,
128-
shouldPurgeCache: shouldPurgeCache,
129-
shouldDeleteDownloads: shouldDeleteDownloads,
130-
shouldPerformHealthCheck: shouldPerformHealthCheck,
131-
numberOfOrphansRemoved: $numberOfOrphansRemoved,
132-
packagesHoldingBackCachePurge: $packagesHoldingBackCachePurge,
133-
reclaimedSpaceAfterCachePurge: $reclaimedSpaceAfterCachePurge,
134-
healthCheckStatus: $brewHealthCheckStatus,
135-
maintenanceSteps: $maintenanceSteps
136-
)
137-
138-
case .finished(let results):
139-
MaintenanceFinishedView(
140-
maintenanceResults: results
141-
)
142-
}
143-
}
144-
.navigationTitle(sheetTitle)
145-
.toolbar
146-
{
147-
if maintenanceSteps.isDismissable
148-
{
149-
ToolbarItem(placement: .cancellationAction)
120+
if maintenanceSteps.isDismissable
150121
{
151-
Button
122+
ToolbarItem(placement: .cancellationAction)
152123
{
153-
dismiss()
154-
} label: {
155-
Text(dismissButtonTitle)
124+
Button
125+
{
126+
dismiss()
127+
} label: {
128+
Text(dismissButtonTitle)
129+
}
130+
.keyboardShortcut(.cancelAction)
156131
}
157-
.keyboardShortcut(.cancelAction)
158132
}
159133
}
160-
}
161134
}
162135
}
163136
}
137+
138+
@ViewBuilder
139+
var maintenanceStepsViews: some View
140+
{
141+
switch maintenanceSteps
142+
{
143+
case .ready:
144+
MaintenanceReadyView(
145+
selectedMaintenanceStepsTracker: selectedMaintenanceStepsTracker,
146+
maintenanceSteps: $maintenanceSteps,
147+
isShowingControlButtons: true,
148+
forcedOptions: forcedOptions!
149+
)
150+
151+
case .maintenanceRunning:
152+
MaintenanceRunningView(
153+
maintenanceSteps: $maintenanceSteps,
154+
selectedMaintenanceStepsTracker: selectedMaintenanceStepsTracker
155+
)
156+
157+
case .finished(let results):
158+
MaintenanceFinishedView(
159+
maintenanceResults: results
160+
)
161+
}
162+
}
164163
}
165164

166165
extension MaintenanceView

Cork/Views/Maintenance/Sub-Views/Maintenance Finished View.swift

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,11 +189,20 @@ struct MaintenanceFinishedView: View
189189
.lineLimit(nil)
190190
.fixedSize(horizontal: false, vertical: true)
191191
case .problemsFound(let problems):
192-
HStack
192+
VStack
193193
{
194194
Text("maintenance.results.health-check.problems")
195195
.lineLimit(nil)
196196
.fixedSize(horizontal: false, vertical: true)
197+
198+
DisclosureGroup {
199+
List(problems, id: \.self) { problem in
200+
Text(problem)
201+
}
202+
} label: {
203+
Text("maintenance.results.health-check.problems.show-list")
204+
}
205+
197206
}
198207
}
199208
}

Cork/Views/Maintenance/Sub-Views/Maintenance Running View.swift

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,7 @@ struct MaintenanceRunningView: View
2222

2323
@Binding var maintenanceSteps: MaintenanceView.MaintenanceStage
2424

25-
let shouldUninstallOrphans: Bool
26-
let shouldPurgeCache: Bool
27-
let shouldDeleteDownloads: Bool
28-
let shouldPerformHealthCheck: Bool
25+
let selectedMaintenanceStepsTracker: MaintenanceView.SelectedMaintenanceStepsTracker
2926

3027
@State private var cachePurgeResults: MaintenanceResults.CachePurgeResults?
3128
@State private var orphanRemovalResults: MaintenanceResults.OrphanRemovalResults?
@@ -38,14 +35,14 @@ struct MaintenanceRunningView: View
3835
Text(currentMaintenanceStepText)
3936
.task
4037
{
41-
38+
await performMaintenance()
4239
}
4340
}
4441
}
4542

4643
func performMaintenance() async
4744
{
48-
if shouldUninstallOrphans
45+
if selectedMaintenanceStepsTracker.shouldUninstallOrphans
4946
{
5047
currentMaintenanceStepText = "maintenance.step.removing-orphans"
5148

@@ -63,7 +60,7 @@ struct MaintenanceRunningView: View
6360
AppConstants.shared.logger.info("Will not uninstall orphans")
6461
}
6562

66-
if shouldPurgeCache
63+
if selectedMaintenanceStepsTracker.shouldPurgeCache
6764
{
6865
currentMaintenanceStepText = "maintenance.step.purging-cache"
6966

@@ -92,7 +89,7 @@ struct MaintenanceRunningView: View
9289
AppConstants.shared.logger.info("Will not purge cache")
9390
}
9491

95-
if shouldDeleteDownloads
92+
if selectedMaintenanceStepsTracker.shouldDeleteDownloads
9693
{
9794
AppConstants.shared.logger.info("Will delete downloads")
9895

@@ -123,7 +120,7 @@ struct MaintenanceRunningView: View
123120
AppConstants.shared.logger.info("Will not delete downloads")
124121
}
125122

126-
if shouldPerformHealthCheck
123+
if selectedMaintenanceStepsTracker.shouldPerformHealthCheck
127124
{
128125
currentMaintenanceStepText = "maintenance.step.running-health-check"
129126

Cork/Views/Maintenance/Sub-Views/Ready View.swift

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,7 @@ struct MaintenanceReadyView: View
1616
@Default(.default_shouldDeleteDownloads) var default_shouldDeleteDownloads: Bool
1717
@Default(.default_shouldPerformHealthCheck) var default_shouldPerformHealthCheck: Bool
1818

19-
@Binding var shouldUninstallOrphans: Bool
20-
@Binding var shouldPurgeCache: Bool
21-
@Binding var shouldDeleteDownloads: Bool
22-
@Binding var shouldPerformHealthCheck: Bool
19+
@Bindable var selectedMaintenanceStepsTracker: MaintenanceView.SelectedMaintenanceStepsTracker
2320

2421
@Binding var maintenanceSteps: MaintenanceView.MaintenanceStage
2522

@@ -39,7 +36,7 @@ struct MaintenanceReadyView: View
3936
{
4037
VStack(alignment: .leading)
4138
{
42-
Toggle(isOn: $shouldUninstallOrphans)
39+
Toggle(isOn: $selectedMaintenanceStepsTracker.shouldUninstallOrphans)
4340
{
4441
Text("maintenance.steps.packages.uninstall-orphans")
4542
}
@@ -50,11 +47,11 @@ struct MaintenanceReadyView: View
5047
{
5148
VStack(alignment: .leading)
5249
{
53-
Toggle(isOn: $shouldPurgeCache)
50+
Toggle(isOn: $selectedMaintenanceStepsTracker.shouldPurgeCache)
5451
{
5552
Text("maintenance.steps.downloads.purge-cache")
5653
}
57-
Toggle(isOn: $shouldDeleteDownloads)
54+
Toggle(isOn: $selectedMaintenanceStepsTracker.shouldDeleteDownloads)
5855
{
5956
Text("maintenance.steps.downloads.delete-cached-downloads")
6057
}
@@ -63,7 +60,7 @@ struct MaintenanceReadyView: View
6360

6461
LabeledContent("maintenance.steps.other")
6562
{
66-
Toggle(isOn: $shouldPerformHealthCheck)
63+
Toggle(isOn: $selectedMaintenanceStepsTracker.shouldPerformHealthCheck)
6764
{
6865
Text("maintenance.steps.other.health-check")
6966
}
@@ -85,7 +82,7 @@ struct MaintenanceReadyView: View
8582
Text("maintenance.steps.start")
8683
}
8784
.keyboardShortcut(.defaultAction)
88-
.disabled(isStartDisabled)
85+
//.disabled(isStartDisabled)
8986
}
9087
}
9188
}
@@ -95,19 +92,21 @@ struct MaintenanceReadyView: View
9592
{
9693
/// Replace the provided values with those from AppStorage
9794
/// I have to do this because I don't want the settings in the sheet itself to affect those in the defaults
98-
shouldUninstallOrphans = default_shouldUninstallOrphans
99-
shouldPurgeCache = default_shouldPurgeCache
100-
shouldDeleteDownloads = default_shouldDeleteDownloads
101-
shouldPerformHealthCheck = default_shouldPerformHealthCheck
95+
selectedMaintenanceStepsTracker.shouldUninstallOrphans = default_shouldUninstallOrphans
96+
selectedMaintenanceStepsTracker.shouldPurgeCache = default_shouldPurgeCache
97+
selectedMaintenanceStepsTracker.shouldDeleteDownloads = default_shouldDeleteDownloads
98+
selectedMaintenanceStepsTracker.shouldPerformHealthCheck = default_shouldPerformHealthCheck
10299
}
103100
}
104101
}
105102

103+
/*
106104
private var isStartDisabled: Bool
107105
{
108106
[shouldUninstallOrphans, shouldPurgeCache, shouldDeleteDownloads, shouldPerformHealthCheck].allSatisfy
109107
{
110108
!$0
111109
}
112110
}
111+
*/
113112
}

Cork/Views/Reusables/Sheets/Sheet Template.swift

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,11 @@ struct SheetTemplate<Content: View>: View
1111
{
1212
var isShowingTitle: Bool
1313

14-
// Store a closure that builds the content rather than a stored @ViewBuilder property
15-
private let content: () -> Content
16-
17-
// Provide a @ViewBuilder initializer so call sites can pass trailing closure content naturally
18-
init(isShowingTitle: Bool, @ViewBuilder content: @escaping () -> Content) {
19-
self.isShowingTitle = isShowingTitle
20-
self.content = content
21-
}
14+
@ViewBuilder var sheetContent: Content
2215

2316
var body: some View
2417
{
25-
content()
18+
sheetContent
2619
.toolbar(.hidden, for: isShowingTitle ? .automatic : .windowToolbar)
2720
.padding()
2821
.frame(minWidth: 300)

Cork/Views/Settings/Panes/Maintenance Pane.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ struct MaintenancePane: View
2121
{
2222
SettingsPaneTemplate
2323
{
24+
EmptyView()
25+
/*
2426
VStack(alignment: .leading, spacing: 10)
2527
{
2628
Text("settings.maintenance.default-steps")
@@ -36,6 +38,7 @@ struct MaintenancePane: View
3638
enablePadding: false
3739
)
3840
}
41+
*/
3942
}
4043
}
4144
}

0 commit comments

Comments
 (0)