PR Cleanup

This commit is contained in:
Matt Kiazyk 2020-12-31 16:06:03 -06:00
parent 7bfb94d75a
commit 72bdadb796
No known key found for this signature in database
GPG key ID: 967DBC53389132D7
5 changed files with 41 additions and 53 deletions

View file

@ -4,7 +4,7 @@ import Combine
import Path import Path
import LegibleError import LegibleError
import KeychainAccess import KeychainAccess
import SwiftUI import Path
import Version import Version
class AppState: ObservableObject { class AppState: ObservableObject {
@ -33,6 +33,7 @@ class AppState: ObservableObject {
@Published var presentingSignInAlert = false @Published var presentingSignInAlert = false
@Published var isProcessingAuthRequest = false @Published var isProcessingAuthRequest = false
@Published var secondFactorData: SecondFactorData? @Published var secondFactorData: SecondFactorData?
@Published var xcodeBeingConfirmedForUninstallation: Xcode?
@Published var helperInstallState: HelperInstallState = .notInstalled @Published var helperInstallState: HelperInstallState = .notInstalled
init() { init() {
@ -217,7 +218,7 @@ class AppState: ObservableObject {
uninstallPublisher == nil uninstallPublisher == nil
else { return } else { return }
uninstallPublisher = HelperClient().uninstallXcode(installedXcode.path) uninstallPublisher = uninstallXcode(path: installedXcode.path)
.flatMap { [unowned self] _ in .flatMap { [unowned self] _ in
self.updateSelectedXcodePath() self.updateSelectedXcodePath()
} }
@ -315,6 +316,29 @@ class AppState: ObservableObject {
} }
} }
private func uninstallXcode(path: Path) -> AnyPublisher<Void, Error> {
let connectionErrorSubject = PassthroughSubject<String, Error>()
return Deferred {
Future { promise in
do {
try Current.files.trashItem(at: path.url)
promise(.success(()))
} catch {
promise(.failure(error))
}
}
}
// Take values, but fail when connectionErrorSubject fails
.zip(
connectionErrorSubject
.prepend("")
.map { _ in Void() }
)
.map { $0.0 }
.eraseToAnyPublisher()
}
// MARK: - Nested Types // MARK: - Nested Types

View file

@ -1,6 +1,5 @@
import Combine import Combine
import Foundation import Foundation
import Path
final class HelperClient { final class HelperClient {
private var connection: NSXPCConnection? private var connection: NSXPCConnection?
@ -104,27 +103,4 @@ final class HelperClient {
.map { $0.0 } .map { $0.0 }
.eraseToAnyPublisher() .eraseToAnyPublisher()
} }
func uninstallXcode(_ path: Path) -> AnyPublisher<Void, Error> {
let connectionErrorSubject = PassthroughSubject<String, Error>()
return Deferred {
Future { promise in
do {
try Current.files.trashItem(at: path.url)
promise(.success(()))
} catch {
promise(.failure(error))
}
}
}
// Take values, but fail when connectionErrorSubject fails
.zip(
connectionErrorSubject
.prepend("")
.map { _ in Void() }
)
.map { $0.0 }
.eraseToAnyPublisher()
}
} }

View file

@ -18,6 +18,9 @@ struct XcodeCommands: Commands {
OpenCommand() OpenCommand()
RevealCommand() RevealCommand()
CopyPathCommand() CopyPathCommand()
Divider()
UninstallCommand() UninstallCommand()
} }
.environmentObject(appState) .environmentObject(appState)
@ -88,23 +91,14 @@ struct UninstallButton: View {
@EnvironmentObject var appState: AppState @EnvironmentObject var appState: AppState
let xcode: Xcode? let xcode: Xcode?
@State private var showingAlert = false
var alert: Alert {
Alert(title: Text("Uninstall Xcode \(xcode!.description)?"),
message: Text("It will be moved to the Trash, but won't be emptied."),
primaryButton: .destructive(Text("Uninstall"), action: { self.appState.uninstall(id: xcode!.id) }),
secondaryButton: .cancel(Text("Cancel")))
}
var body: some View { var body: some View {
Button(action: { Button(action: {
self.showingAlert = true appState.xcodeBeingConfirmedForUninstallation = xcode
}) { }) {
Text("Uninstall") Text("Uninstall")
} }
.foregroundColor(.red) .foregroundColor(.red)
.help("Uninstall") .help("Uninstall")
.alert(isPresented:$showingAlert, content: { self.alert })
} }
} }

View file

@ -7,13 +7,18 @@ struct MainWindow: View {
@AppStorage("lastUpdated") private var lastUpdated: Double? @AppStorage("lastUpdated") private var lastUpdated: Double?
@SceneStorage("isShowingInfoPane") private var isShowingInfoPane = false @SceneStorage("isShowingInfoPane") private var isShowingInfoPane = false
@SceneStorage("xcodeListCategory") private var category: XcodeListCategory = .all @SceneStorage("xcodeListCategory") private var category: XcodeListCategory = .all
var body: some View { var body: some View {
HSplitView { HSplitView {
XcodeListView(selectedXcodeID: $selectedXcodeID, searchText: searchText, category: category) XcodeListView(selectedXcodeID: $selectedXcodeID, searchText: searchText, category: category)
.frame(minWidth: 300) .frame(minWidth: 300)
.layoutPriority(1) .layoutPriority(1)
.alert(item: $appState.xcodeBeingConfirmedForUninstallation) { xcode in
Alert(title: Text("Uninstall Xcode \(xcode.description)?"),
message: Text("It will be moved to the Trash, but won't be emptied."),
primaryButton: .destructive(Text("Uninstall"), action: { self.appState.uninstall(id: xcode.id) }),
secondaryButton: .cancel(Text("Cancel")))
}
InfoPane(selectedXcodeID: selectedXcodeID) InfoPane(selectedXcodeID: selectedXcodeID)
.frame(minWidth: 300, maxWidth: .infinity) .frame(minWidth: 300, maxWidth: .infinity)
.frame(width: isShowingInfoPane ? nil : 0) .frame(width: isShowingInfoPane ? nil : 0)
@ -31,15 +36,6 @@ struct MainWindow: View {
message: Text(verbatim: error.message), message: Text(verbatim: error.message),
dismissButton: .default(Text("OK"))) dismissButton: .default(Text("OK")))
} }
/*
Removing this for now, because it's overriding the error alert that's being worked on above.
.alert(item: $appState.xcodeBeingConfirmedForUninstallation) { xcode in
Alert(title: Text("Uninstall Xcode \(xcode.description)?"),
message: Text("It will be moved to the Trash, but won't be emptied."),
primaryButton: .destructive(Text("Uninstall"), action: { self.appState.uninstall(id: xcode.id) }),
secondaryButton: .cancel(Text("Cancel")))
}
**/
.sheet(isPresented: $appState.secondFactorData.isNotNil) { .sheet(isPresented: $appState.secondFactorData.isNotNil) {
secondFactorView(appState.secondFactorData!) secondFactorView(appState.secondFactorData!)
.environmentObject(appState) .environmentObject(appState)

View file

@ -37,6 +37,9 @@ struct InfoPane: View {
OpenButton(xcode: xcode) OpenButton(xcode: xcode)
.help("Open") .help("Open")
Spacer()
UninstallButton(xcode: xcode)
} }
} else { } else {
InstallButton(xcode: xcode) InstallButton(xcode: xcode)
@ -49,12 +52,7 @@ struct InfoPane: View {
compatibility(for: xcode) compatibility(for: xcode)
sdks(for: xcode) sdks(for: xcode)
compilers(for: xcode) compilers(for: xcode)
if xcode.path != nil {
VStack(alignment: .leading) {
UninstallButton(xcode: xcode)
}
}
Spacer() Spacer()
} }
} else { } else {