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
Tell a removal History couldn't record when it happens
Țugui Dragoș07ffe78a584d
diff --git a/Localization/Peel/Localizable.xcstrings b/Localization/Peel/Localizable.xcstringsindex c832d22e..79badcef 100644--- a/Localization/Peel/Localizable.xcstrings+++ b/Localization/Peel/Localizable.xcstrings@@ -49432,6 +49432,112 @@}}},+ "History couldn’t record this removal." : {+ "localizations" : {+ "cs" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Historie nemohla zaznamenat toto odstranění."+ }+ },+ "de" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Der Verlauf konnte nicht aufzeichnen, was gerade entfernt wurde."+ }+ },+ "es" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Historial no ha podido registrar esta eliminación."+ }+ },+ "fr" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "L’Historique n’a pas pu enregistrer cette suppression."+ }+ },+ "it" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "La Cronologia non è riuscita a registrare questa rimozione."+ }+ },+ "ja" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "今回ゴミ箱に入れた項目を履歴に記録できませんでした。"+ }+ },+ "ko" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "이번 제거 내역을 기록에 저장할 수 없습니다."+ }+ },+ "nl" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Geschiedenis kon deze verwijdering niet registreren."+ }+ },+ "pl" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Historia nie mogła zapisać tego przeniesienia do Kosza."+ }+ },+ "pt" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "O Histórico não conseguiu registrar esta remoção."+ }+ },+ "ro" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Istoricul nu a putut înregistra această eliminare."+ }+ },+ "ru" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Не удалось записать это удаление в Историю."+ }+ },+ "sv" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Den här borttagningen kunde inte föras in i Historik."+ }+ },+ "tr" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Geçmiş, bu kaldırma işlemini kaydedemedi."+ }+ },+ "uk" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Історії не вдалося записати це вилучення."+ }+ },+ "zh-Hans" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "“历史记录”未能记录此次移除。"+ }+ },+ "zh-Hant" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "「歷史記錄」無法記錄這次移除。"+ }+ }+ }+ },"History keeps what it can’t see until Peel can look again." : {"localizations" : {"cs" : {@@ -187314,6 +187420,112 @@}}},+ "What moved is in the Trash: drag it back out in Finder if you need it." : {+ "localizations" : {+ "cs" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Co se přesunulo, je v koši: pokud to potřebujete, přetáhněte to ve Finderu zpět ven."+ }+ },+ "de" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Was verschoben wurde, liegt im Papierkorb: Ziehe es im Finder wieder heraus, wenn du es brauchst."+ }+ },+ "es" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Lo que se ha trasladado está en la papelera: si lo necesitas, sácalo arrastrándolo en el Finder."+ }+ },+ "fr" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Ce qui a été déplacé se trouve dans la corbeille : faites-le glisser hors de la corbeille dans le Finder si vous en avez besoin."+ }+ },+ "it" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Ciò che è stato spostato è nel Cestino: se ti serve, trascinalo fuori nel Finder."+ }+ },+ "ja" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "移動した項目はゴミ箱にあります。必要な場合は、Finderでドラッグして取り出してください。"+ }+ },+ "ko" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "이동한 항목은 휴지통에 있습니다. 필요하면 Finder에서 휴지통 밖으로 드래그하여 꺼내십시오."+ }+ },+ "nl" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Wat is verplaatst, staat in de prullenmand: sleep het in Finder er weer uit als je het nodig hebt."+ }+ },+ "pl" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "To, co przeniesiono, jest w Koszu: wyciągnij to z Kosza w Finderze, jeśli tego potrzebujesz."+ }+ },+ "pt" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "O que foi movido está no Lixo: arraste-o para fora no Finder se precisar."+ }+ },+ "ro" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Ce s‑a mutat se află în Coș: în Finder, îl puteți trage afară de acolo dacă aveți nevoie de el."+ }+ },+ "ru" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "То, что было перемещено, находится в Корзине: если оно Вам нужно, в Finder перетащите его из Корзины обратно."+ }+ },+ "sv" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Det som flyttades ligger i papperskorgen: dra ut det igen i Finder om du behöver det."+ }+ },+ "tr" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Taşınanlar Çöp Sepeti’nde: ihtiyacınız varsa onları Finder’da dışarı sürükleyin."+ }+ },+ "uk" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Те, що переміщено, лежить у Смітнику: якщо воно вам потрібне, у Finder перетягніть його зі Смітника назад."+ }+ },+ "zh-Hans" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "已移走的内容在废纸篓中:如果你需要,请在“访达”中将它拖出来。"+ }+ },+ "zh-Hant" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "已移動的項目在「垃圾桶」中:如有需要,請在Finder中將它們拖出來。"+ }+ }+ }+ },"What sandboxed apps, such as those from the App Store, cached or left as temporary files in their own containers, and cached in the ones they share with apps from the same maker. What an open app uses stays, and the caches of Apple’s own apps are listed but never selected." : {"localizations" : {"cs" : {diff --git a/Peel/Model/RemovalHistoryStore.swift b/Peel/Model/RemovalHistoryStore.swiftindex e23514c2..d0473c11 100644--- a/Peel/Model/RemovalHistoryStore.swift+++ b/Peel/Model/RemovalHistoryStore.swift@@ -91,6 +91,8 @@ struct RemovalInProgress {/// never shares the removal's.let refusals = UUID()fileprivate(set) var records: [RemovalRecord] = []+ /// True once History couldn't record a part of it, so Put Back has nothing to go on for what moved.+ fileprivate(set) var wasNotRecorded = false}/// What Peel was asked to move in one removal and did not.@@ -111,8 +113,10 @@ nonisolated struct RefusalBatch: Identifiable, Hashable {@Observablefinal class RemovalHistoryStore {- private let log = RemovalLog()- private let refusals = RefusalLog()+ private let log: RemovalLog+ private let refusals: RefusalLog+ /// Where a removal History couldn't record is told, with whatever else the removal left to tell.+ private let outcome: RemovalOutcome?/// Read again here once History has counted a removal, rather than by each tool.var stats: LifetimeStats?/// The last batch moved, for Undo. `@Environment(\.undoManager)` is nil in an app with no documents,@@ -164,6 +168,12 @@ final class RemovalHistoryStore {refusalBatches.first { $0.id == selection }}+ init(log: RemovalLog = RemovalLog(), refusals: RefusalLog = RefusalLog(), outcome: RemovalOutcome? = nil) {+ self.log = log+ self.refusals = refusals+ self.outcome = outcome+ }+func load() async {await apply(await log.load())await loadRefusals()@@ -243,7 +253,9 @@ final class RemovalHistoryStore {if !result.trashed.isEmpty {let new = part.records(of: result, sizes: sizes, sharingStorage: sharingStorage, batch: removal.batch)removal.records += new- await apply(await log.add(new))+ let added = await log.add(new)+ if added.records == nil { removal.wasNotRecorded = true }+ await apply(added)}// Refusals are logged whether or not anything moved: a removal where nothing moved is the one most worth a// record.@@ -263,6 +275,7 @@ final class RemovalHistoryStore {/// totals, and Undo.func finish(_ removal: RemovalInProgress) {guard !removal.records.isEmpty else { return }+ if removal.wasNotRecorded { outcome?.noteHistoryCouldNotRecord() }let parts = RemovalPart.of(removal.records.map { ($0.date, $0.part) })let moved = RemovalBatch(id: removal.batch, parts: parts, date: .now, records: removal.records)justMoved = moveddiff --git a/Peel/Model/RemovalOutcome.swift b/Peel/Model/RemovalOutcome.swiftindex f5ed6552..1cf73262 100644--- a/Peel/Model/RemovalOutcome.swift+++ b/Peel/Model/RemovalOutcome.swift@@ -27,11 +27,18 @@ final class RemovalOutcome {private(set) var leftForAnAdministrator = 0/// The lines of the shell startup files that still name what moved, which the person edits.private(set) var shellReferences: [ShellReferences.Reference] = []+ /// True when History couldn't record the removal, so Put Back has nothing to go on for what moved.+ private(set) var historyCouldNotRecord = falseprivate(set) var movedCount = 0var isEmpty: Bool {failures.isEmpty && privacy.isEmpty && appsToQuit.isEmpty && driversAwaitingARestart.isEmpty&& appsStartingFromTheTrash.isEmpty && leftForAnAdministrator == 0 && shellReferences.isEmpty+ && !historyCouldNotRecord+ }++ func noteHistoryCouldNotRecord() {+ historyCouldNotRecord = true}/// Keeps what the removal could not do, what a restart or an emptied Trash finishes, and what stays for an@@ -77,5 +84,6 @@ final class RemovalOutcome {appsStartingFromTheTrash = []leftForAnAdministrator = 0shellReferences = []+ historyCouldNotRecord = false}}diff --git a/Peel/PeelApp.swift b/Peel/PeelApp.swiftindex c8a7e5ba..fb939d0f 100644--- a/Peel/PeelApp.swift+++ b/Peel/PeelApp.swift@@ -89,7 +89,8 @@ struct PeelApp: App {_helper = State(initialValue: helper)_home = State(initialValue: HomeModel(helper: helper))- let (library, history, outcome) = (AppLibrary(), RemovalHistoryStore(), RemovalOutcome())+ let outcome = RemovalOutcome()+ let (library, history) = (AppLibrary(), RemovalHistoryStore(outcome: outcome))let (orphans, space, developer, projects) = (OrphanLibrary(), SpaceLibrary(), DeveloperLibrary(), ProjectLibrary())diff --git a/Peel/Views/RemovalFailureAlert.swift b/Peel/Views/RemovalFailureAlert.swiftindex 6ef14081..4e64c2a1 100644--- a/Peel/Views/RemovalFailureAlert.swift+++ b/Peel/Views/RemovalFailureAlert.swift@@ -74,6 +74,9 @@ struct RemovalFailureAlert: ViewModifier {}private var title: Text {+ if outcome.historyCouldNotRecord {+ return Text("History couldn’t record this removal.")+ }if #available(macOS 27, *), !outcome.appsStartingFromTheTrash.isEmpty, outcome.failures.isEmpty,outcome.appsToQuit.isEmpty, outcome.privacy.isEmpty {return outcome.driversAwaitingARestart.isEmpty@@ -99,7 +102,9 @@ struct RemovalFailureAlert: ViewModifier {}static func message(for outcome: RemovalOutcome) -> String {- var lines = shortened(quitLines(outcome))+ var lines = outcome.historyCouldNotRecord+ ? [String(localized: "What moved is in the Trash: drag it back out in Finder if you need it.")] : []+ 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)") } }diff --git a/PeelTests/RemovalOutcomeTests.swift b/PeelTests/RemovalOutcomeTests.swiftindex cec5b020..7305e310 100644--- a/PeelTests/RemovalOutcomeTests.swift+++ b/PeelTests/RemovalOutcomeTests.swift@@ -16,4 +16,33 @@ struct RemovalOutcomeTests {outcome.clear()#expect(outcome.isEmpty)}++ @Test func tellsOfARemovalHistoryCouldNotRecord() async throws {+ let folder = FileManager.default.temporaryDirectory.appending(path: "PeelTests-\(UUID().uuidString)")+ let peel = folder.appending(path: "Peel", directoryHint: .isDirectory)+ try FileManager.default.createDirectory(at: peel, withIntermediateDirectories: true)+ try Data("[]".utf8).write(to: peel.appending(path: "removals.json"))+ try FileManager.default.setAttributes(+ [.posixPermissions: 0o555], ofItemAtPath: peel.path(percentEncoded: false)+ )+ defer {+ try? FileManager.default.setAttributes(+ [.posixPermissions: 0o755], ofItemAtPath: peel.path(percentEncoded: false)+ )+ try? FileManager.default.removeItem(at: folder)+ }+ let outcome = RemovalOutcome()+ let history = RemovalHistoryStore(+ log: RemovalLog(url: peel.appending(path: "removals.json")),+ refusals: RefusalLog(url: folder.appending(path: "refusals.json")),+ outcome: outcome+ )+ let item = #"{"originalURL": "file:///Users/me/Cache", "trashedURL": "file:///Users/me/.Trash/Cache", "date": 0}"#+ let moved = try JSONDecoder().decode(TrashedItem.self, from: Data(item.utf8))++ await history.record(TrashResult(trashed: [moved]), tool: .developer, source: "Xcode", sizes: [:])++ #expect(outcome.historyCouldNotRecord && !outcome.isEmpty)+ #expect(RemovalFailureAlert.message(for: outcome).hasPrefix("What moved is in the Trash"))+ }}