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.

Take rows that wait for the helper out of Orphaned Files' selection when it stops

Țugui Dragoș42b2a0f2c014
diff --git a/Peel/Model/OrphanLibrary.swift b/Peel/Model/OrphanLibrary.swift
index fc832737..c63c6b98 100644
--- a/Peel/Model/OrphanLibrary.swift
+++ b/Peel/Model/OrphanLibrary.swift
@@ -35,6 +35,18 @@ final class OrphanLibrary {
return (scan.forAnAdministrator.isEmpty ? [] : [.forAnAdministrator]) + scan.groups.map { .group($0.id) }
}
+ /// Takes out of the selection what waits for the helper while the helper can't act: its checkbox is off then, and
+ /// a move would only refuse it, so it would stay selected, and counted, for every move after.
+ func follow(canUseHelper: Bool) {
+ let kept = Self.selection(selectedURLs, in: scan?.groups ?? [], canUseHelper: canUseHelper)
+ if kept != selectedURLs { selectedURLs = kept }
+ }
+
+ static func selection(_ selected: Set<URL>, in groups: [OrphanGroup], canUseHelper: Bool) -> Set<URL> {
+ guard !canUseHelper else { return selected }
+ return selected.subtracting(groups.flatMap(\.items).filter { $0.isLocked(canUseHelper: false) }.map(\.url))
+ }
+
func selected(in group: OrphanGroup) -> [OrphanItem] {
group.items.filter { selectedURLs.contains($0.url) }
}
diff --git a/Peel/PeelApp.swift b/Peel/PeelApp.swift
index 310913ba..163f9c0f 100644
--- a/Peel/PeelApp.swift
+++ b/Peel/PeelApp.swift
@@ -122,11 +122,12 @@ struct PeelApp: App {
))
}
- /// Keeps what Space selects in step with the helper whichever page is open, since its selection travels to the
- /// other storage pages.
+ /// Keeps what Space and Orphaned Files select in step with the helper whichever page is open, since their
+ /// selections travel to the other storage pages.
private func followHelper() async {
for await canAct in Observations({ helper.canAct }) {
space.follow(canUseHelper: canAct)
+ orphans.follow(canUseHelper: canAct)
}
}
diff --git a/PeelTests/OrphanPartsTests.swift b/PeelTests/OrphanPartsTests.swift
index ba413b5f..e3775467 100644
--- a/PeelTests/OrphanPartsTests.swift
+++ b/PeelTests/OrphanPartsTests.swift
@@ -22,3 +22,22 @@ struct OrphanPartsTests {
#expect(part.source == "Chat")
}
}
+
+@MainActor
+struct OrphanHelperTests {
+ @Test func whatWaitsForTheHelperLeavesTheSelectionWhileTheHelperCanNotAct() {
+ let preferences = OrphanItem(
+ url: URL(filePath: "/Library/Preferences/org.example.chat.plist"),
+ kind: .preferences, size: 10, modificationDate: nil, requiresPrivileges: true
+ )
+ let cache = OrphanItem(
+ url: URL(filePath: "/Users/me/Library/Caches/org.example.chat"),
+ kind: .caches, size: 10, modificationDate: nil, requiresPrivileges: false
+ )
+ let group = OrphanGroup(identifier: "org.example.chat", items: [preferences, cache])
+ let selected: Set<URL> = [preferences.url, cache.url]
+
+ #expect(OrphanLibrary.selection(selected, in: [group], canUseHelper: true) == selected)
+ #expect(OrphanLibrary.selection(selected, in: [group], canUseHelper: false) == [cache.url])
+ }
+}