Uninstall Mac apps with every file they leave behind, and see why each belongs. Free up space, fine-tune macOS, and set up Terminal.
Swift cache-cleanercleanerclideveloper-toolsdisk-cleanupdisk-spaceduplicate-finderhomebrewliquid-glassmac-cleanermacosmacos-appmacos-golden-gatemacos-tahoemacos-tweaksswiftswiftuiterminal-themesuninstalluninstaller
History records what Peel could not measure as unknown
Țugui Dragoș254e239d3a8a
diff --git a/Packages/PeelCore/Sources/PeelCommandLine/Commands/AppCommands.swift b/Packages/PeelCore/Sources/PeelCommandLine/Commands/AppCommands.swiftindex a95e411d..2ecaae38 100644--- a/Packages/PeelCore/Sources/PeelCommandLine/Commands/AppCommands.swift+++ b/Packages/PeelCore/Sources/PeelCommandLine/Commands/AppCommands.swift@@ -299,7 +299,7 @@ struct UninstallCommand: AsyncParsableCommand {// The privacy reset comes before the move, because `tccutil` only finds an app that is still in place.let privacy = resetPrivacy ? Self.privacyOutcome(await PrivacyReset.reset(bundleIdentifier: target.bundleIdentifier), app: target) : nillet result = await plan.move(using: service)- let sizes = Dictionary(plan.items.map { ($0.url, $0.size ?? 0) }, uniquingKeysWith: { first, _ in first })+ let sizes = [URL: Int64](measured: plan.items.map { ($0.url, $0.size) })let recorded = await Removals.record(result, from: target.name, sizes: sizes, tool: "applications")signal(SIGINT, SIG_DFL)signal(SIGTERM, SIG_DFL)diff --git a/Packages/PeelCore/Sources/PeelCommandLine/Commands/HistoryCommands.swift b/Packages/PeelCore/Sources/PeelCommandLine/Commands/HistoryCommands.swiftindex aa1a4a55..4dc137ac 100644--- a/Packages/PeelCore/Sources/PeelCommandLine/Commands/HistoryCommands.swift+++ b/Packages/PeelCore/Sources/PeelCommandLine/Commands/HistoryCommands.swift@@ -10,7 +10,7 @@ struct Batch {var date: Date { records.map(\.date).max() ?? .distantPast }var source: String { records.first?.source ?? "" }var tool: String { records.first?.tool ?? "" }- var size: Int64 { records.totalSize }+ var size: SizeTotal { records.totalSize }/// The records whose items are still in the Trash. An item emptied from the Trash can't be put back.var restorable: [RemovalRecord] { records.filter(\.isStillInTrash) }@@ -53,7 +53,7 @@ struct HistoryCommand: AsyncParsableCommand {let date: Datelet source: Stringlet tool: String- let size: Int64+ let size: MeasuredSizelet itemCount: Intlet restorableCount: Intlet files: [FileRecord]@@ -83,7 +83,7 @@ struct HistoryCommand: AsyncParsableCommand {date: batch.date,source: batch.source,tool: batch.tool,- size: batch.size,+ size: MeasuredSize(batch.size),itemCount: batch.records.count,restorableCount: batch.restorable.count,files: batch.records.map { FileRecord(path: Output.path($0.originalURL), size: MeasuredSize($0.size)) }diff --git a/Packages/PeelCore/Sources/PeelCommandLine/Support/Cleanup.swift b/Packages/PeelCore/Sources/PeelCommandLine/Support/Cleanup.swiftindex 38cb201e..3565d8d6 100644--- a/Packages/PeelCore/Sources/PeelCommandLine/Support/Cleanup.swift+++ b/Packages/PeelCore/Sources/PeelCommandLine/Support/Cleanup.swift@@ -91,7 +91,7 @@ struct Cleanup {signal(SIGINT, SIG_IGN)signal(SIGTERM, SIG_IGN)let result = await move(service, moving.map(\.url))- let sizes = Dictionary(items.map { ($0.url, $0.size ?? 0) }, uniquingKeysWith: { first, _ in first })+ let sizes = [URL: Int64](measured: items.map { ($0.url, $0.size) })let recorded = await Removals.record(TrashResult(trashed: result.trashed, failures: result.failures + refused),from: source,diff --git a/Packages/PeelCore/Sources/PeelCommandLine/Support/Removals.swift b/Packages/PeelCore/Sources/PeelCommandLine/Support/Removals.swiftindex 6a7f1d45..96d0319e 100644--- a/Packages/PeelCore/Sources/PeelCommandLine/Support/Removals.swift+++ b/Packages/PeelCore/Sources/PeelCommandLine/Support/Removals.swift@@ -3,7 +3,7 @@ import PeelCoreenum Removals {/// Records what moved as one batch in History, which the app reads too, and every failure in the log of- /// refusals. Returns false when History couldn't be written.+ /// refusals. An item missing from `sizes` is recorded as unknown. Returns false when History couldn't be written.static func record(_ result: TrashResult,from source: String,@@ -17,7 +17,7 @@ enum Removals {guard !result.trashed.isEmpty else { return true }let batch = UUID()let records = result.trashed.map {- RemovalRecord(batch: batch, item: $0, size: sizes[$0.originalURL] ?? 0, source: source, sourceKey: sourceKey, tool: tool)+ RemovalRecord(batch: batch, item: $0, size: sizes[$0.originalURL], source: source, sourceKey: sourceKey, tool: tool)}return await log.add(records).records != nil}diff --git a/Packages/PeelCore/Sources/PeelCore/Removal/RemovalGrouping.swift b/Packages/PeelCore/Sources/PeelCore/Removal/RemovalGrouping.swiftindex 7329f631..52eae927 100644--- a/Packages/PeelCore/Sources/PeelCore/Removal/RemovalGrouping.swift+++ b/Packages/PeelCore/Sources/PeelCore/Removal/RemovalGrouping.swift@@ -1,7 +1,8 @@public import Foundation-/// One removal as History shows it: the records that moved together, largest first. `grouped` lists the-/// removals newest first, and lives here rather than in the app so the rule can be tested.+/// One removal as History shows it: the records that moved together, largest first, and one Peel could not+/// measure before them. `grouped` lists the removals newest first, and lives here rather than in the app so the+/// rule can be tested.public struct RemovalGroup: Sendable, Hashable, Identifiable {public let id: UUIDpublic let source: String@@ -11,14 +12,17 @@ public struct RemovalGroup: Sendable, Hashable, Identifiable {public let date: Datepublic let records: [RemovalRecord]- public var size: Int64 { records.totalSize }+ public var size: SizeTotal { records.totalSize }}extension RemovalRecord {public static func grouped(_ records: [RemovalRecord]) -> [RemovalGroup] {Dictionary(grouping: records, by: \.batch).map { batch, records in- let sorted = records.sorted { $0.size != $1.size ? $0.size > $1.size : $0.originalURL.path(percentEncoded: false) < $1.originalURL.path(percentEncoded: false) }+ let sorted = records.sorted {+ let (lhs, rhs) = (SizeTotal([$0.size]), SizeTotal([$1.size]))+ return lhs != rhs ? lhs > rhs : $0.originalURL.path(percentEncoded: false) < $1.originalURL.path(percentEncoded: false)+ }return RemovalGroup(id: batch,source: sorted.first?.source ?? "",diff --git a/Packages/PeelCore/Sources/PeelCore/Removal/RemovalHistory.swift b/Packages/PeelCore/Sources/PeelCore/Removal/RemovalHistory.swiftindex ecfde378..159fe28e 100644--- a/Packages/PeelCore/Sources/PeelCore/Removal/RemovalHistory.swift+++ b/Packages/PeelCore/Sources/PeelCore/Removal/RemovalHistory.swift@@ -7,7 +7,8 @@ public struct RemovalRecord: Sendable, Codable, Hashable, Identifiable {public let originalURL: URLpublic let trashedURL: URLpublic let date: Date- public let size: Int64+ /// Nil when Peel could not measure the item. It is never read as zero.+ public let size: Int64?/// What the items belonged to: an app, an orphan group, a file name.public let source: Stringpublic let tool: String@@ -15,7 +16,7 @@ public struct RemovalRecord: Sendable, Codable, Hashable, Identifiable {/// History can show it in the user's language. `source` then holds the English name, which `peel` prints.public let sourceKey: String?- public init(id: UUID = UUID(), batch: UUID, item: TrashedItem, size: Int64, source: String, sourceKey: String? = nil, tool: String) {+ public init(id: UUID = UUID(), batch: UUID, item: TrashedItem, size: Int64?, source: String, sourceKey: String? = nil, tool: String) {self.id = idself.batch = batchoriginalURL = item.originalURL@@ -35,7 +36,7 @@ public struct RemovalRecord: Sendable, Codable, Hashable, Identifiable {originalURL = try container.decode(URL.self, forKey: .originalURL)trashedURL = try container.decode(URL.self, forKey: .trashedURL)date = try container.decode(Date.self, forKey: .date)- size = max(0, try container.decode(Int64.self, forKey: .size))+ size = try container.decodeIfPresent(Int64.self, forKey: .size).map { max(0, $0) }source = try container.decode(String.self, forKey: .source)tool = try container.decode(String.self, forKey: .tool)sourceKey = try container.decodeIfPresent(String.self, forKey: .sourceKey)@@ -58,10 +59,18 @@ public struct RemovalRecord: Sendable, Codable, Hashable, Identifiable {}}+extension [URL: Int64] {+ /// The sizes History records, by item: those that were measured. An item whose size is not known is left out,+ /// and is recorded as unknown rather than as zero.+ public init(measured sizes: some Sequence<(URL, Int64?)>) {+ self.init(sizes.compactMap { url, size in size.map { (url, $0) } }, uniquingKeysWith: { first, _ in first })+ }+}+extension Sequence<RemovalRecord> {- /// The sum of the sizes, capped at `Int64.max` rather than crashing on overflow: the sizes come from a file.- public var totalSize: Int64 {- reduce(0) { $0.addingCapped($1.size) }+ /// The sum of the sizes, incomplete when one of them is not known.+ public var totalSize: SizeTotal {+ SizeTotal(map(\.size))}}diff --git a/Packages/PeelCore/Sources/PeelCore/Support/SizeTotal.swift b/Packages/PeelCore/Sources/PeelCore/Support/SizeTotal.swiftindex a70ab760..b2fdb7f4 100644--- a/Packages/PeelCore/Sources/PeelCore/Support/SizeTotal.swift+++ b/Packages/PeelCore/Sources/PeelCore/Support/SizeTotal.swift@@ -10,12 +10,13 @@ public struct SizeTotal: Sendable, Hashable, Comparable {self.isComplete = isComplete}- /// Reads `sizes` once, so a sequence that can be read only once is summed whole.+ /// Reads `sizes` once, so a sequence that can be read only once is summed whole. The sum stops at `Int64.max`+ /// rather than trapping, since some sizes come from a file any process can rewrite.public init(_ sizes: some Sequence<Int64?>) {var known: Int64 = 0var isComplete = truefor size in sizes {- if let size { known += size } else { isComplete = false }+ if let size { known = known.addingCapped(size) } else { isComplete = false }}self.init(known: known, isComplete: isComplete)}diff --git a/Packages/PeelCore/Tests/PeelCoreTests/CommandLineTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/CommandLineTests.swiftindex 5ae580a1..bfc1ae71 100644--- a/Packages/PeelCore/Tests/PeelCoreTests/CommandLineTests.swift+++ b/Packages/PeelCore/Tests/PeelCoreTests/CommandLineTests.swift@@ -620,7 +620,7 @@ struct CommandLineTests {#expect(batches.map(\.id) == [recent, old])#expect(batches[1].records.count == 2)- #expect(batches[1].size == 20)+ #expect(batches[1].size == SizeTotal(known: 20, isComplete: true))#expect(batches[0].shortID == String(recent.uuidString.prefix(8)).lowercased())}diff --git a/Packages/PeelCore/Tests/PeelCoreTests/HistoryCommandTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/HistoryCommandTests.swiftindex 3a6e2a01..12b85152 100644--- a/Packages/PeelCore/Tests/PeelCoreTests/HistoryCommandTests.swift+++ b/Packages/PeelCore/Tests/PeelCoreTests/HistoryCommandTests.swift@@ -130,6 +130,42 @@ struct HistoryCommandTests {#expect(Batch.all(in: try #require(await logs.removals.load().records)).count == 3, "listing forgot nothing")}+ /// What Peel could not measure is never printed as zero: the table says "over" while part of a removal is+ /// known, and `--json` writes `null`, for the removal and for the file alike.+ @Test func aSizeNobodyMeasuredIsNeverPrintedAsZero() async throws {+ let directory = try TemporaryDirectory()+ let logs = logs(in: directory)+ let known = try removal(in: directory).record+ let unknown = RemovalRecord(+ batch: known.batch,+ item: TrashedItem(originalURL: directory.url.appending(path: "home/Documents/notes.txt"), trashedURL: try directory.file("home/.Trash/notes.txt", bytes: 3), date: .now),+ size: nil,+ source: "Editor",+ tool: "applications"+ )+ _ = await logs.removals.add([known, unknown])++ #expect(HistoryCommand.rows(for: Batch.all(in: [known, unknown]))[1][4] == "over 40 bytes")++ let listing = try #require(try listed(try await printed(["history", "--json"], from: logs)).first as? [String: Any])+ #expect(listing["size"] is NSNull)+ let files = try #require(listing["files"] as? [[String: Any]])+ #expect(Set(files.map { ($0["size"] as? Int).map(String.init) ?? "null" }) == ["40", "null"])+ }++ /// A caller passes the sizes it measured; an item it could not measure is left out and recorded as unknown.+ @Test func anItemLeftOutOfTheSizesIsRecordedAsUnknown() async throws {+ let directory = try TemporaryDirectory()+ let logs = logs(in: directory)+ let measured = TrashedItem(originalURL: URL(filePath: "/Users/me/a.txt"), trashedURL: URL(filePath: "/Users/me/.Trash/a.txt"), date: .now)+ let unmeasured = TrashedItem(originalURL: URL(filePath: "/Users/me/b"), trashedURL: URL(filePath: "/Users/me/.Trash/b"), date: .now)++ #expect(await Removals.record(TrashResult(trashed: [measured, unmeasured]), from: "Editor", sizes: [measured.originalURL: 5], tool: "applications", in: logs.removals, refusals: logs.refusals))++ let records = try #require(await logs.removals.load().records)+ #expect(Dictionary(uniqueKeysWithValues: records.map { ($0.originalURL.lastPathComponent, $0.size) }) == ["a.txt": 5, "b": nil])+ }+@Test func forgetsTheRefusalsWhenAsked() async throws {let directory = try TemporaryDirectory()let logs = logs(in: directory)diff --git a/Packages/PeelCore/Tests/PeelCoreTests/RemovalGroupingTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/RemovalGroupingTests.swiftindex 3206b03d..ccee0a7d 100644--- a/Packages/PeelCore/Tests/PeelCoreTests/RemovalGroupingTests.swift+++ b/Packages/PeelCore/Tests/PeelCoreTests/RemovalGroupingTests.swift@@ -4,7 +4,7 @@ import Testing/// What History shows: one row per removal, newest first, and inside it the largest item first.struct RemovalGroupingTests {- private func record(_ batch: UUID, _ name: String, size: Int64, at date: Date, source: String = "Example", tool: String = "applications") -> RemovalRecord {+ private func record(_ batch: UUID, _ name: String, size: Int64?, at date: Date, source: String = "Example", tool: String = "applications") -> RemovalRecord {RemovalRecord(batch: batch,item: TrashedItem(@@ -50,11 +50,26 @@ struct RemovalGroupingTests {#expect(groups.last?.records.map(\.originalURL.lastPathComponent) == ["big.bin", "small.bin"])// The batch's own time is the first record written, not the last.#expect(groups.last?.date == now.addingTimeInterval(-60))- #expect(groups.last?.size == 110)+ #expect(groups.last?.size == SizeTotal(known: 110, isComplete: true))#expect(groups.first?.source == "Caches")#expect(groups.first?.tool == "space")}+ /// An item whose size is not known comes first, since what could not be measured is most likely the biggest,+ /// and the removal's total says it is only the least the size can be.+ @Test func anItemNobodyMeasuredComesFirst() {+ let now = Date(timeIntervalSince1970: 1_800_000_000)+ let batch = UUID()+ let groups = RemovalRecord.grouped([+ record(batch, "big.bin", size: 100, at: now),+ record(batch, "unknown.bin", size: nil, at: now),+ record(batch, "small.bin", size: 10, at: now),+ ])++ #expect(groups.first?.records.map(\.originalURL.lastPathComponent) == ["unknown.bin", "big.bin", "small.bin"])+ #expect(groups.first?.size == SizeTotal(known: 110, isComplete: false))+ }+/// Two removals made at the same moment must keep their order from one render to the next.@Test func keepsTheOrderOfTwoRemovalsAtTheSameMoment() {let now = Date(timeIntervalSince1970: 1_800_000_000)diff --git a/Packages/PeelCore/Tests/PeelCoreTests/RemovalHistoryTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/RemovalHistoryTests.swiftindex 0c2b59a6..726b827b 100644--- a/Packages/PeelCore/Tests/PeelCoreTests/RemovalHistoryTests.swift+++ b/Packages/PeelCore/Tests/PeelCoreTests/RemovalHistoryTests.swift@@ -90,7 +90,30 @@ struct RemovalHistoryTests {let records = try decoder.decode([RemovalRecord].self, from: Data(stored.utf8))#expect(records.map(\.size) == [Int64.max, 0, 1], "a size below zero is no size")- #expect(records.totalSize == Int64.max, "the sum stops at the largest number there is instead of trapping")+ #expect(records.totalSize == SizeTotal(known: .max, isComplete: true), "the sum stops at the largest number there is instead of trapping")+ }++ /// What Peel could not measure is recorded as not known, so History never shows it as zero and a total with+ /// it in says "over". A record written without a size, or with `null`, reads the same way.+ @Test func aSizeNobodyMeasuredStaysUnknown() throws {+ let stored = """+ [{"id":"\(UUID())","batch":"\(UUID())","originalURL":"file:///Applications/A.app","trashedURL":"file:///Users/x/.Trash/A.app",+ "date":"2026-09-20T10:00:00Z","size":null,"source":"A","tool":"applications"},+ {"id":"\(UUID())","batch":"\(UUID())","originalURL":"file:///Applications/B.app","trashedURL":"file:///Users/x/.Trash/B.app",+ "date":"2026-09-20T10:00:00Z","source":"B","tool":"applications"},+ {"id":"\(UUID())","batch":"\(UUID())","originalURL":"file:///Applications/C.app","trashedURL":"file:///Users/x/.Trash/C.app",+ "date":"2026-09-20T10:00:00Z","size":7,"source":"C","tool":"applications"}]+ """+ let decoder = JSONDecoder()+ decoder.dateDecodingStrategy = .iso8601+ let records = try decoder.decode([RemovalRecord].self, from: Data(stored.utf8))++ #expect(records.map(\.size) == [nil, nil, 7])+ #expect(records.totalSize == SizeTotal(known: 7, isComplete: false))++ let encoder = JSONEncoder()+ encoder.dateEncodingStrategy = .iso8601+ #expect(try decoder.decode([RemovalRecord].self, from: encoder.encode(records)).map(\.size) == [nil, nil, 7])}@Test func tellsWhenAnItemIsNoLongerInTheTrash() throws {diff --git a/Peel/Model/BulkRemovalPlan.swift b/Peel/Model/BulkRemovalPlan.swiftindex bf11f196..c3fea17e 100644--- a/Peel/Model/BulkRemovalPlan.swift+++ b/Peel/Model/BulkRemovalPlan.swift@@ -81,7 +81,7 @@ final class BulkRemovalPlan {}var sizes: [URL: Int64] {- Dictionary(items.map { ($0.url, $0.size) }, uniquingKeysWith: { first, _ in first })+ [URL: Int64](measured: items.map { ($0.url, $0.isMeasured ? $0.size : nil) })}/// The source History records: up to three app names, or a count in English that History shows in thediff --git a/Peel/Model/LifetimeStats.swift b/Peel/Model/LifetimeStats.swiftindex bd1380a6..958f1542 100644--- a/Peel/Model/LifetimeStats.swift+++ b/Peel/Model/LifetimeStats.swift@@ -12,28 +12,31 @@ final class LifetimeStats {private enum Key {static let installed = "statsInstalledOn"static let bytes = "statsBytesFreed"+ static let bytesIncomplete = "statsBytesFreedIsIncomplete"static let items = "statsItemsRemoved"static let apps = "statsAppsRemoved"static let biggest = "statsBiggestCleanUp"+ static let biggestIncomplete = "statsBiggestCleanUpIsIncomplete"}private let defaults: UserDefaultsprivate(set) var installedOn: Date- private(set) var bytesFreed: Int64+ /// Incomplete once a removal held something Peel could not measure: the total is then only the least it can be.+ private(set) var bytesFreed: SizeTotalprivate(set) var itemsRemoved: Intprivate(set) var appsRemoved: Int- private(set) var biggestCleanUp: Int64+ private(set) var biggestCleanUp: SizeTotalinit(defaults: UserDefaults = .standard, bundle: URL = Bundle.main.bundleURL) {self.defaults = defaultsinstalledOn = defaults.object(forKey: Key.installed) as? Date ?? Self.arrival(of: bundle)// Any process can write these preferences, so a total below zero is read as none, and every sum below// is capped rather than allowed to trap.- bytesFreed = max(0, Int64(defaults.integer(forKey: Key.bytes)))+ bytesFreed = SizeTotal(known: max(0, Int64(defaults.integer(forKey: Key.bytes))), isComplete: !defaults.bool(forKey: Key.bytesIncomplete))itemsRemoved = max(0, defaults.integer(forKey: Key.items))appsRemoved = max(0, defaults.integer(forKey: Key.apps))- biggestCleanUp = max(0, Int64(defaults.integer(forKey: Key.biggest)))+ biggestCleanUp = SizeTotal(known: max(0, Int64(defaults.integer(forKey: Key.biggest))), isComplete: !defaults.bool(forKey: Key.biggestIncomplete))defaults.set(installedOn, forKey: Key.installed)}@@ -43,7 +46,7 @@ final class LifetimeStats {/// True when the biggest cleanup differs from the total. While the two are equal, as after the first/// cleanup, showing both would say the same thing twice.- var hasABiggestCleanUp: Bool { biggestCleanUp > 0 && biggestCleanUp != bytesFreed }+ var hasABiggestCleanUp: Bool { biggestCleanUp.known > 0 && biggestCleanUp != bytesFreed }/// The date `bundle` was installed, which is the date it was added to its folder.///@@ -56,19 +59,22 @@ final class LifetimeStats {}/// Adds a removal to the totals. Apps are counted by the bundles that moved, not by batch: five apps- /// removed together count as five, and an app reset, which moves settings but no bundle, counts as none.+ /// removed together count as five, and an app reset, which moves settings but no bundle, counts as none. An+ /// item missing from `sizes` was not measured.func add(_ result: TrashResult, sizes: [URL: Int64]) {guard !result.trashed.isEmpty else { return }- let freed = result.trashed.reduce(Int64(0)) { $0.addingCapped(sizes[$1.originalURL] ?? 0) }- bytesFreed = bytesFreed.addingCapped(freed)+ let freed = SizeTotal(result.trashed.map { sizes[$0.originalURL] })+ bytesFreed = SizeTotal(known: bytesFreed.known.addingCapped(freed.known), isComplete: bytesFreed.isComplete && freed.isComplete)itemsRemoved = itemsRemoved.addingCapped(result.trashed.count)// A helper app kept under a Library folder is a leftover, not an app the user removed.appsRemoved = appsRemoved.addingCapped(result.trashed.count { $0.originalURL.pathExtension.lowercased() == "app" && !$0.originalURL.pathComponents.contains("Library") })- biggestCleanUp = max(biggestCleanUp, freed)+ if freed.known > biggestCleanUp.known { biggestCleanUp = freed }- defaults.set(Int(bytesFreed), forKey: Key.bytes)+ defaults.set(Int(bytesFreed.known), forKey: Key.bytes)+ defaults.set(!bytesFreed.isComplete, forKey: Key.bytesIncomplete)defaults.set(itemsRemoved, forKey: Key.items)defaults.set(appsRemoved, forKey: Key.apps)- defaults.set(Int(biggestCleanUp), forKey: Key.biggest)+ defaults.set(Int(biggestCleanUp.known), forKey: Key.biggest)+ defaults.set(!biggestCleanUp.isComplete, forKey: Key.biggestIncomplete)}}diff --git a/Peel/Model/RemovalHistoryStore.swift b/Peel/Model/RemovalHistoryStore.swiftindex f8550a57..971bfd4e 100644--- a/Peel/Model/RemovalHistoryStore.swift+++ b/Peel/Model/RemovalHistoryStore.swift@@ -39,11 +39,11 @@ struct RemovalBatch: Identifiable, Hashable {return source}- var size: Int64 { records.totalSize }+ var size: SizeTotal { records.totalSize }var movedAnnouncement: AttributedString {- size > 0- ? AttributedString(localized: "Moved ^[\(records.count) item](inflect: true) to the Trash, \(size.byteCount).")+ size.isComplete && size.known > 0+ ? AttributedString(localized: "Moved ^[\(records.count) item](inflect: true) to the Trash, \(size.known.byteCount)."): AttributedString(localized: "Moved ^[\(records.count) item](inflect: true) to the Trash.")}}@@ -100,7 +100,8 @@ final class RemovalHistoryStore {}/// Records a removal in History. When Peel wrote the source itself, pass it in English along with a- /// `sourceKey`, so History can show it in the user's language (see `RemovalRecord.sourceKey`).+ /// `sourceKey`, so History can show it in the user's language (see `RemovalRecord.sourceKey`). An item missing+ /// from `sizes` is recorded as unknown.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.@@ -108,7 +109,7 @@ final class RemovalHistoryStore {guard !result.trashed.isEmpty else { return }let batch = UUID()let new = result.trashed.map {- RemovalRecord(batch: batch, item: $0, size: sizes[$0.originalURL] ?? 0, source: source, sourceKey: sourceKey, tool: tool.rawValue)+ RemovalRecord(batch: batch, item: $0, size: sizes[$0.originalURL], source: source, sourceKey: sourceKey, tool: tool.rawValue)}let moved = RemovalBatch(id: batch, source: source, sourceKey: sourceKey, tool: tool, date: .now, records: new)justMoved = moveddiff --git a/Peel/Views/AppDetailView.swift b/Peel/Views/AppDetailView.swiftindex 52084b18..1bc4e406 100644--- a/Peel/Views/AppDetailView.swift+++ b/Peel/Views/AppDetailView.swift@@ -571,10 +571,8 @@ struct AppDetailView: View {if let state = AppManagement.state(after: result, appBundles: [plan.app.url], movedByTheHelper: plan.privilegedURLs) {home.record(appManagement: state)}- var sizes = [plan.app.url: plan.appSize]- for leftover in plan.scan?.leftovers ?? [] {- sizes[leftover.url] = leftover.size- }+ let sizes = [URL: Int64](measured: [(plan.app.url, plan.isAppMeasured ? plan.appSize : nil)]+ + (plan.scan?.leftovers ?? []).map { ($0.url, $0.isMeasured ? $0.size : nil) })await history.record(result, tool: .applications, source: plan.app.name, sizes: sizes)if result.trashed.contains(where: { $0.originalURL == plan.app.url }) {diff --git a/Peel/Views/Developer/DeveloperDetailView.swift b/Peel/Views/Developer/DeveloperDetailView.swiftindex 44940266..38ba76bb 100644--- a/Peel/Views/Developer/DeveloperDetailView.swift+++ b/Peel/Views/Developer/DeveloperDetailView.swift@@ -57,7 +57,7 @@ struct DeveloperDetailView: View {result,tool: .developer,source: environment.name,- sizes: Dictionary(environment.locations.map { ($0.url, $0.size ?? 0) }, uniquingKeysWith: { first, _ in first })+ sizes: [URL: Int64](measured: environment.locations.map { ($0.url, $0.size) }))}// A nil result means nothing moved: one of the environment's apps was opened in the meantime.diff --git a/Peel/Views/History/HistoryDetailView.swift b/Peel/Views/History/HistoryDetailView.swiftindex 9ffbd615..1961816f 100644--- a/Peel/Views/History/HistoryDetailView.swift+++ b/Peel/Views/History/HistoryDetailView.swift@@ -48,7 +48,7 @@ struct HistoryDetailView: View {}/// The size of what can still be put back. Until the disk has answered, it is the batch's own total.- private var restorableSize: Int64 {+ private var restorableSize: SizeTotal {standing == nil ? batch.size : restorable.totalSize}@@ -167,7 +167,7 @@ struct HistoryDetailView: View {} trailing: {// VoiceOver reads the figure and its caption as one element, since `TotalLabel` combines them.TotalLabel(- bytes: restorableSize,+ total: restorableSize,caption: standing == nil ? Text("moved") : Text("to put back"))}diff --git a/Peel/Views/History/HistoryList.swift b/Peel/Views/History/HistoryList.swiftindex 9e2888d5..19501b48 100644--- a/Peel/Views/History/HistoryList.swift+++ b/Peel/Views/History/HistoryList.swift@@ -105,7 +105,7 @@ private struct HistoryBatchRow: View {} details: {HStack(spacing: 6) {Text("^[\(batch.records.count) item](inflect: true)")- Text(verbatim: batch.size.byteCount)+ Text(verbatim: batch.size.text).monospacedDigit()Text(batch.date, format: .relative(presentation: .named)).help(Text(batch.date, format: .dateTime.day().month(.wide).year().hour().minute()))diff --git a/Peel/Views/Home/HomeDeviceCard.swift b/Peel/Views/Home/HomeDeviceCard.swiftindex b7f5ab36..3fb0d326 100644--- a/Peel/Views/Home/HomeDeviceCard.swift+++ b/Peel/Views/Home/HomeDeviceCard.swift@@ -15,23 +15,34 @@ struct DeviceSticker: View {let angle: Double/// The width of the label's longest word. A sticker narrower than this would break the word in two.@State private var longestWord: CGFloat = 0+ /// The width of `value` at its full size, such as "Over 12.3 GB", which a narrower sticker would shrink or cut.+ @State private var valueWidth: CGFloat = 0/// How far the label's last line sits above the sticker's bottom edge.@State private var labelRise: CGFloat = .infinityprivate static let labelFont = Font.system(.caption, design: .rounded, weight: .semibold)+ private static let valueFont = Font.system(size: 16, weight: .bold, design: .rounded)/// At least 62 points tall, and taller when the words need it. In a row, every sticker stretches to the- /// height of the tallest one. As wide as `width`, or wider when the words need it.+ /// height of the tallest one. As wide as `width`, or wider when the words or the figure need it.var body: some View {VStack(spacing: 0) {Text(value)- .font(.system(size: 16, weight: .bold, design: .rounded))+ .font(Self.valueFont).monospacedDigit().contentTransition(.numericText(value: amount ?? 0)).motion(value: value).lineLimit(1).minimumScaleFactor(0.65).padding(.horizontal, 5)+ .background {+ Text(value)+ .font(Self.valueFont)+ .monospacedDigit()+ .fixedSize()+ .hidden()+ .onGeometryChange(for: CGFloat.self) { $0.size.width } action: { valueWidth = $0 }+ }Text(label).font(Self.labelFont).multilineTextAlignment(.center)@@ -55,9 +66,10 @@ struct DeviceSticker: View {private nonisolated static let space = "sticker"- /// The width before `curveRoom`: `width`, or the longest word with 5 points on each side if that is wider.+ /// The width before `curveRoom`: `width`, or the longest word or the figure with 5 points on each side if+ /// that is wider.private var wordsWidth: CGFloat {- max(width, ceil(longestWord) + 10)+ max(width, ceil(longestWord) + 10, ceil(valueWidth) + 10)}/// Extra width that keeps the clipping curve of a round sticker 3 points clear of the longest word on thediff --git a/Peel/Views/Home/HomeView.swift b/Peel/Views/Home/HomeView.swiftindex 16bb51bf..f559d72a 100644--- a/Peel/Views/Home/HomeView.swift+++ b/Peel/Views/Home/HomeView.swift@@ -117,7 +117,7 @@ struct HomeContent: View {/// removal is shown only in the menu bar panel, since a fourth sticker doesn't fit the column.private var totals: some View {HStack(spacing: 10) {- DeviceSticker(value: stats.bytesFreed.byteCount, amount: Double(stats.bytesFreed), label: "Moved to Trash", fill: Album.orange, ink: .white, width: 86, radius: 16, angle: -3)+ DeviceSticker(value: stats.bytesFreed.text, amount: Double(stats.bytesFreed.known), label: "Moved to Trash", fill: Album.orange, ink: .white, width: 86, radius: 16, angle: -3)DeviceSticker(value: stats.appsRemoved.shortCount,amount: Double(stats.appsRemoved),diff --git a/Peel/Views/Installers/InstallerDetailView.swift b/Peel/Views/Installers/InstallerDetailView.swiftindex 2c9ad210..29d43380 100644--- a/Peel/Views/Installers/InstallerDetailView.swift+++ b/Peel/Views/Installers/InstallerDetailView.swift@@ -96,7 +96,7 @@ struct InstallerDetailView: View {Button("Move to Trash") {Task {// Sizes are read before the move: the rescan after it does not list the items that moved.- let sizes = Dictionary(items.map { ($0.url, $0.size ?? 0) }, uniquingKeysWith: { first, _ in first })+ let sizes = [URL: Int64](measured: items.map { ($0.url, $0.size) })let result = await installers.removeSelected(in: kind, installedApps: library.apps) { result inawait history.record(result, tool: .installers, source: kind.title.inEnglish, sourceKey: "installers.\(kind.rawValue)", sizes: sizes)}diff --git a/Peel/Views/MenuBarPanel.swift b/Peel/Views/MenuBarPanel.swiftindex babde193..8aa9b150 100644--- a/Peel/Views/MenuBarPanel.swift+++ b/Peel/Views/MenuBarPanel.swift@@ -65,10 +65,10 @@ struct MenuBarPanel: View {private var hero: some View {VStack(spacing: 8) {- Text(stats.bytesFreed.byteCount)+ Text(stats.bytesFreed.text).font(.system(size: 50, weight: .bold, design: .rounded)).monospacedDigit()- .contentTransition(.numericText(value: Double(stats.bytesFreed)))+ .contentTransition(.numericText(value: Double(stats.bytesFreed.known))).motion(value: stats.bytesFreed).minimumScaleFactor(0.6).lineLimit(1)@@ -88,7 +88,7 @@ struct MenuBarPanel: View {row("doc.on.doc", stats.itemsRemoved == 1 ? "File removed" : "Files removed", stats.itemsRemoved.shortCount, amount: stats.itemsRemoved)if stats.hasABiggestCleanUp {Divider().padding(.leading, Self.wordsInset)- row("internaldrive", "Biggest removal", stats.biggestCleanUp.byteCount, amount: stats.biggestCleanUp)+ row("internaldrive", "Biggest removal", stats.biggestCleanUp.text, amount: stats.biggestCleanUp.known)}updates}diff --git a/Peel/Views/Orphans/OrphanDetailView.swift b/Peel/Views/Orphans/OrphanDetailView.swiftindex 02a4aba0..6cc0044e 100644--- a/Peel/Views/Orphans/OrphanDetailView.swift+++ b/Peel/Views/Orphans/OrphanDetailView.swift@@ -126,7 +126,7 @@ struct OrphanDetailView: View {let result = await orphans.removeSelected(in: group, installedApps: library.apps)outcome.report(result)// History is written before the rescan, which can take a while: it is how the user puts back what just moved.- await history.record(result, tool: .orphans, source: group.identifier, sizes: Dictionary(group.items.map { ($0.url, $0.size ?? 0) }, uniquingKeysWith: { first, _ in first }))+ await history.record(result, tool: .orphans, source: group.identifier, sizes: [URL: Int64](measured: group.items.map { ($0.url, $0.size) }))await orphans.refresh(from: library)}}diff --git a/Peel/Views/Packages/ForgetReceiptDialog.swift b/Peel/Views/Packages/ForgetReceiptDialog.swiftindex 8dd10d85..add00ad4 100644--- a/Peel/Views/Packages/ForgetReceiptDialog.swift+++ b/Peel/Views/Packages/ForgetReceiptDialog.swift@@ -21,7 +21,11 @@ struct ForgetReceiptDialog: ViewModifier {if !result.failures.isEmpty {failure = result.failures.map { $0.url.abbreviatedPath }.joined(separator: "\n")}- await history.record(result, tool: .packages, source: receipt.identifier, sizes: [:])+ var sizes: [URL: Int64] = [:]+ for item in result.trashed {+ sizes[item.originalURL] = await FileSize.allocatedSize(of: item.trashedURL)+ }+ await history.record(result, tool: .packages, source: receipt.identifier, sizes: sizes)await rescan()}}diff --git a/Peel/Views/Packages/PackageDetailView.swift b/Peel/Views/Packages/PackageDetailView.swiftindex a0b71270..ee613c5f 100644--- a/Peel/Views/Packages/PackageDetailView.swift+++ b/Peel/Views/Packages/PackageDetailView.swift@@ -92,7 +92,7 @@ struct PackageDetailView: View {result,tool: .packages,source: receipt.identifier,- sizes: Dictionary(receipt.items.map { ($0.url, $0.size ?? 0) }, uniquingKeysWith: { first, _ in first })+ sizes: [URL: Int64](measured: receipt.items.map { ($0.url, $0.size) }))}outcome.report(result)diff --git a/Peel/Views/Plugins/PluginDetailView.swift b/Peel/Views/Plugins/PluginDetailView.swiftindex f190ac89..fcd42c14 100644--- a/Peel/Views/Plugins/PluginDetailView.swift+++ b/Peel/Views/Plugins/PluginDetailView.swift@@ -97,7 +97,7 @@ struct PluginDetailView: View {Button("Move to Trash") {Task {let result = await plugins.moveToTrash(plugin) { result in- await history.record(result, tool: .plugins, source: plugin.name, sizes: [plugin.url: plugin.size ?? 0])+ await history.record(result, tool: .plugins, source: plugin.name, sizes: [URL: Int64](measured: [(plugin.url, plugin.size)]))}outcome.report(result)}diff --git a/Peel/Views/Projects/ProjectDetailView.swift b/Peel/Views/Projects/ProjectDetailView.swiftindex 68d7f848..515ca07a 100644--- a/Peel/Views/Projects/ProjectDetailView.swift+++ b/Peel/Views/Projects/ProjectDetailView.swift@@ -86,7 +86,7 @@ struct ProjectDetailView: View {result,tool: .projects,source: group.project.lastPathComponent,- sizes: Dictionary(group.artifacts.map { ($0.url, $0.size ?? 0) }, uniquingKeysWith: { first, _ in first })+ sizes: [URL: Int64](measured: group.artifacts.map { ($0.url, $0.size) }))}outcome.report(result)diff --git a/Peel/Views/RemovalBar.swift b/Peel/Views/RemovalBar.swiftindex deb9d7b6..45dc52c7 100644--- a/Peel/Views/RemovalBar.swift+++ b/Peel/Views/RemovalBar.swift@@ -34,7 +34,7 @@ struct RemovalBar: View {Text(notice.words).foregroundStyle(.secondary)} else if let moved {- Text(moved.size > 0 ? moved.size.byteCount : String(inflecting: "^[\(moved.records.count) item](inflect: true)"))+ Text(moved.size.known > 0 ? moved.size.text : String(inflecting: "^[\(moved.records.count) item](inflect: true)")).font(.barFigure).monospacedDigit()Text("Moved")diff --git a/Peel/Views/ResetSheet.swift b/Peel/Views/ResetSheet.swiftindex ff188532..1cd87159 100644--- a/Peel/Views/ResetSheet.swift+++ b/Peel/Views/ResetSheet.swift@@ -316,6 +316,6 @@ struct ResetSheet: View {}private var sizes: [URL: Int64] {- Dictionary(plan.items.map { ($0.url, $0.size ?? 0) }, uniquingKeysWith: { first, _ in first })+ [URL: Int64](measured: plan.items.map { ($0.url, $0.size) })}}diff --git a/Peel/Views/Settings/SavedSettingsSection.swift b/Peel/Views/Settings/SavedSettingsSection.swiftindex 74faf76a..7f65b3da 100644--- a/Peel/Views/Settings/SavedSettingsSection.swift+++ b/Peel/Views/Settings/SavedSettingsSection.swift@@ -121,11 +121,13 @@ struct SavedSettingsSection: View {private func moveToTrash(_ copy: PreferenceBackup.Copy, named name: String) async {workingOn = copy.iddefer { workingOn = nil }+ // Measured before the move, since nothing is left at that path after it.+ let size = await FileSize.allocatedSize(of: copy.folder)let result = await TrashService(exclusions: ExclusionsStore.shared.exclusions).trash([copy.folder])if let reason = result.failures.first?.reason {failure = Failure(title: String(localized: "The copy couldn’t be moved to the Trash."), message: reason.explanation)}- await history.record(result, tool: .applications, source: name, sizes: [:])+ await history.record(result, tool: .applications, source: name, sizes: [URL: Int64](measured: [(copy.folder, size)]))reload()}diff --git a/SAFETY.md b/SAFETY.mdindex 58ad9c04..a7b60ef4 100644--- a/SAFETY.md+++ b/SAFETY.md@@ -136,9 +136,9 @@ move, or one that needs the helper while it cannot act.Never selected for you, even when found: model weights, virtual environments, `/Users/Shared` (it belongs toevery account, not just yours), a project you worked on this week, a folder with a repository, a wallet, or asigning key inside, a folder macOS would not let Peel read, and a folder Peel could not measure in time. Those-last two are shown with their size as "Unknown", never as zero, in every tool: a folder too big to read quickly-may be exactly the one with work inside, and nothing is selected for you without saying how much it is. A total-that leaves such a folder out reads "Over" what is known.+last two are shown with their size as "Unknown", never as zero, in every tool and in History once they are+moved: a folder too big to read quickly may be exactly the one with work inside, and nothing is selected for you+without saying how much it is. A total that leaves such a folder out reads "Over" what is known.In Duplicates, one copy of every group always stays, and a file that changed since the scan is refused.