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.

Tell every page when a Put Back brings something back

Țugui Dragoș5075f8c96563
diff --git a/Peel/Model/RemovalHistoryStore.swift b/Peel/Model/RemovalHistoryStore.swift
index 70cecbe4..f19e51e0 100644
--- a/Peel/Model/RemovalHistoryStore.swift
+++ b/Peel/Model/RemovalHistoryStore.swift
@@ -181,8 +181,9 @@ final class RemovalHistoryStore {
/// Counts the times a removal's page has to look in the Trash again: History read again, by Reload or as Peel came
/// forward, and a Put Back that brought something back, whatever History could write of it.
private(set) var trashLooks = 0
- /// Counts, for each tool, the Put Backs that brought back what it had moved, so its page lists them again.
- private(set) var putBack: [Tool: Int] = [:]
+ /// Counts the Put Backs that brought something back, which any page may list wherever it moved from, so each lists
+ /// again: a plug-in an uninstall moved comes back to Plug-ins' list too.
+ private(set) var putBacks = 0
/// The count each page last listed under, kept here so a page off screen at a Put Back lists it when it returns.
@ObservationIgnored private var listedAfterPutBack = ScannedRevisions()
@ObservationIgnored private var listedRefusals: [RefusalRecord] = []
@@ -246,7 +247,10 @@ final class RemovalHistoryStore {
/// Reads History before a removal's page looks in the Trash, so the page never looks with records `peel` changed.
private func readAgain() async {
+ let listed = Set(records.map(\.id))
await load()
+ // What left History meanwhile, `peel restore` may have put back.
+ if !listed.isSubset(of: records.map(\.id)) { putBacks += 1 }
trashLooks += 1
}
@@ -445,7 +449,7 @@ final class RemovalHistoryStore {
/// Whether a Put Back brought back what `tool` moved since its page last asked. False the first time it asks.
func needsRescanAfterPutBack(_ tool: Tool) -> Bool {
- listedAfterPutBack.needsRescan(tool.rawValue, at: putBack[tool, default: 0])
+ listedAfterPutBack.needsRescan(tool.rawValue, at: putBacks)
}
/// Takes the records `ids` names out of what Undo would put back, once they are back or gone from History.
@@ -544,9 +548,7 @@ final class RemovalHistoryStore {
selectedIDs.subtract(restored)
if !restored.isEmpty {
keepUndoable(without: restored)
- for tool in Set(ordered.filter { restored.contains($0.id) }.compactMap { Tool(rawValue: $0.tool) }) {
- putBack[tool, default: 0] += 1
- }
+ putBacks += 1
await apply(await log.remove(restored))
trashLooks += 1
// A move is announced, and so is its undoing: the rows only vanish from the list.
diff --git a/Peel/Views/ExclusionRescan.swift b/Peel/Views/ExclusionRescan.swift
index 71eeda76..ac21ee09 100644
--- a/Peel/Views/ExclusionRescan.swift
+++ b/Peel/Views/ExclusionRescan.swift
@@ -30,7 +30,7 @@ private struct PutBackRescan: ViewModifier {
let rescan: () async -> Void
func body(content: Content) -> some View {
- content.task(id: history.putBack[tool, default: 0]) {
+ content.task(id: history.putBacks) {
guard history.needsRescanAfterPutBack(tool) else { return }
await rescan()
}
diff --git a/Peel/Views/Intel/IntelList.swift b/Peel/Views/Intel/IntelList.swift
index 2e411e44..894e4601 100644
--- a/Peel/Views/Intel/IntelList.swift
+++ b/Peel/Views/Intel/IntelList.swift
@@ -115,6 +115,7 @@ struct IntelList: View {
Task { await intel.readAgain(installedApps: library.apps, knownSizes: library.sizes) }
}
.rescanOnExclusionChange("IntelList") { await scan() }
+ .rescanAfterPutBack(.intel) { await scan() }
}
private func phase(_ matching: [IntelFinding]) -> ScanPhase {
diff --git a/PeelTests/RemovalOutcomeTests.swift b/PeelTests/RemovalOutcomeTests.swift
index 4dcb21a4..3c01e94f 100644
--- a/PeelTests/RemovalOutcomeTests.swift
+++ b/PeelTests/RemovalOutcomeTests.swift
@@ -106,7 +106,23 @@ struct RemovalOutcomeTests {
#expect(history.undoTitle == nil)
}
- @Test func aPutBackTellsThePageOfTheToolThatMovedWhatCameBack() async throws {
+ @Test func whatPeelRestorePutBackIsListedAgainToo() async throws {
+ let folder = FileManager.default.temporaryDirectory.appending(path: "PeelTests-\(UUID().uuidString)")
+ defer { try? FileManager.default.removeItem(at: folder) }
+ let history = history(in: folder, outcome: RemovalOutcome())
+ await history.record(try moved(["Cache", "Other"]), tool: .plugins, source: "Plug-ins", sizes: [:])
+ #expect(!history.needsRescanAfterPutBack(.plugins))
+ let peel = RemovalLog(url: folder.appending(path: "removals.json"))
+
+ _ = await peel.remove([try #require(history.records.first).id])
+ await history.readAgainIfInUse()
+
+ #expect(history.needsRescanAfterPutBack(.plugins))
+ await history.readAgainIfInUse()
+ #expect(!history.needsRescanAfterPutBack(.plugins), "nothing left since")
+ }
+
+ @Test func aPutBackTellsEveryPageWhicheverMovedWhatCameBack() async throws {
let folder = FileManager.default.temporaryDirectory.appending(path: "PeelTests-\(UUID().uuidString)")
defer { try? FileManager.default.removeItem(at: folder) }
let history = history(in: folder, outcome: RemovalOutcome())
@@ -117,6 +133,6 @@ struct RemovalOutcomeTests {
#expect(history.needsRescanAfterPutBack(.plugins))
#expect(!history.needsRescanAfterPutBack(.plugins), "once it has listed again")
- #expect(!history.needsRescanAfterPutBack(.space))
+ #expect(history.needsRescanAfterPutBack(.space))
}
}