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.

List iCloud Drive's first refusals, and copy the rest

Țugui Dragoș0238dbfc6f8b
diff --git a/Peel/Views/Cloud/CloudView.swift b/Peel/Views/Cloud/CloudView.swift
index c490884a..f4626ccd 100644
--- a/Peel/Views/Cloud/CloudView.swift
+++ b/Peel/Views/Cloud/CloudView.swift
@@ -28,7 +28,8 @@ struct CloudView: View {
if !cloud.refusals.isEmpty {
Section {
- ForEach(cloud.refusals) { refusal in
+ let (shown, more) = RemovalFailureAlert.first(cloud.refusals)
+ ForEach(shown) { refusal in
VStack(alignment: .leading, spacing: 2) {
Text(refusal.url.abbreviatedPath)
.font(.callout)
@@ -39,6 +40,19 @@ struct CloudView: View {
.foregroundStyle(.secondary)
}
}
+ if more > 0 {
+ HStack {
+ Text(verbatim: String(inflecting: "And ^[\(more) more item](inflect: true)."))
+ .font(.callout)
+ .foregroundStyle(.secondary)
+ Spacer()
+ CopyButton(
+ text: cloud.refusals.map { "\($0.url.abbreviatedPath)\n\($0.explanation)" }
+ .joined(separator: "\n\n"),
+ title: "Copy Details"
+ )
+ }
+ }
} header: {
heading("Still Here", "These were left as they are, with the reason beside each one.")
}
diff --git a/Peel/Views/RemovalFailureAlert.swift b/Peel/Views/RemovalFailureAlert.swift
index eba82a68..563dfbb2 100644
--- a/Peel/Views/RemovalFailureAlert.swift
+++ b/Peel/Views/RemovalFailureAlert.swift
@@ -28,6 +28,11 @@ struct RemovalFailureAlert: ViewModifier {
listed(names) { String(inflecting: "^[\($0) more app](inflect: true)") }
}
+ /// The first of `items`, as many as an alert lists, and how many more there are.
+ static func first<T>(_ items: [T]) -> (shown: [T], more: Int) {
+ (Array(items.prefix(mostListed)), max(0, items.count - mostListed))
+ }
+
/// Folders named in one sentence, the same way.
static func listedFolders(_ paths: [String]) -> String {
listed(paths) { String(inflecting: "^[\($0) more folder](inflect: true)") }
diff --git a/PeelTests/UnreadableFoldersTests.swift b/PeelTests/UnreadableFoldersTests.swift
index c8483f14..b93aa81a 100644
--- a/PeelTests/UnreadableFoldersTests.swift
+++ b/PeelTests/UnreadableFoldersTests.swift
@@ -11,4 +11,11 @@ struct UnreadableFoldersTests {
#expect(sentence.contains("56"))
#expect(RemovalFailureAlert.listedFolders(["/a", "/b"]).contains("/b"))
}
+
+ @Test func anAlertsFirstItemsAndHowManyMore() {
+ let (shown, more) = RemovalFailureAlert.first(Array(1...60))
+
+ #expect(shown == [1, 2, 3, 4] && more == 56)
+ #expect(RemovalFailureAlert.first([1, 2]) == ([1, 2], 0))
+ }
}