mirror of https://github.com/buresdv/Cork
Merge branch 'package-installation'
This commit is contained in:
commit
3036a25d19
|
|
@ -25,6 +25,9 @@
|
|||
637E00622872F1AF005C9890 /* Search Result.swift in Sources */ = {isa = PBXBuildFile; fileRef = 637E00612872F1AF005C9890 /* Search Result.swift */; };
|
||||
637E00642872F3CE005C9890 /* Upgrade Packages.swift in Sources */ = {isa = PBXBuildFile; fileRef = 637E00632872F3CE005C9890 /* Upgrade Packages.swift */; };
|
||||
637E00662872F629005C9890 /* Update Progress Tracker.swift in Sources */ = {isa = PBXBuildFile; fileRef = 637E00652872F629005C9890 /* Update Progress Tracker.swift */; };
|
||||
637E006828733C1C005C9890 /* Search for Package by ID.swift in Sources */ = {isa = PBXBuildFile; fileRef = 637E006728733C1C005C9890 /* Search for Package by ID.swift */; };
|
||||
637E006B28734041005C9890 /* Install Selected Packages.swift in Sources */ = {isa = PBXBuildFile; fileRef = 637E006A28734041005C9890 /* Install Selected Packages.swift */; };
|
||||
637E006E2873419B005C9890 /* Install Progress Tracker.swift in Sources */ = {isa = PBXBuildFile; fileRef = 637E006D2873419B005C9890 /* Install Progress Tracker.swift */; };
|
||||
639A7D832871D08200B50280 /* Add Formula.swift in Sources */ = {isa = PBXBuildFile; fileRef = 639A7D822871D08200B50280 /* Add Formula.swift */; };
|
||||
639A7D862871D78C00B50280 /* Package Details.swift in Sources */ = {isa = PBXBuildFile; fileRef = 639A7D852871D78C00B50280 /* Package Details.swift */; };
|
||||
/* End PBXBuildFile section */
|
||||
|
|
@ -49,6 +52,9 @@
|
|||
637E00612872F1AF005C9890 /* Search Result.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Search Result.swift"; sourceTree = "<group>"; };
|
||||
637E00632872F3CE005C9890 /* Upgrade Packages.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Upgrade Packages.swift"; sourceTree = "<group>"; };
|
||||
637E00652872F629005C9890 /* Update Progress Tracker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Update Progress Tracker.swift"; sourceTree = "<group>"; };
|
||||
637E006728733C1C005C9890 /* Search for Package by ID.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Search for Package by ID.swift"; sourceTree = "<group>"; };
|
||||
637E006A28734041005C9890 /* Install Selected Packages.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Install Selected Packages.swift"; sourceTree = "<group>"; };
|
||||
637E006D2873419B005C9890 /* Install Progress Tracker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Install Progress Tracker.swift"; sourceTree = "<group>"; };
|
||||
639A7D822871D08200B50280 /* Add Formula.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Add Formula.swift"; sourceTree = "<group>"; };
|
||||
639A7D852871D78C00B50280 /* Package Details.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Package Details.swift"; sourceTree = "<group>"; };
|
||||
/* End PBXFileReference section */
|
||||
|
|
@ -108,12 +114,14 @@
|
|||
634065762871AB2A001A2178 /* Logic */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
637E006928734032005C9890 /* Installation */,
|
||||
6371EA242871EE6000300E1B /* Shell */,
|
||||
6371EA1F2871E0EC00300E1B /* Helpers */,
|
||||
634065802871B0A3001A2178 /* File Browser */,
|
||||
634065792871AC27001A2178 /* Brew Data Storage.swift */,
|
||||
6371EA2C287202F400300E1B /* Extract from JSON.swift */,
|
||||
637E00632872F3CE005C9890 /* Upgrade Packages.swift */,
|
||||
637E006728733C1C005C9890 /* Search for Package by ID.swift */,
|
||||
);
|
||||
path = Logic;
|
||||
sourceTree = "<group>";
|
||||
|
|
@ -163,11 +171,28 @@
|
|||
path = Shell;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
637E006928734032005C9890 /* Installation */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
637E006A28734041005C9890 /* Install Selected Packages.swift */,
|
||||
);
|
||||
path = Installation;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
637E006C28734189005C9890 /* Installation */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
639A7D822871D08200B50280 /* Add Formula.swift */,
|
||||
637E006D2873419B005C9890 /* Install Progress Tracker.swift */,
|
||||
);
|
||||
path = Installation;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
639A7D812871D07800B50280 /* Views */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
637E006C28734189005C9890 /* Installation */,
|
||||
6371EA1C2871D96800300E1B /* Packages */,
|
||||
639A7D822871D08200B50280 /* Add Formula.swift */,
|
||||
);
|
||||
path = Views;
|
||||
sourceTree = "<group>";
|
||||
|
|
@ -252,6 +277,7 @@
|
|||
634065822871B0BE001A2178 /* Get Contents of Folder.swift in Sources */,
|
||||
639A7D832871D08200B50280 /* Add Formula.swift in Sources */,
|
||||
637E00622872F1AF005C9890 /* Search Result.swift in Sources */,
|
||||
637E006828733C1C005C9890 /* Search for Package by ID.swift in Sources */,
|
||||
6340657A2871AC27001A2178 /* Brew Data Storage.swift in Sources */,
|
||||
6340657F2871AF68001A2178 /* App Constants.swift in Sources */,
|
||||
634065672871AA42001A2178 /* ContentView.swift in Sources */,
|
||||
|
|
@ -259,10 +285,12 @@
|
|||
637E00642872F3CE005C9890 /* Upgrade Packages.swift in Sources */,
|
||||
6371EA2D287202F400300E1B /* Extract from JSON.swift in Sources */,
|
||||
6371EA1E2871D98100300E1B /* Package List Item.swift in Sources */,
|
||||
637E006B28734041005C9890 /* Install Selected Packages.swift in Sources */,
|
||||
634EB3972871C1F00009DFC2 /* Get Package Version.swift in Sources */,
|
||||
6371EA212871E0FE00300E1B /* Return Formatted Versions.swift in Sources */,
|
||||
6371EA232871EE5A00300E1B /* Brew Interface.swift in Sources */,
|
||||
637E00662872F629005C9890 /* Update Progress Tracker.swift in Sources */,
|
||||
637E006E2873419B005C9890 /* Install Progress Tracker.swift in Sources */,
|
||||
639A7D862871D78C00B50280 /* Package Details.swift in Sources */,
|
||||
634065652871AA42001A2178 /* CorkApp.swift in Sources */,
|
||||
);
|
||||
|
|
|
|||
|
|
@ -56,31 +56,27 @@ struct ContentView: View {
|
|||
.collapsible(true)
|
||||
}
|
||||
.listStyle(.bordered)
|
||||
}
|
||||
.toolbar {
|
||||
VStack(alignment: .leading) {
|
||||
Text("Cork")
|
||||
.font(.headline)
|
||||
Text("\(brewData.installedCasks.count + brewData.installedFormulae.count) packages installed")
|
||||
.font(.subheadline)
|
||||
}
|
||||
|
||||
Button {
|
||||
print("Clicked on upgrade")
|
||||
|
||||
upgradeBrewPackages(updateProgressTracker)
|
||||
} label: {
|
||||
Label {
|
||||
Text("Upgrade Formulae")
|
||||
} icon: {
|
||||
Image(systemName: "arrow.clockwise")
|
||||
}
|
||||
.navigationTitle("Cork")
|
||||
.navigationSubtitle("\(brewData.installedCasks.count + brewData.installedFormulae.count) packages installed")
|
||||
.toolbar {
|
||||
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()
|
||||
|
|
@ -102,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()
|
||||
|
|
|
|||
|
|
@ -13,7 +13,9 @@ struct CorkApp: App {
|
|||
WindowGroup {
|
||||
ContentView()
|
||||
}
|
||||
.windowToolbarStyle(UnifiedWindowToolbarStyle(showsTitle: false))
|
||||
.windowStyle(HiddenTitleBarWindowStyle())
|
||||
.windowStyle(.automatic)
|
||||
.windowToolbarStyle(.automatic)
|
||||
//.windowToolbarStyle(UnifiedWindowToolbarStyle(showsTitle: true))
|
||||
//.windowStyle(HiddenTitleBarWindowStyle())
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,33 @@
|
|||
//
|
||||
// Install Selected Packages.swift
|
||||
// Cork
|
||||
//
|
||||
// Created by David Bureš on 04.07.2022.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import SwiftUI
|
||||
|
||||
@MainActor
|
||||
func installSelectedPackages(packageArray: [String], tracker: InstallationProgressTracker) -> Void {
|
||||
let progressSteps: Float = Float(1) / Float(packageArray.count)
|
||||
|
||||
tracker.progressNumber = 0
|
||||
|
||||
for package in packageArray {
|
||||
Task {
|
||||
tracker.packageBeingCurrentlyInstalled = package
|
||||
print(tracker.packageBeingCurrentlyInstalled)
|
||||
|
||||
let installCommandOutput = await shell("/opt/homebrew/bin/brew", ["install", package])
|
||||
|
||||
if installCommandOutput!.contains("was successfully installed") {
|
||||
tracker.progressNumber += progressSteps
|
||||
} else {
|
||||
tracker.isShowingInstallationFailureAlert = true
|
||||
}
|
||||
|
||||
print("Installing \(tracker.packageBeingCurrentlyInstalled) at \(tracker.progressNumber)")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
//
|
||||
// Search for Package by ID.swift
|
||||
// Cork
|
||||
//
|
||||
// Created by David Bureš on 04.07.2022.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
func getPackageNamesFromUUID(selectionBinding: Set<UUID>, tracker: SearchResultTracker) -> [String] {
|
||||
let foundFormulae: [SearchResult] = tracker.foundFormulae
|
||||
let foundCasks: [SearchResult] = tracker.foundCasks
|
||||
|
||||
var resultArray: [String] = [String]()
|
||||
|
||||
for selection in selectionBinding {
|
||||
/// Step 1: Look through formulae
|
||||
for item in foundFormulae {
|
||||
if selection == item.id {
|
||||
resultArray.append(item.packageName)
|
||||
}
|
||||
}
|
||||
|
||||
/// Step 2: Look through casks
|
||||
for item in foundCasks {
|
||||
if selection == item.id {
|
||||
resultArray.append(item.packageName)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return resultArray
|
||||
}
|
||||
|
|
@ -11,6 +11,14 @@ import SwiftUI
|
|||
class SearchResultTracker: ObservableObject {
|
||||
@Published var foundFormulae: [SearchResult] = [SearchResult]()
|
||||
@Published var foundCasks: [SearchResult] = [SearchResult]()
|
||||
@Published var selectedPackagesForInstallation: [String] = [String]()
|
||||
}
|
||||
|
||||
class InstallationProgressTracker: ObservableObject {
|
||||
@Published var progressNumber: Float = 0
|
||||
@Published var packageBeingCurrentlyInstalled: String = ""
|
||||
|
||||
@Published var isShowingInstallationFailureAlert: Bool = false
|
||||
}
|
||||
|
||||
struct AddFormulaView: View {
|
||||
|
|
@ -23,6 +31,7 @@ struct AddFormulaView: View {
|
|||
@State private var foundPackageSelection = Set<UUID>()
|
||||
|
||||
@ObservedObject var searchResultTracker = SearchResultTracker()
|
||||
@ObservedObject var installationProgressTracker = InstallationProgressTracker()
|
||||
|
||||
var body: some View {
|
||||
VStack {
|
||||
|
|
@ -31,17 +40,23 @@ struct AddFormulaView: View {
|
|||
|
||||
if isShowingListLoader {
|
||||
ProgressView()
|
||||
} else if installationProgressTracker.progressNumber != 0 {
|
||||
InstallProgressTrackerView(progress: $installationProgressTracker.progressNumber, currentlyInstallingPackage: $installationProgressTracker.packageBeingCurrentlyInstalled)
|
||||
} else if isShowingResultsList {
|
||||
List(selection: $foundPackageSelection) {
|
||||
Section("Found Formulae") {
|
||||
ForEach(searchResultTracker.foundFormulae) { formula in
|
||||
Text(formula.packageName)
|
||||
if !searchResultTracker.foundFormulae.isEmpty {
|
||||
Section("Found Formulae") {
|
||||
ForEach(searchResultTracker.foundFormulae) { formula in
|
||||
Text(formula.packageName)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Section("Found Casks") {
|
||||
ForEach(searchResultTracker.foundCasks) { cask in
|
||||
Text(cask.packageName)
|
||||
if !searchResultTracker.foundCasks.isEmpty {
|
||||
Section("Found Casks") {
|
||||
ForEach(searchResultTracker.foundCasks) { cask in
|
||||
Text(cask.packageName)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -133,9 +148,12 @@ struct AddFormulaView: View {
|
|||
.keyboardShortcut(.defaultAction)
|
||||
} else {
|
||||
Button {
|
||||
for selection in foundPackageSelection {
|
||||
print(selection)
|
||||
}
|
||||
// TODO: Optimize this
|
||||
searchResultTracker.selectedPackagesForInstallation = [String]()
|
||||
|
||||
installSelectedPackages(packageArray: getPackageNamesFromUUID(selectionBinding: foundPackageSelection, tracker: searchResultTracker), tracker: installationProgressTracker)
|
||||
|
||||
print(searchResultTracker.selectedPackagesForInstallation)
|
||||
} label: {
|
||||
Text("Install")
|
||||
}
|
||||
|
|
@ -146,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")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
//
|
||||
// Install Progress Tracker.swift
|
||||
// Cork
|
||||
//
|
||||
// Created by David Bureš on 04.07.2022.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct InstallProgressTrackerView: View {
|
||||
@Binding var progress: Float
|
||||
@Binding var currentlyInstallingPackage: String
|
||||
|
||||
var body: some View {
|
||||
VStack {
|
||||
ProgressView(value: progress)
|
||||
Text("Installing \(currentlyInstallingPackage)")
|
||||
}
|
||||
.padding()
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue