mirror of https://github.com/buresdv/Cork
Added updating and upgrading
This commit is contained in:
parent
35eb111bff
commit
0160e43302
|
|
@ -24,6 +24,7 @@
|
|||
6371EA2D287202F400300E1B /* Extract from JSON.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6371EA2C287202F400300E1B /* Extract from JSON.swift */; };
|
||||
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 */; };
|
||||
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 */
|
||||
|
|
@ -47,6 +48,7 @@
|
|||
6371EA2C287202F400300E1B /* Extract from JSON.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Extract from JSON.swift"; sourceTree = "<group>"; };
|
||||
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>"; };
|
||||
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 */
|
||||
|
|
@ -121,6 +123,7 @@
|
|||
children = (
|
||||
6340657C2871AC65001A2178 /* Brew Package.swift */,
|
||||
637E00612872F1AF005C9890 /* Search Result.swift */,
|
||||
637E00652872F629005C9890 /* Update Progress Tracker.swift */,
|
||||
);
|
||||
path = Models;
|
||||
sourceTree = "<group>";
|
||||
|
|
@ -259,6 +262,7 @@
|
|||
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 */,
|
||||
639A7D862871D78C00B50280 /* Package Details.swift in Sources */,
|
||||
634065652871AA42001A2178 /* CorkApp.swift in Sources */,
|
||||
);
|
||||
|
|
|
|||
|
|
@ -8,9 +8,9 @@
|
|||
import SwiftUI
|
||||
|
||||
struct ContentView: View {
|
||||
|
||||
@StateObject var brewData = BrewDataStorage()
|
||||
@StateObject var selectedPackageInfo = SelectedPackageInfo()
|
||||
@StateObject var updateProgressTracker = UpdateProgressTracker()
|
||||
|
||||
@State private var multiSelection = Set<UUID>()
|
||||
|
||||
|
|
@ -67,11 +67,8 @@ struct ContentView: View {
|
|||
|
||||
Button {
|
||||
print("Clicked on upgrade")
|
||||
do {
|
||||
try upgradeBrewPackages()
|
||||
} catch let error as NSError {
|
||||
print("Failed while upgrading packages: \(error)")
|
||||
}
|
||||
|
||||
upgradeBrewPackages(updateProgressTracker)
|
||||
} label: {
|
||||
Label {
|
||||
Text("Upgrade Formulae")
|
||||
|
|
@ -123,14 +120,6 @@ struct ContentView: View {
|
|||
.padding()
|
||||
.environmentObject(brewData)
|
||||
.onAppear {
|
||||
|
||||
Task {
|
||||
print("Started Command task at \(Date())")
|
||||
|
||||
let commandResult = await shell("/opt/homebrew/bin/brew", ["search", "gimp"])
|
||||
print(commandResult)
|
||||
}
|
||||
|
||||
Task { // Task that gets the contents of the Cellar folder
|
||||
print("Started Cellar task at \(Date())")
|
||||
let contentsOfCellarFolder = await getContentsOfFolder(targetFolder: AppConstantsLocal.brewCellarPath)
|
||||
|
|
@ -158,5 +147,13 @@ struct ContentView: View {
|
|||
.sheet(isPresented: $isShowingInstallSheet) {
|
||||
AddFormulaView(isShowingSheet: $isShowingInstallSheet)
|
||||
}
|
||||
.sheet(isPresented: $updateProgressTracker.showUpdateSheet) {
|
||||
VStack {
|
||||
ProgressView(value: updateProgressTracker.updateProgress)
|
||||
.frame(width: 200)
|
||||
Text(updateProgressTracker.updateStage.rawValue)
|
||||
}
|
||||
.padding()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ enum WhatToExtract: String {
|
|||
|
||||
func extractPackageInfo(rawJSON: String, whatToExtract: WhatToExtract) -> String {
|
||||
let regex = "(?<=\(whatToExtract.rawValue)\": \").*?(?=\")"
|
||||
guard let matchedRange = rawJSON.range(of: regex, options: .regularExpression) else { return "" }
|
||||
guard let matchedRange = rawJSON.range(of: regex, options: .regularExpression) else { return "ERROR" }
|
||||
let matchedString: String = String(rawJSON[matchedRange])
|
||||
|
||||
return matchedString
|
||||
|
|
|
|||
|
|
@ -6,7 +6,21 @@
|
|||
//
|
||||
|
||||
import Foundation
|
||||
import SwiftUI
|
||||
|
||||
func upgradeBrewPackages() throws -> Void {
|
||||
|
||||
@MainActor
|
||||
func upgradeBrewPackages(_ updateProgressTracker: UpdateProgressTracker) -> Void {
|
||||
Task {
|
||||
updateProgressTracker.updateProgress = 0
|
||||
|
||||
updateProgressTracker.showUpdateSheet = true
|
||||
updateProgressTracker.updateStage = .updating
|
||||
let updateResult = await shell("/opt/homebrew/bin/brew", ["update"])!
|
||||
updateProgressTracker.updateProgress += 0.5
|
||||
|
||||
updateProgressTracker.updateStage = .upgrading
|
||||
let upgradeResult = await shell("/opt/homebrew/bin/brew", ["upgrade"])!
|
||||
updateProgressTracker.updateProgress += 0.5
|
||||
updateProgressTracker.showUpdateSheet = false
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue