Confirm before cancelling installation

This commit is contained in:
Brandon Evans 2021-01-07 19:36:54 -07:00
parent 1a830dc9dc
commit 4a33d010a8
No known key found for this signature in database
GPG key ID: D58A4B8DB64F8E93
6 changed files with 32 additions and 7 deletions

View file

@ -30,6 +30,7 @@ class AppState: ObservableObject {
@Published var isProcessingAuthRequest = false
@Published var secondFactorData: SecondFactorData?
@Published var xcodeBeingConfirmedForUninstallation: Xcode?
@Published var xcodeBeingConfirmedForInstallCancellation: Xcode?
@Published var helperInstallState: HelperInstallState = .notInstalled
// MARK: - Errors

View file

@ -39,6 +39,12 @@ struct Xcode: Identifiable, CustomStringConvertible {
var id: Version { version }
var installed: Bool { installState == .installed }
var installing: Bool {
switch installState {
case .installing: return true
default: return false
}
}
var description: String {
version.xcodeDescription

View file

@ -55,13 +55,13 @@ struct CancelInstallButton: View {
var body: some View {
Button(action: cancelInstall) {
Text("Cancel")
.help("Cancel installation")
.help("Stop installation")
}
}
private func cancelInstall() {
guard let xcode = xcode else { return }
appState.cancelInstall(id: xcode.id)
appState.xcodeBeingConfirmedForInstallCancellation = xcode
}
}
@ -160,9 +160,14 @@ struct InstallCommand: View {
@FocusedValue(\.selectedXcode) private var selectedXcode: SelectedXcode?
var body: some View {
InstallButton(xcode: selectedXcode.unwrapped)
.keyboardShortcut("i", modifiers: [.command, .option])
.disabled(selectedXcode.unwrapped?.installed == true)
if selectedXcode.unwrapped?.installing == true {
CancelInstallButton(xcode: selectedXcode.unwrapped)
.keyboardShortcut(".", modifiers: [.command])
} else {
InstallButton(xcode: selectedXcode.unwrapped)
.keyboardShortcut("i", modifiers: [.command, .option])
.disabled(selectedXcode.unwrapped?.installState != .notInstalled)
}
}
}

View file

@ -24,6 +24,15 @@ struct MainWindow: View {
.frame(minWidth: 300, maxWidth: .infinity)
.frame(width: isShowingInfoPane ? nil : 0)
.isHidden(!isShowingInfoPane)
// This alert isn't intentionally placed here,
// just trying to put it in a unique part of the hierarchy
// since you can't have more than one in the same spot.
.alert(item: $appState.xcodeBeingConfirmedForInstallCancellation) { xcode in
Alert(title: Text("Are you sure you want to stop the installation of Xcode \(xcode.description)?"),
message: Text("Any progress will be discarded."),
primaryButton: .destructive(Text("Stop Installation"), action: { self.appState.cancelInstall(id: xcode.id) }),
secondaryButton: .cancel(Text("Cancel")))
}
}
.mainToolbar(
category: $category,

View file

@ -31,7 +31,7 @@ struct InstallationStepView: View {
}
.buttonStyle(PlainButtonStyle())
.foregroundColor(highlighted ? .white : .secondary)
.help("Cancel installation")
.help("Stop installation")
}
.frame(minWidth: 80)
}

View file

@ -85,7 +85,11 @@ struct XcodeListViewRow: View {
.buttonStyle(AppStoreButtonStyle(primary: false, highlighted: selected))
.help("Install this version")
case let .installing(installationStep):
InstallationStepView(installationStep: installationStep, highlighted: selected, cancel: { appState.cancelInstall(id: xcode.id) })
InstallationStepView(
installationStep: installationStep,
highlighted: selected,
cancel: { appState.xcodeBeingConfirmedForInstallCancellation = xcode }
)
}
}
}