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.

History lists what Peel was asked to move and didn't

Țugui Dragoșb718fb91a5f5
diff --git a/ARCHITECTURE.md b/ARCHITECTURE.md
index d3e942ab..64a992c8 100644
--- a/ARCHITECTURE.md
+++ b/ARCHITECTURE.md
@@ -77,7 +77,7 @@ Take the most common case, uninstalling an app. Every other page follows the sam
forget the preference domains whose files went.
7. **Record.** Every removal goes into History (`removals.json`, through `RemovalLog`), with where each item came
from and where it went, so it can be put back; History keeps the most recent 20,000 items. What Peel refused to
- move is recorded too (`refusals.json`).
+ move is recorded too (`refusals.json`), and History lists it under Not Moved, one removal to an entry.
8. **Put back.** History's Put Back reads its record as a request, not as a fact: an item returns only from a
real Trash, only to a place the guard allows, and, through the helper, only if the helper's own ledger says
it moved that very item from that very place.
diff --git a/CHANGELOG.md b/CHANGELOG.md
index ee84dd18..8c5320c0 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -18,7 +18,8 @@ The first public release, for macOS 26 and later, on Apple silicon and Intel Mac
- Lists background items, extensions, plug-ins, installer receipts, Homebrew packages, and software that still
needs Rosetta.
- Changes settings macOS has but doesn't show, and puts back what was there when you turn one off.
-- Moves what it removes to the Trash instead of deleting it, and keeps a History that puts it back.
+- Moves what it removes to the Trash instead of deleting it, and keeps a History that puts it back and lists
+ what it didn't move, with the reason.
- Leaves alone the files, folders, and apps you exclude.
- Checks your apps for updates, and watches the Trash for apps you remove yourself.
- Exports what is installed and where each app came from, as JSON, CSV, plain text, or a Brewfile.
diff --git a/Localization/Peel/Localizable.xcstrings b/Localization/Peel/Localizable.xcstrings
index f525fa96..82986b6f 100644
--- a/Localization/Peel/Localizable.xcstrings
+++ b/Localization/Peel/Localizable.xcstrings
@@ -123453,6 +123453,118 @@
}
}
},
+ "You asked to move these %@, on %@." : {
+ "localizations" : {
+ "cs" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Požádali jste o přesunutí těchto položek %@, dne %@."
+ }
+ },
+ "de" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Du wolltest diese Objekte %@, am %@, verschieben."
+ }
+ },
+ "en" : {
+ "stringUnit" : {
+ "state" : "new",
+ "value" : "You asked to move these %1$@, on %2$@."
+ }
+ },
+ "es" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Pediste trasladar estos ítems a la papelera %@, el %@."
+ }
+ },
+ "fr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Vous avez demandé de déplacer ces éléments %@, le %@."
+ }
+ },
+ "it" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Hai chiesto di spostare questi elementi %@, in data %@."
+ }
+ },
+ "ja" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "%2$@(%1$@)に、これらの項目をゴミ箱に入れるようPeelに指示しました。"
+ }
+ },
+ "ko" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "사용자가 %@(%@)에 이 항목들을 이동하도록 요청했습니다."
+ }
+ },
+ "nl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Op %2$@ vroeg je om deze onderdelen te verplaatsen (%1$@)."
+ }
+ },
+ "pl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Poproszono o przeniesienie tych rzeczy %@, %@."
+ }
+ },
+ "pt" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Você pediu para mover estes itens %@, em %@."
+ }
+ },
+ "ro" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Ați cerut mutarea acestora %@, pe %@."
+ }
+ },
+ "ru" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Вы попросили переместить эти объекты %@, %@."
+ }
+ },
+ "sv" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Du bad Peel att flytta de här objekten %@, den %@."
+ }
+ },
+ "tr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Bunların taşınmasını %@, %@ tarihinde istediniz."
+ }
+ },
+ "uk" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Ви попросили перемістити ці елементи %@, %@."
+ }
+ },
+ "zh-Hans" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "你%@(%@)要求移动这些项目。"
+ }
+ },
+ "zh-Hant" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "你%@要求移動這些項目,時間為%@。"
+ }
+ }
+ }
+ },
"You lose the quick way to type accented letters." : {
"localizations" : {
"cs" : {
@@ -129189,6 +129301,346 @@
}
}
},
+ "^[%lld item](inflect: true) not moved" : {
+ "localizations" : {
+ "cs" : {
+ "variations" : {
+ "plural" : {
+ "few" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "%lld položky nepřesunuty"
+ }
+ },
+ "many" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "%lld položky nepřesunuto"
+ }
+ },
+ "one" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "%lld položka nepřesunuta"
+ }
+ },
+ "other" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "%lld položek nepřesunuto"
+ }
+ }
+ }
+ }
+ },
+ "de" : {
+ "variations" : {
+ "plural" : {
+ "one" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "%lld Objekt nicht verschoben"
+ }
+ },
+ "other" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "%lld Objekte nicht verschoben"
+ }
+ }
+ }
+ }
+ },
+ "es" : {
+ "variations" : {
+ "plural" : {
+ "many" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "%lld de ítems sin trasladar"
+ }
+ },
+ "one" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "%lld ítem sin trasladar"
+ }
+ },
+ "other" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "%lld ítems sin trasladar"
+ }
+ }
+ }
+ }
+ },
+ "fr" : {
+ "variations" : {
+ "plural" : {
+ "many" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "%lld d’éléments non déplacés"
+ }
+ },
+ "one" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "%lld élément non déplacé"
+ }
+ },
+ "other" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "%lld éléments non déplacés"
+ }
+ }
+ }
+ }
+ },
+ "it" : {
+ "variations" : {
+ "plural" : {
+ "many" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "%lld di elementi non spostati"
+ }
+ },
+ "one" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "%lld elemento non spostato"
+ }
+ },
+ "other" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "%lld elementi non spostati"
+ }
+ }
+ }
+ }
+ },
+ "ja" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "移動されなかった%lld項目"
+ }
+ },
+ "ko" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "항목 %lld개가 이동되지 않음"
+ }
+ },
+ "nl" : {
+ "variations" : {
+ "plural" : {
+ "one" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "%lld onderdeel niet verplaatst"
+ }
+ },
+ "other" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "%lld onderdelen niet verplaatst"
+ }
+ }
+ }
+ }
+ },
+ "pl" : {
+ "variations" : {
+ "plural" : {
+ "few" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Nie przeniesiono %lld rzeczy"
+ }
+ },
+ "many" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Nie przeniesiono %lld rzeczy"
+ }
+ },
+ "one" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Nie przeniesiono %lld rzeczy"
+ }
+ },
+ "other" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Nie przeniesiono %lld rzeczy"
+ }
+ }
+ }
+ }
+ },
+ "pt" : {
+ "variations" : {
+ "plural" : {
+ "many" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "%lld de itens não movidos"
+ }
+ },
+ "one" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "%lld item não movido"
+ }
+ },
+ "other" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "%lld itens não movidos"
+ }
+ }
+ }
+ }
+ },
+ "ro" : {
+ "variations" : {
+ "plural" : {
+ "few" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "%lld articole nu au fost mutate"
+ }
+ },
+ "one" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "%lld articol nu a fost mutat"
+ }
+ },
+ "other" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "%lld de articole nu au fost mutate"
+ }
+ }
+ }
+ }
+ },
+ "ru" : {
+ "variations" : {
+ "plural" : {
+ "few" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Не перемещено %lld объекта"
+ }
+ },
+ "many" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Не перемещено %lld объектов"
+ }
+ },
+ "one" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Не перемещен %lld объект"
+ }
+ },
+ "other" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Не перемещено %lld объекта"
+ }
+ }
+ }
+ }
+ },
+ "sv" : {
+ "variations" : {
+ "plural" : {
+ "one" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "%lld objekt flyttades inte"
+ }
+ },
+ "other" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "%lld objekt flyttades inte"
+ }
+ }
+ }
+ }
+ },
+ "tr" : {
+ "variations" : {
+ "plural" : {
+ "one" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "%lld öğe taşınmadı"
+ }
+ },
+ "other" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "%lld öğe taşınmadı"
+ }
+ }
+ }
+ }
+ },
+ "uk" : {
+ "variations" : {
+ "plural" : {
+ "few" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "%lld елементи не переміщено"
+ }
+ },
+ "many" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "%lld елементів не переміщено"
+ }
+ },
+ "one" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "%lld елемент не переміщено"
+ }
+ },
+ "other" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "%lld елемента не переміщено"
+ }
+ }
+ }
+ }
+ },
+ "zh-Hans" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "%lld个项目未移动"
+ }
+ },
+ "zh-Hant" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "%lld個項目未移動"
+ }
+ }
+ }
+ },
"^[%lld item](inflect: true) on a disk that isn’t connected" : {
"localizations" : {
"cs" : {
diff --git a/Packages/PeelCore/Sources/PeelCommandLine/Support/Cleanup.swift b/Packages/PeelCore/Sources/PeelCommandLine/Support/Cleanup.swift
index 3565d8d6..02cc5885 100644
--- a/Packages/PeelCore/Sources/PeelCommandLine/Support/Cleanup.swift
+++ b/Packages/PeelCore/Sources/PeelCommandLine/Support/Cleanup.swift
@@ -79,7 +79,7 @@ struct Cleanup {
let refused = items.compactMap { item in item.refusal.map { TrashFailure(url: item.url, reason: $0) } }
guard !moving.isEmpty else {
Output.line("Nothing here can be moved.")
- await refusals.add(refused, source: source, tool: tool)
+ await refusals.add(refused, source: source, sourceKey: sourceKey, tool: tool)
return
}
if !yes {
diff --git a/Packages/PeelCore/Sources/PeelCommandLine/Support/Removals.swift b/Packages/PeelCore/Sources/PeelCommandLine/Support/Removals.swift
index 96d0319e..05973e98 100644
--- a/Packages/PeelCore/Sources/PeelCommandLine/Support/Removals.swift
+++ b/Packages/PeelCore/Sources/PeelCommandLine/Support/Removals.swift
@@ -13,7 +13,7 @@ enum Removals {
in log: RemovalLog = RemovalLog(),
refusals: RefusalLog = RefusalLog()
) async -> Bool {
- await refusals.add(result.failures, source: source, tool: tool)
+ await refusals.add(result.failures, source: source, sourceKey: sourceKey, tool: tool)
guard !result.trashed.isEmpty else { return true }
let batch = UUID()
let records = result.trashed.map {
diff --git a/Packages/PeelCore/Sources/PeelCore/Removal/RefusalLog.swift b/Packages/PeelCore/Sources/PeelCore/Removal/RefusalLog.swift
index 520f2b81..b3768079 100644
--- a/Packages/PeelCore/Sources/PeelCore/Removal/RefusalLog.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Removal/RefusalLog.swift
@@ -2,21 +2,28 @@ public import Foundation
public struct RefusalRecord: Sendable, Codable, Hashable, Identifiable {
public let id: UUID
+ /// What one removal refused shares a batch, so History shows it as one entry. A record without one is an entry
+ /// of its own.
+ public let batch: UUID?
public let url: URL
/// `TrashFailure.Reason.name`: a word, not the sentence shown on screen, so later versions can still read it.
public let reason: String
public let detail: String?
public let date: Date
public let source: String
+ /// A key for a source Peel names itself, as in `RemovalRecord.sourceKey`.
+ public let sourceKey: String?
public let tool: String
- public init(failure: TrashFailure, date: Date = .now, source: String, tool: String) {
+ public init(failure: TrashFailure, date: Date = .now, source: String, sourceKey: String? = nil, tool: String, batch: UUID? = nil) {
id = UUID()
+ self.batch = batch
url = failure.url
reason = failure.reason.name
detail = failure.reason.detail
self.date = date
self.source = source
+ self.sourceKey = sourceKey
self.tool = tool
}
}
@@ -37,8 +44,10 @@ public actor RefusalLog {
FileLock.whileHeld(beside: url) { current() ?? [] }
}
- public func add(_ failures: [TrashFailure], source: String, tool: String) {
- let records = failures.map { RefusalRecord(failure: $0, source: source, tool: tool) }
+ public func add(_ failures: [TrashFailure], source: String, sourceKey: String? = nil, tool: String) {
+ let batch = UUID()
+ let date = Date.now
+ let records = failures.map { RefusalRecord(failure: $0, date: date, source: source, sourceKey: sourceKey, tool: tool, batch: batch) }
guard !records.isEmpty else { return }
FileLock.whileHeld(beside: url) {
guard let existing = current() else { return }
diff --git a/Packages/PeelCore/Sources/PeelCore/Removal/RemovalGrouping.swift b/Packages/PeelCore/Sources/PeelCore/Removal/RemovalGrouping.swift
index 52eae927..96ec0eb2 100644
--- a/Packages/PeelCore/Sources/PeelCore/Removal/RemovalGrouping.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Removal/RemovalGrouping.swift
@@ -35,3 +35,32 @@ extension RemovalRecord {
.sorted { $0.date != $1.date ? $0.date > $1.date : $0.id.uuidString < $1.id.uuidString }
}
}
+
+/// What Peel was asked to move in one removal and did not, as History shows it.
+public struct RefusalGroup: Sendable, Hashable, Identifiable {
+ public let id: UUID
+ public let source: String
+ public let sourceKey: String?
+ public let tool: String
+ public let date: Date
+ public let records: [RefusalRecord]
+}
+
+extension RefusalRecord {
+ /// The refusals one removal to an entry, newest first, each entry's records by path.
+ public static func grouped(_ records: [RefusalRecord]) -> [RefusalGroup] {
+ Dictionary(grouping: records, by: { $0.batch ?? $0.id })
+ .map { batch, records in
+ let sorted = records.sorted { $0.url.path(percentEncoded: false) < $1.url.path(percentEncoded: false) }
+ return RefusalGroup(
+ id: batch,
+ source: sorted.first?.source ?? "",
+ sourceKey: sorted.first?.sourceKey,
+ tool: sorted.first?.tool ?? "",
+ date: sorted.map(\.date).min() ?? .now,
+ records: sorted
+ )
+ }
+ .sorted { $0.date != $1.date ? $0.date > $1.date : $0.id.uuidString < $1.id.uuidString }
+ }
+}
diff --git a/Packages/PeelCore/Sources/PeelCore/Removal/TrashService.swift b/Packages/PeelCore/Sources/PeelCore/Removal/TrashService.swift
index dd113fdf..eac93fa5 100644
--- a/Packages/PeelCore/Sources/PeelCore/Removal/TrashService.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Removal/TrashService.swift
@@ -57,6 +57,22 @@ extension TrashFailure.Reason {
default: nil
}
}
+
+ /// The reason a refusal log stored as `name` and `detail`, or nil for a word this version doesn't know.
+ public init?(name: String, detail: String?) {
+ switch name {
+ case "protected-location": self = .protectedLocation
+ case "changed-since-scan": self = .changedSinceScan
+ case "claimed-since-scan": self = .claimedSinceScan
+ case "last-copy": self = .lastCopy
+ case "not-permitted": self = .notPermitted
+ case "needs-helper": self = .needsHelper
+ case "moved-without-a-trace": self = .movedWithoutATrace
+ case "something-else-moved": self = .somethingElseMoved(named: detail ?? "")
+ case "failed": self = .failed(detail ?? "")
+ default: return nil
+ }
+ }
}
public enum RestoreFailure: Sendable, Hashable {
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/RefusalLogTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/RefusalLogTests.swift
index a687665a..1be38269 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/RefusalLogTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/RefusalLogTests.swift
@@ -103,14 +103,66 @@ struct RefusalLogTests {
#expect(await log.clear(), "forgetting what is already forgotten is no failure")
}
+ private static let everyReason: [TrashFailure.Reason] = [
+ .protectedLocation, .changedSinceScan, .claimedSinceScan, .lastCopy, .notPermitted, .needsHelper,
+ .movedWithoutATrace, .somethingElseMoved(named: "x 2"), .failed("x"),
+ ]
+
/// A record stores its reason as a word, not a sentence, so a later version of Peel can still read it.
@Test func everyReasonHasAWordOfItsOwn() {
- let reasons: [TrashFailure.Reason] = [
- .protectedLocation, .changedSinceScan, .claimedSinceScan, .lastCopy, .notPermitted, .needsHelper, .failed("x"),
- ]
+ let reasons = Self.everyReason
#expect(Set(reasons.map(\.name)).count == reasons.count)
#expect(reasons.allSatisfy { !$0.name.contains(" ") })
- #expect(reasons.filter { $0.detail != nil }.count == 1)
+ #expect(reasons.filter { $0.detail != nil }.count == 2)
+ }
+
+ /// History words a refusal from the reason it stored, so every word leads back to its reason, and a word a
+ /// later version wrote is read as none rather than guessed at.
+ @Test func everyReasonReadsBackFromItsWord() {
+ for reason in Self.everyReason {
+ #expect(TrashFailure.Reason(name: reason.name, detail: reason.detail) == reason)
+ }
+ #expect(TrashFailure.Reason(name: "a-word-from-later", detail: nil) == nil)
+ }
+
+ /// What one removal refused shares a batch and its source, so History shows it as one entry, in the words of
+ /// the source Peel named.
+ @Test func oneRemovalsRefusalsShareABatch() async throws {
+ let directory = try TemporaryDirectory()
+ let log = RefusalLog(url: directory.url.appending(path: "Peel/refusals.json"))
+
+ await log.add([failure("/Users/me/a", .lastCopy), failure("/Users/me/b", .lastCopy)], source: "Duplicates", sourceKey: "tool", tool: "duplicates")
+ await log.add([failure("/Users/me/c", .notPermitted)], source: "Editor", tool: "applications")
+
+ let records = await log.load()
+ let first = records.filter { $0.source == "Duplicates" }
+ #expect(first.count == 2)
+ #expect(Set(first.map(\.batch)).count == 1)
+ #expect(first.allSatisfy { $0.batch != nil && $0.sourceKey == "tool" })
+ #expect(records.first { $0.source == "Editor" }?.batch != first.first?.batch)
+ #expect(records.first { $0.source == "Editor" }?.sourceKey == nil)
+ }
+
+ /// History lists what was refused one removal to an entry, newest first. A record kept without a batch is an
+ /// entry of its own.
+ @Test func historyShowsEachRemovalsRefusalsAsOneEntry() throws {
+ let decoder = JSONDecoder()
+ decoder.dateDecodingStrategy = .iso8601
+ let batch = UUID()
+ let stored = """
+ [{"id":"\(UUID())","batch":"\(batch)","url":"file:///Users/me/b","reason":"last-copy","date":"2026-09-20T10:00:00Z","source":"Duplicates","sourceKey":"tool","tool":"duplicates"},
+ {"id":"\(UUID())","batch":"\(batch)","url":"file:///Users/me/a","reason":"last-copy","date":"2026-09-20T10:00:01Z","source":"Duplicates","sourceKey":"tool","tool":"duplicates"},
+ {"id":"\(UUID())","url":"file:///Users/me/old","reason":"not-permitted","date":"2026-09-19T10:00:00Z","source":"Editor","tool":"applications"}]
+ """
+ let groups = RefusalRecord.grouped(try decoder.decode([RefusalRecord].self, from: Data(stored.utf8)))
+
+ #expect(groups.map(\.source) == ["Duplicates", "Editor"])
+ #expect(groups.first?.id == batch)
+ #expect(groups.first?.sourceKey == "tool")
+ #expect(groups.first?.records.map(\.url.lastPathComponent) == ["a", "b"])
+ #expect(groups.first?.date == ISO8601DateFormatter().date(from: "2026-09-20T10:00:00Z"))
+ #expect(groups.last?.records.count == 1)
+ #expect(groups.last?.sourceKey == nil)
}
}
diff --git a/Peel/Model/RemovalHistoryStore.swift b/Peel/Model/RemovalHistoryStore.swift
index 971bfd4e..262f5c6c 100644
--- a/Peel/Model/RemovalHistoryStore.swift
+++ b/Peel/Model/RemovalHistoryStore.swift
@@ -48,6 +48,24 @@ struct RemovalBatch: Identifiable, Hashable {
}
}
+/// What Peel was asked to move in one removal and did not.
+struct RefusalBatch: Identifiable, Hashable {
+ let id: UUID
+ let tool: Tool?
+ let date: Date
+ let records: [RefusalRecord]
+ /// The source in the user's language, as `RemovalBatch.title` gives it.
+ let title: String
+
+ init(_ group: RefusalGroup) {
+ id = group.id
+ tool = Tool(rawValue: group.tool)
+ date = group.date
+ records = group.records
+ title = RemovalBatch.title(source: group.source, key: group.sourceKey, tool: tool)
+ }
+}
+
@Observable
final class RemovalHistoryStore {
private let log = RemovalLog()
@@ -69,6 +87,9 @@ final class RemovalHistoryStore {
private(set) var hasLoaded = false
/// What a search looks through, built once with the batches rather than walked on every keystroke.
private(set) var searchKeys: [RemovalBatch.ID: String] = [:]
+ /// What Peel was asked to move and did not, one removal to an entry, newest first.
+ private(set) var refusalBatches: [RefusalBatch] = []
+ private(set) var refusalSearchKeys: [RefusalBatch.ID: String] = [:]
private(set) var problem: RemovalLogProblem?
private(set) var isRestoring = false
var selection: RemovalBatch.ID?
@@ -95,8 +116,20 @@ final class RemovalHistoryStore {
batches.first { $0.id == selection }
}
+ var selectedRefusals: RefusalBatch? {
+ refusalBatches.first { $0.id == selection }
+ }
+
func load() async {
apply(await log.load())
+ await loadRefusals()
+ }
+
+ private func loadRefusals() async {
+ refusalBatches = RefusalRecord.grouped(await refusals.load()).map(RefusalBatch.init)
+ refusalSearchKeys = Dictionary(uniqueKeysWithValues: refusalBatches.map {
+ ($0.id, Self.searchKey(title: $0.title, names: $0.records.map(\.url.lastPathComponent)))
+ })
}
/// Records a removal in History. When Peel wrote the source itself, pass it in English along with a
@@ -105,7 +138,10 @@ final class RemovalHistoryStore {
func record(_ result: TrashResult, tool: Tool, source: String, sourceKey: String? = nil, sizes: [URL: Int64]) async {
// Refusals are logged before the early return below: a removal where nothing moved is the one most
// worth a record.
- await refusals.add(result.failures, source: source, tool: tool.rawValue)
+ await refusals.add(result.failures, source: source, sourceKey: sourceKey, tool: tool.rawValue)
+ if !result.failures.isEmpty {
+ await loadRefusals()
+ }
guard !result.trashed.isEmpty else { return }
let batch = UUID()
let new = result.trashed.map {
@@ -141,7 +177,9 @@ final class RemovalHistoryStore {
if let records = outcome.records {
self.records = records
batches = Self.batches(of: records)
- searchKeys = Dictionary(uniqueKeysWithValues: batches.map { ($0.id, Self.searchKey(of: $0)) })
+ searchKeys = Dictionary(uniqueKeysWithValues: batches.map {
+ ($0.id, Self.searchKey(title: $0.title, names: $0.records.map(\.originalURL.lastPathComponent)))
+ })
}
problem = outcome.problem
hasLoaded = true
@@ -191,10 +229,10 @@ final class RemovalHistoryStore {
}
- /// The batch's title and the name of each item in it, joined into one string, so a search makes one call
+ /// A batch's title and the name of each item in it, joined into one string, so a search makes one call
/// per batch rather than one per record.
- private static func searchKey(of batch: RemovalBatch) -> String {
- ([batch.title] + batch.records.map { $0.originalURL.lastPathComponent }).joined(separator: "\n")
+ private static func searchKey(title: String, names: [String]) -> String {
+ ([title] + names).joined(separator: "\n")
}
}
diff --git a/Peel/Views/ContentView.swift b/Peel/Views/ContentView.swift
index 21f82302..6a052eb5 100644
--- a/Peel/Views/ContentView.swift
+++ b/Peel/Views/ContentView.swift
@@ -403,6 +403,9 @@ struct ContentView: View {
if let batch = history.selectedBatch {
HistoryDetailView(batch: batch)
.id(batch.id)
+ } else if let refusals = history.selectedRefusals {
+ RefusalDetailView(batch: refusals)
+ .id(refusals.id)
} else {
DetailPlaceholder(tool: .history, summary: history.summary, instruction: "Choose a removal to put any of it back.")
}
diff --git a/Peel/Views/History/HistoryList.swift b/Peel/Views/History/HistoryList.swift
index 19501b48..c3559553 100644
--- a/Peel/Views/History/HistoryList.swift
+++ b/Peel/Views/History/HistoryList.swift
@@ -14,15 +14,34 @@ struct HistoryList: View {
return history.batches.filter { batch in history.searchKeys[batch.id].map { SearchText.matches($0, searchText) } == true }
}
+ private var refusals: [RefusalBatch] {
+ guard !searchText.isEmpty else { return history.refusalBatches }
+ return history.refusalBatches.filter { batch in history.refusalSearchKeys[batch.id].map { SearchText.matches($0, searchText) } == true }
+ }
+
var body: some View {
@Bindable var history = history
// Filtered once per body, since the list and the overlay both use the result.
let listed = batches
+ let refused = refusals
- List(listed, selection: $history.selection) { batch in
- HistoryBatchRow(batch: batch)
+ List(selection: $history.selection) {
+ ForEach(listed) { batch in
+ HistoryBatchRow(batch: batch)
+ }
+ // No heading when the list would start with it: a list that begins with a heading and fills all at
+ // once keeps its rows at the table's default height.
+ if listed.isEmpty {
+ ForEach(refused) { RefusalBatchRow(batch: $0) }
+ } else if !refused.isEmpty {
+ Section {
+ ForEach(refused) { RefusalBatchRow(batch: $0) }
+ } header: {
+ Text("Not Moved")
+ }
+ }
}
- .columnSearch(text: $searchText, prompt: "Search History", when: !history.batches.isEmpty)
+ .columnSearch(text: $searchText, prompt: "Search History", when: !history.batches.isEmpty || !history.refusalBatches.isEmpty)
.safeAreaBar(edge: .top) {
Group {
if let problem = history.problem {
@@ -35,17 +54,17 @@ struct HistoryList: View {
.motion(.settle, .movement, value: history.problem != nil)
}
.overlay {
- if history.batches.isEmpty, history.hasLoaded {
+ if history.batches.isEmpty, history.refusalBatches.isEmpty, history.hasLoaded {
ContentUnavailableView(
"Nothing Removed Yet",
systemImage: "clock.arrow.circlepath",
description: Text("What you move to the Trash with Peel shows up here, and can be put back while it’s still in the Trash.")
)
- } else if listed.isEmpty {
+ } else if listed.isEmpty, refused.isEmpty {
ContentUnavailableView.search(text: searchText)
}
}
- .fadesInColumn(whenRowsChange: history.batches.map(\.id))
+ .fadesInColumn(whenRowsChange: history.batches.map(\.id) + history.refusalBatches.map(\.id))
.navigationTitle(Text(Tool.history.title))
// Every tool has a button in the toolbar, so the window keeps one height from page to page.
.toolbar {
@@ -114,3 +133,23 @@ private struct HistoryBatchRow: View {
}
}
}
+
+/// One removal's refusals: what Peel was asked to move and did not.
+private struct RefusalBatchRow: View {
+ let batch: RefusalBatch
+
+ var body: some View {
+ ToolRow(systemImage: "nosign") {
+ Text(verbatim: batch.title)
+ .lineLimit(1)
+ .truncationMode(.middle)
+ } details: {
+ HStack(spacing: 6) {
+ Text("^[\(batch.records.count) item](inflect: true) not moved")
+ Text(batch.date, format: .relative(presentation: .named))
+ .help(Text(batch.date, format: .dateTime.day().month(.wide).year().hour().minute()))
+ }
+ .lineLimit(1)
+ }
+ }
+}
diff --git a/Peel/Views/History/RefusalDetailView.swift b/Peel/Views/History/RefusalDetailView.swift
new file mode 100644
index 00000000..fe889c3f
--- /dev/null
+++ b/Peel/Views/History/RefusalDetailView.swift
@@ -0,0 +1,69 @@
+import PeelCore
+import SwiftUI
+
+/// What Peel was asked to move in one removal and did not, with the reason for each item.
+struct RefusalDetailView: View {
+ @Environment(ExclusionsStore.self) private var exclusions
+ let batch: RefusalBatch
+
+ var body: some View {
+ List {
+ PageHeader(systemImage: "nosign") {
+ Text(verbatim: batch.title)
+ .pageTitle()
+ .textSelection(.enabled)
+ .help(Text(verbatim: batch.title))
+ } details: {
+ Text("You asked to move these \(batch.date, format: .relative(presentation: .named)), on \(batch.date, format: .dateTime.day().month(.wide).year().hour().minute()).")
+ .font(.callout)
+ .foregroundStyle(.secondary)
+ }
+ .listRowSeparator(.hidden)
+
+ Section {
+ ForEach(Array(batch.records.enumerated()), id: \.element.id) { index, record in
+ RefusalRecordRow(record: record, isExcluded: exclusions.exclusions.excludes(record.url), isFirst: index == 0)
+ }
+ .listRowSeparator(.hidden)
+ } header: {
+ Text("Items")
+ }
+ }
+ .navigationTitle(Text(verbatim: batch.title))
+ .toolbar(removing: .title)
+ }
+}
+
+private struct RefusalRecordRow: View {
+ let record: RefusalRecord
+ let isExcluded: Bool
+ var isFirst = false
+
+ var body: some View {
+ HStack(alignment: .firstTextBaseline, spacing: 10) {
+ Image(systemName: "nosign")
+ .foregroundStyle(.secondary)
+ .frame(width: 20)
+ VStack(alignment: .leading, spacing: 2) {
+ Text(record.url.abbreviatedPath)
+ .lineLimit(1)
+ .truncationMode(.middle)
+ Text(explanation)
+ .font(.caption)
+ .foregroundStyle(.secondary)
+ .fixedSize(horizontal: false, vertical: true)
+ }
+ Spacer(minLength: 0)
+ }
+ .tableRow(isFirst: isFirst)
+ .contextMenu {
+ ItemMenu(url: record.url, isExcluded: isExcluded)
+ }
+ }
+
+ /// Why the item stayed, in the words Peel shows when it refuses. A reason this version doesn't know is shown
+ /// as it was stored.
+ private var explanation: String {
+ TrashFailure.Reason(name: record.reason, detail: record.detail)?.explanation ?? record.detail ?? record.reason
+ }
+}
diff --git a/README.md b/README.md
index 4a3efccd..d16a4c85 100644
--- a/README.md
+++ b/README.md
@@ -125,7 +125,8 @@ before, or leaves it to macOS.
### Stay in control
-- **History:** everything Peel moved to the Trash, ready to put back, from the app and from Terminal alike.
+- **History:** everything Peel moved to the Trash, ready to put back, from the app and from Terminal alike, and
+ what it was asked to move and wouldn't, with the reason for each item.
- **Exclusions:** files, folders, and apps Peel must never touch.
### Work your way