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.

Keep Rescan off for the whole of a Move to Trash

Țugui Dragoșa3fe4789e3d0
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 98f1db64..553d2fa5 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -739,6 +739,8 @@ its changes the way [Keep a Changelog](https://keepachangelog.com/) suggests.
buttons no longer move into its overflow menu for a moment.
- On macOS 27, closing the sidebar by dragging its edge keeps the divider between a list and its page in place.
- On macOS 26, sheets and alerts open and close faster on pages with section headers.
+- Rescan stays off for the whole of a Move to Trash across several pages. It flashed between them, could start a scan
+ halfway, and offered Stop while the list was read again.
- The shortcuts that show a place in Peel open the main window, also while Settings is open or Peel runs from the menu
bar alone.
- A job's file and its program chosen together move in one pass.
diff --git a/Peel/Model/DeveloperLibrary.swift b/Peel/Model/DeveloperLibrary.swift
index b3736c51..fba981cd 100644
--- a/Peel/Model/DeveloperLibrary.swift
+++ b/Peel/Model/DeveloperLibrary.swift
@@ -11,7 +11,7 @@ final class DeveloperLibrary {
/// The scan this page runs, which a newer one or the Stop button ends.
let scanRun = ScanRun()
var isScanning: Bool { scanRun.isRunning }
- private(set) var isRemoving = false
+ var isRemoving = false
var selection: DeveloperEnvironment.ID?
var selectedURLs: Set<URL> = []
@@ -75,8 +75,6 @@ extension DeveloperLibrary: CarriesSelection {
func move(_ part: CarriedSelection.Part, apps: AppLibrary) async -> TrashResult? {
guard let environment = environment(of: part.page) else { return TrashResult() }
guard environment.runningApp == nil else { return nil }
- isRemoving = true
- defer { isRemoving = false }
let urls = environment.locations.map(\.url).filter { selectedURLs.contains($0) && part.sizes.keys.contains($0) }
return await TrashService(exclusions: ExclusionsStore.shared.exclusions).trash(urls)
}
diff --git a/Peel/Model/DuplicateLibrary.swift b/Peel/Model/DuplicateLibrary.swift
index 3e1839ee..e8b421ad 100644
--- a/Peel/Model/DuplicateLibrary.swift
+++ b/Peel/Model/DuplicateLibrary.swift
@@ -36,7 +36,7 @@ final class DuplicateLibrary {
private(set) var isScanning = false
/// True when the last scan was stopped before it ended, so the page says so rather than offer a first scan.
private(set) var wasStopped = false
- private(set) var isRemoving = false
+ var isRemoving = false
var selection: DuplicateRow?
private(set) var selectedURLs: Set<URL> = []
private(set) var selectedFolders: Set<URL> = []
@@ -332,8 +332,6 @@ extension DuplicateLibrary: CarriesSelection {
func move(_ part: CarriedSelection.Part, apps: AppLibrary) async -> TrashResult? {
guard let scan else { return TrashResult() }
- isRemoving = true
- defer { isRemoving = false }
let result = await DuplicateRemoval.trash(
selectedURLs.filter { part.sizes.keys.contains($0) },
folders: selectedFolders.filter { part.sizes.keys.contains($0) },
diff --git a/Peel/Model/FileSearchLibrary.swift b/Peel/Model/FileSearchLibrary.swift
index 654f6249..6db82c5f 100644
--- a/Peel/Model/FileSearchLibrary.swift
+++ b/Peel/Model/FileSearchLibrary.swift
@@ -15,7 +15,7 @@ final class FileSearchLibrary {
var isSearching: Bool {
scanRun.isRunning || (criteria.isSearchable && criteria != searchedCriteria)
}
- private(set) var isRemoving = false
+ var isRemoving = false
var selectedURLs: Set<URL> = []
/// The file the detail shows. The files selected for the Trash are `selectedURLs`.
var chosen: URL?
@@ -195,8 +195,6 @@ extension FileSearchLibrary: CarriesSelection {
}
func move(_ part: CarriedSelection.Part, apps: AppLibrary) async -> TrashResult? {
- isRemoving = true
- defer { isRemoving = false }
let files = ((results?.files ?? []) + selection.outside.values).filter {
selectedURLs.contains($0.url) && part.sizes.keys.contains($0.url) && !$0.requiresPrivileges
}
diff --git a/Peel/Model/InstallerLibrary.swift b/Peel/Model/InstallerLibrary.swift
index f58e4606..a25561b8 100644
--- a/Peel/Model/InstallerLibrary.swift
+++ b/Peel/Model/InstallerLibrary.swift
@@ -17,7 +17,7 @@ final class InstallerLibrary {
/// The scan this page runs, which a newer one or the Stop button ends.
let scanRun = ScanRun()
var isScanning: Bool { scanRun.isRunning }
- private(set) var isRemoving = false
+ var isRemoving = false
var selection: InstallerItem.Kind?
var selectedURLs: Set<URL> = []
@@ -119,8 +119,6 @@ extension InstallerLibrary: CarriesSelection {
func move(_ part: CarriedSelection.Part, apps: AppLibrary) async -> TrashResult? {
guard let kind = InstallerItem.Kind(rawValue: part.page.scope) else { return TrashResult() }
guard appToQuit(for: part) == nil else { return nil }
- isRemoving = true
- defer { isRemoving = false }
let selected = selected(in: kind).filter { part.sizes.keys.contains($0.url) }
let privileged = Set(selected.filter(\.requiresPrivileges).map(\.url))
return await TrashService(exclusions: ExclusionsStore.shared.exclusions)
diff --git a/Peel/Model/OrphanLibrary.swift b/Peel/Model/OrphanLibrary.swift
index d09058b8..9740b0a7 100644
--- a/Peel/Model/OrphanLibrary.swift
+++ b/Peel/Model/OrphanLibrary.swift
@@ -15,7 +15,7 @@ final class OrphanLibrary {
/// The scan this page runs, which a newer one or the Stop button ends.
let scanRun = ScanRun()
var isScanning: Bool { scanRun.isRunning }
- private(set) var isRemoving = false
+ var isRemoving = false
var selection: OrphanPage?
var selectedURLs: Set<URL> = []
@@ -153,8 +153,6 @@ extension OrphanLibrary: CarriesSelection {
func move(_ part: CarriedSelection.Part, apps: AppLibrary) async -> TrashResult? {
guard let group = scan?.groups.first(where: { $0.page == part.page }) else { return TrashResult() }
- isRemoving = true
- defer { isRemoving = false }
let exclusions = ExclusionsStore.shared.exclusions
return await OrphanRemoval.trash(
selected(in: group).filter { part.sizes.keys.contains($0.url) },
diff --git a/Peel/Model/ProjectLibrary.swift b/Peel/Model/ProjectLibrary.swift
index c83a0040..852ec786 100644
--- a/Peel/Model/ProjectLibrary.swift
+++ b/Peel/Model/ProjectLibrary.swift
@@ -24,7 +24,7 @@ final class ProjectLibrary {
/// The scan this page runs, which a newer one or the Stop button ends.
let scanRun = ScanRun()
var isScanning: Bool { scanRun.isRunning }
- private(set) var isRemoving = false
+ var isRemoving = false
private(set) var folders: [URL]
/// Which artifacts Time Machine is already leaving out.
private(set) var excludedFromBackups: Set<URL> = []
@@ -236,8 +236,6 @@ extension ProjectLibrary: CarriesSelection {
func move(_ part: CarriedSelection.Part, apps: AppLibrary) async -> TrashResult? {
guard let group = group(of: part.page) else { return TrashResult() }
- isRemoving = true
- defer { isRemoving = false }
let chosen = group.artifacts.filter { selectedURLs.contains($0.url) && part.sizes.keys.contains($0.url) }
let changed = await ProjectArtifacts.changedSinceScan(chosen, among: (groups ?? []).flatMap(\.artifacts))
return await TrashService(exclusions: ExclusionsStore.shared.exclusions).trash(
diff --git a/Peel/Model/SelectionCarrier.swift b/Peel/Model/SelectionCarrier.swift
index e2e3ea47..4b8d624f 100644
--- a/Peel/Model/SelectionCarrier.swift
+++ b/Peel/Model/SelectionCarrier.swift
@@ -5,6 +5,9 @@ import PeelCore
/// A storage tool whose selection travels: Move to Trash on any storage tool's page moves what is selected on this
/// tool's pages too, once each has been seen (`CarriedSelection`).
protocol CarriesSelection: AnyObject {
+ /// True while a Move to Trash with a part of this tool runs, from its first move until every tool is up to date. It
+ /// is the removal's and not each part's, so what a page shows holds still between its parts.
+ var isRemoving: Bool { get set }
/// What is selected on each of the tool's pages, a part for each page with something selected.
var carriedParts: [CarriedSelection.Part] { get }
/// The app to quit before `part` can move, or nil when none of its apps is open.
@@ -99,6 +102,9 @@ final class SelectionCarrier {
/// Moves `parts` as one removal. Each part is in History as soon as it moved, so nothing that moved is lost if
/// Peel stops halfway, and a part whose tool kept it stays selected, with the app to quit named after.
func move(_ parts: [CarriedSelection.Part]) async {
+ let moving = parts.compactMap(tool(of:))
+ moving.forEach { $0.isRemoving = true }
+ defer { moving.forEach { $0.isRemoving = false } }
await progress.run(toMove: parts.reduce(0) { $0 + $1.count }) {
var removal = RemovalInProgress()
var appsToQuit: [String] = []
diff --git a/Peel/Model/SpaceLibrary.swift b/Peel/Model/SpaceLibrary.swift
index aa595719..5ca60d96 100644
--- a/Peel/Model/SpaceLibrary.swift
+++ b/Peel/Model/SpaceLibrary.swift
@@ -13,7 +13,7 @@ final class SpaceLibrary: RowSelection {
var selection: SpaceItem.ID?
/// What is selected inside the areas' folders.
var selectedURLs: Set<URL> = []
- private(set) var isRemoving = false
+ var isRemoving = false
/// Each area's last plan: what its page lists, and what a selection carried from it is counted by.
private(set) var plans: [SpaceItem.ID: SpaceRemoval.Plan] = [:]
/// The area as it was, and the exclusions' revision, when its plan was made.
@@ -224,8 +224,6 @@ extension SpaceLibrary: CarriesSelection {
/// folders, and they stay where they are, each told as in use by that app.
func move(_ part: CarriedSelection.Part, apps: AppLibrary) async -> TrashResult? {
guard let item = report?.items.first(where: { $0.page == part.page }) else { return TrashResult() }
- isRemoving = true
- defer { isRemoving = false }
let exclusions = ExclusionsStore.shared.exclusions
let chosen = selectedURLs.intersection(part.sizes.keys)
let now = await SpaceRemoval.movableNow(in: item, exclusions: exclusions, running: RunningCopies.current)
diff --git a/PeelTests/SelectionCarrierTests.swift b/PeelTests/SelectionCarrierTests.swift
index f804a684..da45b574 100644
--- a/PeelTests/SelectionCarrierTests.swift
+++ b/PeelTests/SelectionCarrierTests.swift
@@ -6,6 +6,7 @@ import Testing
@MainActor
struct SelectionCarrierTests {
private final class OpenApps: CarriesSelection {
+ var isRemoving = false
let openApps: [String: String]
init(_ openApps: [String: String]) { self.openApps = openApps }
var carriedParts: [CarriedSelection.Part] { [] }
@@ -17,6 +18,7 @@ struct SelectionCarrierTests {
/// A tool that moves each part at once and notes the removal its moves were written down under.
private final class Recording: CarriesSelection {
+ var isRemoving = false
var seen: [RecordedRemoval?] = []
var carriedParts: [CarriedSelection.Part] { [] }
func move(_ part: CarriedSelection.Part, apps: AppLibrary) async -> TrashResult? {
@@ -30,6 +32,22 @@ struct SelectionCarrierTests {
func deselect(_ part: CarriedSelection.Part) {}
}
+ /// A tool that notes, at each step of a pass, whether it and `other` count as removing.
+ private final class Watching: CarriesSelection {
+ var isRemoving = false
+ var other: Watching?
+ var seen: [Bool] = []
+ var carriedParts: [CarriedSelection.Part] { [] }
+ func move(_ part: CarriedSelection.Part, apps: AppLibrary) async -> TrashResult? {
+ seen += [isRemoving, other?.isRemoving ?? true]
+ return TrashResult()
+ }
+ func refresh(after parts: [CarriedSelection.Part], apps: AppLibrary) async {
+ seen += [isRemoving, other?.isRemoving ?? true]
+ }
+ func deselect(_ part: CarriedSelection.Part) {}
+ }
+
private func part(_ scope: String) -> CarriedSelection.Part {
CarriedSelection.Part(
page: Tool.developer.page(scope), title: scope, source: scope, sourceKey: nil,
@@ -88,4 +106,37 @@ struct SelectionCarrierTests {
#expect(recording.seen.map { $0?.batch } == [batch, batch])
#expect(recording.seen.map { $0?.part } == [part("npm").removalPart, part("pip").removalPart])
}
+
+ @Test func everyToolOfAPassCountsAsRemovingUntilTheLastIsUpToDate() async throws {
+ let folder = FileManager.default.temporaryDirectory.appending(path: "PeelTests-\(UUID().uuidString)")
+ defer { try? FileManager.default.removeItem(at: folder) }
+ let made = try MadeUpDefaults()
+ defer { made.forget() }
+ let (developer, space, orphans) = (Watching(), Watching(), Watching())
+ developer.other = space
+ space.other = developer
+ let carrier = SelectionCarrier(
+ tools: [.developer: developer, .space: space, .orphans: orphans],
+ apps: AppLibrary(
+ defaults: made.defaults, releaseNotesStore: ReleaseNotesStore(url: folder.appending(path: "notes.json"))
+ ),
+ history: RemovalHistoryStore(
+ log: RemovalLog(url: folder.appending(path: "removals.json")),
+ refusals: RefusalLog(url: folder.appending(path: "refusals.json")),
+ knowsTheExclusions: { true }
+ ),
+ outcome: RemovalOutcome()
+ )
+ let logs = CarriedSelection.Part(
+ page: Tool.space.page("logs"), title: "Logs", source: "Logs", sourceKey: nil,
+ sizes: [URL(filePath: "/Users/me/Library/Logs/org.example"): 4_096]
+ )
+
+ await carrier.move([part("npm"), logs, part("pip")])
+
+ #expect(developer.seen == Array(repeating: true, count: 6))
+ #expect(space.seen == Array(repeating: true, count: 4))
+ #expect(!developer.isRemoving && !space.isRemoving)
+ #expect(orphans.seen.isEmpty && !orphans.isRemoving)
+ }
}