Installation works, but the tracker is still a bit fucky

This commit is contained in:
David Bureš 2022-07-07 17:26:00 +02:00 committed by David Bureš
parent 6d4585f0f1
commit 3a601142c7
3 changed files with 45 additions and 27 deletions

View File

@ -56,26 +56,27 @@ struct ContentView: View {
.collapsible(true)
}
.listStyle(.bordered)
}
.navigationTitle("Cork")
.navigationSubtitle("\(brewData.installedCasks.count + brewData.installedFormulae.count) packages installed")
.toolbar {
Button {
print("Clicked on upgrade")
upgradeBrewPackages(updateProgressTracker)
} label: {
Label {
Text("Upgrade Formulae")
} icon: {
Image(systemName: "arrow.clockwise")
ToolbarItemGroup(placement: .primaryAction) {
Button {
print("Clicked on upgrade")
upgradeBrewPackages(updateProgressTracker)
} label: {
Label {
Text("Upgrade Formulae")
} icon: {
Image(systemName: "arrow.clockwise")
}
}
}
Spacer()
if !multiSelection.isEmpty { // If the user selected a package, show a button to uninstall it
ToolbarItemGroup(placement: .destructiveAction) {
if !multiSelection.isEmpty { // If the user selected a package, show a button to uninstall it
Button {
print("Clicked Delete")
isShowingAlert.toggle()
@ -97,19 +98,20 @@ struct ContentView: View {
Text("Deleting a formula will completely remove it from your Mac. You will have to reinstall the formula if you want to use it again.")
Text("This action cannot be undone.")
}
}
Button {
isShowingInstallSheet.toggle()
} label: {
Label {
Text("Add Formula")
} icon: {
Image(systemName: "plus")
}
}
ToolbarItemGroup(placement: .primaryAction) {
Button {
isShowingInstallSheet.toggle()
} label: {
Label {
Text("Add Formula")
} icon: {
Image(systemName: "plus")
}
}
}
}
}
.padding()

View File

@ -6,6 +6,7 @@
//
import Foundation
import SwiftUI
@MainActor
func installSelectedPackages(packageArray: [String], tracker: InstallationProgressTracker) -> Void {
@ -18,9 +19,14 @@ func installSelectedPackages(packageArray: [String], tracker: InstallationProgre
tracker.packageBeingCurrentlyInstalled = package
print(tracker.packageBeingCurrentlyInstalled)
await shell("/opt/homebrew/bin/brew", ["install", package])
let installCommandOutput = await shell("/opt/homebrew/bin/brew", ["install", package])
tracker.progressNumber += progressSteps
if installCommandOutput!.contains("was successfully installed") {
tracker.progressNumber += progressSteps
} else {
tracker.isShowingInstallationFailureAlert = true
}
print("Installing \(tracker.packageBeingCurrentlyInstalled) at \(tracker.progressNumber)")
}
}

View File

@ -17,6 +17,8 @@ class SearchResultTracker: ObservableObject {
class InstallationProgressTracker: ObservableObject {
@Published var progressNumber: Float = 0
@Published var packageBeingCurrentlyInstalled: String = ""
@Published var isShowingInstallationFailureAlert: Bool = false
}
struct AddFormulaView: View {
@ -162,5 +164,13 @@ struct AddFormulaView: View {
}
.padding(.vertical)
.frame(width: 300)
.alert("Error installing package", isPresented: $installationProgressTracker.isShowingInstallationFailureAlert) {
Button("Close", role: .cancel) {
installationProgressTracker.isShowingInstallationFailureAlert = false
}
} message: {
Text("An error occured while installing one of the selected packages.")
Text("Please try again in a feww minutes")
}
}
}