Skip to content

armgit / peel

Public Imported from GitHub
0

Uninstall Mac apps with every file they leave behind, and see why each belongs. Free up space, fine-tune macOS, and set up Terminal.

Dropping several apps on the list chooses them all

Țugui Dragoș9cfed014e425
diff --git a/Peel/Model/AppLibrary.swift b/Peel/Model/AppLibrary.swift
index f89fdd5c..e5923b96 100644
--- a/Peel/Model/AppLibrary.swift
+++ b/Peel/Model/AppLibrary.swift
@@ -673,22 +673,33 @@ final class AppLibrary {
await checkSigningTeams()
}
- /// Selects an app, adding it first when it lives outside the scanned folders, for example in the Trash.
- func reveal(_ url: URL) async {
+ /// Selects the apps together, adding each first when it lives outside the scanned folders, for example in
+ /// the Trash. What is not an app is passed over.
+ func reveal(_ urls: [URL]) async {
+ var chosen: Set<InstalledApp.ID> = []
+ for url in urls {
+ if let id = await listed(url) {
+ chosen.insert(id)
+ }
+ }
+ guard !chosen.isEmpty else { return }
+ selection = chosen
+ }
+
+ private func listed(_ url: URL) async -> InstalledApp.ID? {
let bundleURL = url.standardizedFileURL
// Looked up on disk, since a trailing slash, another case, or a link can name a bundle already listed.
// Listed twice, the app would be its own rival and share every file with itself.
if let existing = await Self.find(bundleURL, among: apps) {
- selection = [existing.id]
- return
+ return existing.id
}
- guard bundleURL.pathExtension == "app", let app = await Self.inspect(bundleURL) else { return }
+ guard bundleURL.pathExtension == "app", let app = await Self.inspect(bundleURL) else { return nil }
// Checked again, since two drops of the same bundle can both get this far before either is listed.
if !apps.contains(where: { $0.id == app.id }) {
revealed.append(app)
adopt(apps.filter { listed in !revealed.contains { $0.id == listed.id } })
}
- selection = [app.id]
+ return app.id
}
@concurrent
diff --git a/Peel/Views/AppList.swift b/Peel/Views/AppList.swift
index ab459bc5..9a21a7fe 100644
--- a/Peel/Views/AppList.swift
+++ b/Peel/Views/AppList.swift
@@ -56,8 +56,9 @@ struct AppList: View {
}
}
.dropDestination(for: URL.self) { urls, _ in
- guard let applicationURL = urls.compactMap(OpenRequest.applicationURL(from:)).first else { return false }
- Task { await library.reveal(applicationURL) }
+ let applicationURLs = urls.compactMap(OpenRequest.applicationURL(from:))
+ guard !applicationURLs.isEmpty else { return false }
+ Task { await library.reveal(applicationURLs) }
return true
}
.fadesInColumn(whenRowsChange: library.apps.map(\.id))
diff --git a/Peel/Views/ContentView.swift b/Peel/Views/ContentView.swift
index 27d43b0f..9840e0ac 100644
--- a/Peel/Views/ContentView.swift
+++ b/Peel/Views/ContentView.swift
@@ -130,7 +130,7 @@ struct ContentView: View {
.onOpenURL { url in
guard let applicationURL = OpenRequest.applicationURL(from: url) else { return }
show(.applications)
- Task { await library.reveal(applicationURL) }
+ Task { await library.reveal([applicationURL]) }
}
// A request made while the window was closed (from a Shortcut, the Finder extension, or the menu bar
// panel) is already set when this view appears, and `onChange` only fires on a change, so anything
@@ -353,7 +353,7 @@ struct ContentView: View {
let match = library.apps.first { $0.names.contains { $0.lowercased() == wanted } }
?? library.apps.first { $0.names.contains { SearchText.matches($0, name) } }
guard let match else { return }
- await library.reveal(match.url)
+ await library.reveal([match.url])
}
@ViewBuilder