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.

Name only the first folders in the alerts that refuse some of many

Țugui Dragoș412e8a19a4b5
diff --git a/AGENTS.md b/AGENTS.md
index 2390ee4f..b44b7fec 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -399,8 +399,10 @@ Peel runs on macOS 26 and later, and the two versions are treated differently in
(`HelperModel.change`). A failure goes back to whoever asked for the change and is shown there alone
(`HelperFailureAlert`).
- **An alert names the first few of a list that can grow.** AppKit never caps an alert's height, so a list of apps,
- pages, or lines in one names its first four and counts the rest (`RemovalFailureAlert.mostListed`), and Copy
- Details, offered whenever the alert leaves something out, gives them all.
+ pages, folders, or lines in one names its first four and counts the rest (`RemovalFailureAlert.mostListed`,
+ `RemovalFailureAlert.firstItems`), and Copy Details, where the alert offers it, gives them all. What the person has
+ to know whole before acting, the apps Peel asks to quit or would force quit and the formulae Clean Up uninstalls
+ for good, is named whole, in one sentence.
## Words and translations
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 604108a4..30e7e1a2 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -142,6 +142,8 @@ its changes the way [Keep a Changelog](https://keepachangelog.com/) suggests.
- Open at Login reads and changes the login item away from the main thread, so the window no longer waits for macOS.
- Remove Peel gives you the helper's ledger as the helper moves it to the Trash, so emptying the Trash needs no
administrator's password for it.
+- When many of the folders you choose can't be used, the alert of App Folders and of Exclusions names the first few
+ and counts the others, so its button stays on the screen, as do the alerts of Build Artifacts and Duplicates.
#### Applications
diff --git a/Peel/Views/Duplicates/DuplicateScanForm.swift b/Peel/Views/Duplicates/DuplicateScanForm.swift
index 5b0db176..264ca986 100644
--- a/Peel/Views/Duplicates/DuplicateScanForm.swift
+++ b/Peel/Views/Duplicates/DuplicateScanForm.swift
@@ -79,7 +79,7 @@ struct DuplicateScanForm: View {
) {
Button("OK", role: .cancel) {}
} message: {
- let paths = rejectedFolders.map(\.abbreviatedPath).joined(separator: "\n")
+ let paths = RemovalFailureAlert.firstItems(rejectedFolders.map(\.abbreviatedPath)).joined(separator: "\n")
Text("Choose a folder in your home folder, /Users/Shared, or a disk Peel can write to. iCloud Drive and other folders that sync to your other devices, app data, the Music and TV apps’ media folders, and system folders aren’t scanned.\n\n\(paths)")
}
}
diff --git a/Peel/Views/Projects/ProjectList.swift b/Peel/Views/Projects/ProjectList.swift
index b13940ff..b046e1ee 100644
--- a/Peel/Views/Projects/ProjectList.swift
+++ b/Peel/Views/Projects/ProjectList.swift
@@ -180,8 +180,9 @@ struct ProjectList: View {
}
}
- private static func reasons(_ folders: [(url: URL, reason: ProjectArtifacts.Refusal)]) -> String {
- folders.map { "\($0.url.abbreviatedPath)\n\($0.reason.explanation)" }.joined(separator: "\n\n")
+ static func reasons(_ folders: [(url: URL, reason: ProjectArtifacts.Refusal)]) -> String {
+ RemovalFailureAlert.firstItems(folders.map { "\($0.url.abbreviatedPath)\n\($0.reason.explanation)" })
+ .joined(separator: "\n\n")
}
private func phase(_ filtered: [ProjectGroup]) -> ScanPhase {
diff --git a/Peel/Views/RemovalFailureAlert.swift b/Peel/Views/RemovalFailureAlert.swift
index bc647b5f..6ef14081 100644
--- a/Peel/Views/RemovalFailureAlert.swift
+++ b/Peel/Views/RemovalFailureAlert.swift
@@ -11,6 +11,12 @@ struct RemovalFailureAlert: ViewModifier {
/// How many items the alert lists by path. The rest are only counted, to keep the alert short.
static let mostListed = 4
+ /// The first entries of a list, as many as an alert lists, and then how many items the others are.
+ static func firstItems(_ entries: [String]) -> [String] {
+ guard entries.count > mostListed else { return entries }
+ return entries.prefix(mostListed) + [String(inflecting: "And ^[\(entries.count - mostListed) more item](inflect: true).")]
+ }
+
/// The first lines of a list of apps, as many as an alert lists, and then how many apps the others are.
static func shortened(_ lines: [String]) -> [String] {
guard lines.count > mostListed else { return lines }
@@ -93,12 +99,8 @@ struct RemovalFailureAlert: ViewModifier {
}
static func message(for outcome: RemovalOutcome) -> String {
- let listed = outcome.failures.prefix(mostListed)
- var lines = shortened(quitLines(outcome)) + listed.map { "\($0.url.abbreviatedPath)\n\($0.reason.explanation)" }
- let rest = outcome.failures.count - listed.count
- if rest > 0 {
- lines.append(String(inflecting: "And ^[\(rest) more item](inflect: true)."))
- }
+ var lines = shortened(quitLines(outcome))
+ + firstItems(outcome.failures.map { "\($0.url.abbreviatedPath)\n\($0.reason.explanation)" })
lines += shortened(keptLines(outcome)) + driverLines(outcome) + administratorLines(outcome)
+ shellLines(outcome) { Self.listed($0) { String(inflecting: "^[\($0) more line](inflect: true)") } }
+ appManagementLines(outcome) + shortened(privacyLines(outcome))
diff --git a/Peel/Views/Settings/AppFoldersSection.swift b/Peel/Views/Settings/AppFoldersSection.swift
index 559f1d2f..c2208c69 100644
--- a/Peel/Views/Settings/AppFoldersSection.swift
+++ b/Peel/Views/Settings/AppFoldersSection.swift
@@ -85,8 +85,8 @@ struct AppFoldersSection: View {
}
private var refusalMessage: Text {
- let others = Text("Peel already looks in the Applications folders, and a folder as wide as a whole disk, your home folder, or a Library would slow down every look for apps. Choose the folder that holds the apps.\n\n\(refused.joined(separator: "\n"))")
- let inATrash = Text("The Trash holds what is on its way out, so Peel doesn’t look for apps there.\n\n\(refusedInATrash.joined(separator: "\n"))")
+ let others = Text("Peel already looks in the Applications folders, and a folder as wide as a whole disk, your home folder, or a Library would slow down every look for apps. Choose the folder that holds the apps.\n\n\(RemovalFailureAlert.firstItems(refused).joined(separator: "\n"))")
+ let inATrash = Text("The Trash holds what is on its way out, so Peel doesn’t look for apps there.\n\n\(RemovalFailureAlert.firstItems(refusedInATrash).joined(separator: "\n"))")
switch (refused.isEmpty, refusedInATrash.isEmpty) {
case (false, true): return others
case (true, false): return inATrash
diff --git a/Peel/Views/Settings/ExclusionsSettingsView.swift b/Peel/Views/Settings/ExclusionsSettingsView.swift
index 2e7bd2ee..2e08c239 100644
--- a/Peel/Views/Settings/ExclusionsSettingsView.swift
+++ b/Peel/Views/Settings/ExclusionsSettingsView.swift
@@ -211,7 +211,7 @@ struct ExclusionsSettingsView: View {
.alert(refused.count == 1 ? "That folder can’t be excluded." : "These folders can’t be excluded.", isPresented: isShowingRefusal) {
Button("OK", role: .cancel) {}
} message: {
- let paths = refused.joined(separator: "\n")
+ let paths = RemovalFailureAlert.firstItems(refused).joined(separator: "\n")
refused.count == 1
? Text("That would hide too much from Peel. Choose the folders inside it that matter to you.\n\n\(paths)")
: Text("That would hide too much from Peel. Choose the folders inside them that matter to you.\n\n\(paths)")
diff --git a/PeelTests/RemovalFailureAlertTests.swift b/PeelTests/RemovalFailureAlertTests.swift
index 2e4153ec..0035f108 100644
--- a/PeelTests/RemovalFailureAlertTests.swift
+++ b/PeelTests/RemovalFailureAlertTests.swift
@@ -26,6 +26,20 @@ struct RemovalFailureAlertTests {
#expect(details.filter { $0.contains("Example 30") }.count == 3)
}
+ @Test func namesTheFirstFoldersAnAlertRefusesAndCountsTheOthers() {
+ let most = RemovalFailureAlert.mostListed
+ let paths = (1...30).map { "/Users/someone/Folder \($0)" }
+ let shown = RemovalFailureAlert.firstItems(paths)
+ #expect(shown.count == most + 1)
+ #expect(Array(shown.prefix(most)) == Array(paths.prefix(most)))
+ #expect(RemovalFailureAlert.firstItems(Array(paths.prefix(most))) == Array(paths.prefix(most)))
+
+ let refused = paths.map { (url: URL(filePath: $0), reason: ProjectArtifacts.Refusal.neverSearched) }
+ let reasons = ProjectList.reasons(refused).components(separatedBy: "\n\n")
+ #expect(reasons.count == most + 1, "\(reasons.count)")
+ #expect(!reasons.contains { $0.contains("Folder 30") })
+ }
+
@Test func copiesTheShellLineTheAlertShows() {
let outcome = RemovalOutcome()
outcome.report(