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
Give Duplicates a Select menu without Select All
Țugui Dragoșc7fc77bed2f1
diff --git a/GUIDE.md b/GUIDE.mdindex 8eaa2345..191951db 100644--- a/GUIDE.md+++ b/GUIDE.md@@ -47,7 +47,8 @@ and how to get it, [SAFETY.md](SAFETY.md) what it protects, [PRIVACY.md](PRIVACYwhat it left once it has. If the app is still open after 10 seconds, Peel offers Force Quit, which loses what theapp hasn't saved.- **The Select menu** has Select Recommended, Select All, and Deselect All. Select All selects everything you can- select, what Peel holds back included, and asks first when that takes anything Peel doesn't recommend.+ select, what Peel holds back included, and asks first when that takes anything Peel doesn't recommend. In+ Duplicates it has no Select All, since one copy of every group always stays.- **Several ways in.** Choose an app in the list, drop one on Peel's Dock icon, select several apps at once, orControl-click an app in Finder and choose Uninstall with Peel, once the Finder extension is on in SystemSettings. With Watch the Trash on, Peel notices when you drag an app to the Trash yourself and offers to cleardiff --git a/Packages/PeelCore/Sources/PeelCore/Duplicates/Duplicates.swift b/Packages/PeelCore/Sources/PeelCore/Duplicates/Duplicates.swiftindex b8527982..a15c516c 100644--- a/Packages/PeelCore/Sources/PeelCore/Duplicates/Duplicates.swift+++ b/Packages/PeelCore/Sources/PeelCore/Duplicates/Duplicates.swift@@ -210,6 +210,28 @@ public struct DuplicateScan: Sendable {Self.keepingOne(of: folderGroups.map { $0.folders.map(\.url) }, selection)}+ /// The selection with what Peel suggests in `groups` and `folderGroups`, and nothing else of theirs. What is+ /// selected in the others stays.+ public func selectingRecommended(+ in groups: [DuplicateGroup], _ folderGroups: [DuplicateFolderGroup], files: Set<URL>, folders: Set<URL>+ ) -> (files: Set<URL>, folders: Set<URL>) {+ let cleared = deselecting(groups, folderGroups, files: files, folders: folders)+ return (+ cleared.files.union(groups.flatMap(\.suggestedFiles).map(\.url)),+ cleared.folders.union(folderGroups.flatMap { $0.folders.dropFirst() }.map(\.url))+ )+ }++ /// The selection with nothing in `groups` and `folderGroups`. What is selected in the others stays.+ public func deselecting(+ _ groups: [DuplicateGroup], _ folderGroups: [DuplicateFolderGroup], files: Set<URL>, folders: Set<URL>+ ) -> (files: Set<URL>, folders: Set<URL>) {+ (+ files.subtracting(groups.flatMap(\.files).map(\.url)),+ folders.subtracting(folderGroups.flatMap(\.folders).map(\.url))+ )+ }+/// Whether the copy at `url` may be selected or deselected, given the `selected` copies of its group: one copy of/// every group always stays, so the last one not selected cannot be.public static func canChange(_ url: URL, among copies: [URL], selected: Set<URL>) -> Bool {diff --git a/Packages/PeelCore/Tests/PeelCoreTests/DuplicateFinderTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/DuplicateFinderTests.swiftindex b75f5a07..028c2164 100644--- a/Packages/PeelCore/Tests/PeelCoreTests/DuplicateFinderTests.swift+++ b/Packages/PeelCore/Tests/PeelCoreTests/DuplicateFinderTests.swift@@ -748,6 +748,29 @@ struct DuplicateFinderTests {#expect(kept(files.groups.first?.files.first?.url) == kept(onTheMac))}+ /// Select Recommended and Deselect All change only the groups they are asked about, which a search narrows:+ /// what is selected in the others stays.+ @Test func selectsWhatItRecommendsOnlyInTheGroupsShown() async throws {+ let directory = try TemporaryDirectory()+ let first = randomData(count: 4_000)+ let second = randomData(count: 4_000)+ for name in ["a", "b", "c"] {+ try directory.file("home/Documents/first-\(name).bin", contents: first)+ try directory.file("home/Pictures/second-\(name).bin", contents: second)+ }+ let result = try await scan(directory)+ let shown = try #require(result.groups.first { $0.files.first?.url.lastPathComponent.hasPrefix("first") == true })+ let other = try #require(result.groups.first { $0 != shown })+ let otherSelected = Set(other.files.map(\.url))++ let recommended = result.selectingRecommended(in: [shown], [], files: otherSelected, folders: [])+ #expect(recommended.files == otherSelected.union(shown.suggestedFiles.map(\.url)))+ #expect(shown.suggestedFiles.count == 2)++ let none = result.deselecting([shown], [], files: recommended.files, folders: [])+ #expect(none.files == otherSelected)+ }+@Test func stopsWhenCanceled() async throws {let directory = try TemporaryDirectory()try directory.file("home/Documents/a.txt", contents: Data("same".utf8))diff --git a/Peel/Model/DuplicateLibrary.swift b/Peel/Model/DuplicateLibrary.swiftindex c88ef811..33b22a3f 100644--- a/Peel/Model/DuplicateLibrary.swift+++ b/Peel/Model/DuplicateLibrary.swift@@ -270,6 +270,19 @@ final class DuplicateLibrary {group.folders.filter { selectedFolders.contains($0.url) }.map(\.reclaimableSize).cappedSum}+ /// Selects in `groups` and `folderGroups` what Peel suggests, as after a scan, and nothing else of theirs.+ func selectRecommended(in groups: [DuplicateGroup], _ folderGroups: [DuplicateFolderGroup]) {+ guard let scan else { return }+ let chosen = scan.selectingRecommended(in: groups, folderGroups, files: selectedURLs, folders: selectedFolders)+ select(chosen.files, folders: chosen.folders)+ }++ func deselectAll(in groups: [DuplicateGroup], _ folderGroups: [DuplicateFolderGroup]) {+ guard let scan else { return }+ let chosen = scan.deselecting(groups, folderGroups, files: selectedURLs, folders: selectedFolders)+ select(chosen.files, folders: chosen.folders)+ }+/// Selects exactly `files` and `folders`.private func select(_ files: Set<URL>, folders: Set<URL>) {selectedURLs = filesdiff --git a/Peel/Views/Duplicates/DuplicateList.swift b/Peel/Views/Duplicates/DuplicateList.swiftindex 860110c8..10db289a 100644--- a/Peel/Views/Duplicates/DuplicateList.swift+++ b/Peel/Views/Duplicates/DuplicateList.swift@@ -120,6 +120,9 @@ struct DuplicateList: View {// Attached outside the `if`, so the column has a toolbar item before a scan as well. Without one, the// column gets no title bar section of its own, and the dividers between columns stop below the title bar..toolbar {+ ToolbarItem {+ selectMenu+ }ToolbarItem {Button("Scan Settings", systemImage: "slider.horizontal.3") { isShowingSettings = true }.help(Text("Scan Settings"))@@ -184,6 +187,29 @@ struct DuplicateList: View {.joined(separator: "\n\n")}+ /// Select Recommended and Deselect All over the groups the list shows. There is no Select All: one copy of every+ /// group always stays.+ private var selectMenu: some View {+ let scan = duplicates.scan+ let groups = scan?.groups.filter { $0.matches(searchText) } ?? []+ let folderGroups = scan?.folderGroups.filter { $0.matches(searchText) } ?? []+ let selected = (files: duplicates.selectedURLs, folders: duplicates.selectedFolders)+ let recommended = scan?.selectingRecommended(+ in: groups, folderGroups, files: selected.files, folders: selected.folders+ )+ let none = scan?.deselecting(groups, folderGroups, files: selected.files, folders: selected.folders)+ return Menu {+ Button("Select Recommended") { duplicates.selectRecommended(in: groups, folderGroups) }+ .disabled(recommended.map { $0 == selected } ?? true)+ Button("Deselect All") { duplicates.deselectAll(in: groups, folderGroups) }+ .disabled(none.map { $0 == selected } ?? true)+ } label: {+ ToolbarMenuLabel(title: "Select", systemImage: "checklist")+ }+ .disabled(groups.isEmpty && folderGroups.isEmpty || duplicates.isRemoving)+ .help(Text("Select on every page in the list"))+ }+/// A new scan clears what the last one found, so it asks first when there is something to lose.private func requestScan() {if let scan = duplicates.scan, !scan.groups.isEmpty || !scan.folderGroups.isEmpty {