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
Show Put Back's alert again when a second Put Back ends the same way
Țugui Dragoșb9ae9d372021
diff --git a/Peel/Model/RemovalHistoryStore.swift b/Peel/Model/RemovalHistoryStore.swiftindex f7bdf711..7362b3c0 100644--- a/Peel/Model/RemovalHistoryStore.swift+++ b/Peel/Model/RemovalHistoryStore.swift@@ -168,6 +168,8 @@ final class RemovalHistoryStore {/// sits in many batches.var selectedIDs: Set<RemovalRecord.ID> = []var failures: [RemovalRecord.ID: RestoreFailure] = [:]+ /// Counts the Put Backs History's page tells, so one that ends as the one before is told again.+ private(set) var toldPutBacks = 0/// Counts the times History was read again, by Reload or as Peel came forward, so a removal's page then looks in/// the Trash again with the records as they are now.private(set) var rereads = 0@@ -473,7 +475,10 @@ final class RemovalHistoryStore {restored.insert(record.id)}}- if tellingThePage { failures = problems }+ if tellingThePage {+ failures = problems+ toldPutBacks += 1+ }selectedIDs.subtract(restored)if !restored.isEmpty {keepUndoable(without: restored)diff --git a/Peel/Views/History/HistoryDetailView.swift b/Peel/Views/History/HistoryDetailView.swiftindex 5497c16f..200bf6a5 100644--- a/Peel/Views/History/HistoryDetailView.swift+++ b/Peel/Views/History/HistoryDetailView.swift@@ -76,8 +76,8 @@ struct HistoryDetailView: View {// reports the rest must stay.history.failures = [:]}- .onChange(of: history.failures) { _, all in- failures = batch.records.compactMap { record in all[record.id].map { (record, $0) } }+ .onChange(of: history.toldPutBacks) {+ failures = batch.records.compactMap { record in history.failures[record.id].map { (record, $0) } }isShowingFailures = !failures.isEmpty}.alert(diff --git a/PeelTests/RemovalHistoryStoreTests.swift b/PeelTests/RemovalHistoryStoreTests.swiftindex 3beeefc8..3922bf7d 100644--- a/PeelTests/RemovalHistoryStoreTests.swift+++ b/PeelTests/RemovalHistoryStoreTests.swift@@ -108,6 +108,28 @@ struct RemovalHistoryStoreTests {#expect(heard.words == ["Started History over.", "Started the Not Moved list over."])}+ @Test func tellsAPutBackThatEndsAsTheOneBefore() async throws {+ let folder = FileManager.default.temporaryDirectory.appending(path: "PeelTests-\(UUID().uuidString)")+ defer { try? FileManager.default.removeItem(at: folder) }+ let history = RemovalHistoryStore(+ log: RemovalLog(url: folder.appending(path: "removals.json")),+ refusals: RefusalLog(url: folder.appending(path: "refusals.json")),+ knowsTheExclusions: { true },+ restoring: { items, _ in items.map { _ in .needsHelper } }+ )+ var removal = RemovalInProgress()+ let part = RemovalPart(source: "Example", sourceKey: nil, tool: Tool.developer.rawValue)+ await history.record(try moved("Driver"), part: part, sizes: [:], in: &removal)+ history.finish(removal)++ await history.restore(history.records, canUseHelper: false)+ let first = history.failures+ await history.restore(history.records, canUseHelper: false)++ #expect(history.failures == first)+ #expect(history.toldPutBacks == 2, "the second Put Back's alert never showed")+ }+@Test func saysWhenStartingOverCouldNotSetTheOldFileAside() async throws {let folder = FileManager.default.temporaryDirectory.appending(path: "PeelTests-\(UUID().uuidString)")let path = folder.path(percentEncoded: false)