Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Xcodes/Backend/AppState+Runtimes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -510,9 +510,9 @@ extension AppState {

/// Uninstalls an Xcode, then removes the given simulator runtimes.
@discardableResult
func uninstall(xcode: Xcode, removingRuntimes runtimes: [DownloadableRuntime]) -> Task<Void, Never>? {
func uninstall(xcode: Xcode, permanently: Bool = false, removingRuntimes runtimes: [DownloadableRuntime]) -> Task<Void, Never>? {
guard let installedPath = xcode.installedPath else { return nil }
uninstall(xcode: xcode)
uninstall(xcode: xcode, permanently: permanently)
guard !runtimes.isEmpty, let removalTask = uninstallTask else { return uninstallTask }
return Task { @MainActor [weak self] in
await removalTask.value
Expand Down
22 changes: 12 additions & 10 deletions Xcodes/Backend/AppState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -780,14 +780,13 @@ class AppState: ObservableObject {
}

// MARK: - Uninstall
func uninstall(xcode: Xcode) {
func uninstall(xcode: Xcode, permanently: Bool = false) {
guard let installedXcodePath = xcode.installedPath else { return }

if let index = allXcodes.firstIndex(where: { $0.id == xcode.id }) {
allXcodes[index].installState = .uninstalling(installedXcodePath)
}

uninstallTask?.cancel()
let taskID = UUID()
uninstallTaskID = taskID
uninstallTask = Task { @MainActor in
Expand All @@ -799,7 +798,7 @@ class AppState: ObservableObject {
}
do {
try Task.checkCancellation()
try await uninstallXcodeAsync(path: installedXcodePath)
try await uninstallXcodeAsync(path: installedXcodePath, permanently: permanently)
try Task.checkCancellation()
await updateInstalledXcodesAsync()
await updateSelectedXcodePathAsync()
Expand All @@ -808,7 +807,7 @@ class AppState: ObservableObject {
if let index = allXcodes.firstIndex(where: { $0.id == xcode.id }) {
allXcodes[index].installState = .installed(installedXcodePath)
}
if Current.helper.usePrivilegedHelperForFileOperations && !(error is FileError) {
if permanently && Current.helper.usePrivilegedHelperForFileOperations && !(error is FileError) {
presentHelperRecovery(title: localizeString("Alert.Uninstall.Error.Title"), error: error, command: "sudo /bin/rm -rf " + HelperRecovery.quote(installedXcodePath.string))
} else {
self.error = error
Expand Down Expand Up @@ -1057,7 +1056,7 @@ class AppState: ObservableObject {

// MARK: - Private

private func uninstallXcodeAsync(path: Path) async throws {
private func uninstallXcodeAsync(path: Path, permanently: Bool) async throws {
guard let xcode = InstalledXcode(
path: path,
contentsAtPath: { path in Current.files.contents(atPath: path) },
Expand All @@ -1066,14 +1065,17 @@ class AppState: ObservableObject {
throw FileError.fileNotFound(path.string)
}

if Current.helper.usePrivilegedHelperForFileOperations {
if permanently && Current.helper.usePrivilegedHelperForFileOperations {
try await installHelperIfNecessaryAsync()
try await Current.helper.removeAsync(xcode.path.string)
} else {
_ = try XcodeUninstallService(
removeItem: { url in try Current.files.removeItem(at: url) },
trashItem: { url in try Current.files.trashItem(at: url) }
).uninstall(xcode, emptyTrash: false)
let files = Current.files
try await Task.detached(priority: .userInitiated) {
_ = try XcodeUninstallService(
removeItem: files.removeItem,
trashItem: files.trashItem
).uninstall(xcode, emptyTrash: permanently)
}.value
}
}

Expand Down
13 changes: 11 additions & 2 deletions Xcodes/Frontend/MainWindow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ struct MainWindow: View {
@State private var selectedXcodeID: Xcode.ID?
@State private var searchText: String = ""
@State private var columnVisibility: NavigationSplitViewVisibility = .automatic
@State private var deletePermanently = false
@AppStorage("lastUpdated") private var lastUpdated: Double?
// These two properties should be per-scene state managed by @SceneStorage property wrappers.
// There's currently a bug with @SceneStorage on macOS, though, where quitting the app will discard the values, which removes a lot of its utility.
Expand All @@ -30,10 +31,12 @@ struct MainWindow: View {
presenting: appState.xcodeBeingConfirmedForUninstallation
) { xcode in
let platforms = appState.installedRuntimesUsedOnly(by: xcode)
Button("Uninstall", role: .destructive) { appState.uninstall(xcode: xcode) }
Button("Uninstall", role: .destructive) {
appState.uninstall(xcode: xcode, permanently: deletePermanently)
}
if !platforms.isEmpty {
Button("Alert.Uninstall.WithPlatforms", role: .destructive) {
appState.uninstall(xcode: xcode, removingRuntimes: platforms)
appState.uninstall(xcode: xcode, permanently: deletePermanently, removingRuntimes: platforms)
}
}
Button("Cancel", role: .cancel) {}
Expand All @@ -45,6 +48,12 @@ struct MainWindow: View {
Text(verbatim: localizeString("Alert.Uninstall.Message") + "\n\n" + String(format: localizeString("Alert.Uninstall.PlatformsMessage"), platforms.map(\.visibleIdentifier).joined(separator: ", ")))
}
}
.dialogSuppressionToggle("Alert.Uninstall.DeletePermanently", isSuppressed: $deletePermanently)
.onChange(of: appState.xcodeBeingConfirmedForUninstallation?.id) { _, id in
if id != nil {
deletePermanently = false
}
}
.searchable(text: $searchText, placement: .sidebar)
.mainToolbar(
category: $category,
Expand Down
Loading