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.

Move what an app in the Trash left from Terminal too, and say why a row stays

Țugui Dragoș1d7a4db93bd3
diff --git a/GUIDE.md b/GUIDE.md
index b452b501..10ffd58f 100644
--- a/GUIDE.md
+++ b/GUIDE.md
@@ -14,8 +14,8 @@ and how to get it, [SAFETY.md](SAFETY.md) what it protects, [PRIVACY.md](PRIVACY
containers and group containers, preferences, saved state, logs, launch agents and daemons, plug-in folders, and
more. Each file comes with the reason it matched, such as the app's bundle identifier, its signing team, or a
Homebrew cask that names it.
-- **What Peel is sure of, or nearly, is selected.** Files Peel matched by the app's identifier, its name, or its
- installer's receipt are selected for you, and so is the folder Homebrew keeps for an app it installed, so that
+- **What Peel is sure of, or nearly, is selected.** Files Peel matched by the app's identifier or its name, and its
+ installer's receipt when the package put nothing else outside the app, are selected for you, and so is the folder Homebrew keeps for an app it installed, so that
Homebrew stops listing the app once it is gone. A match on the name alone is only a guess in your home folder, at
the top of a Library, or inside another app's folder or one of Apple's, so it waits under Review Before Removing.
So does a folder named like the app while another installed app's name holds that name, as Epic Games Launcher
diff --git a/Packages/PeelCore/Sources/PeelCommandLine/Commands/AppCommands.swift b/Packages/PeelCore/Sources/PeelCommandLine/Commands/AppCommands.swift
index 0b13e106..8da91b4e 100644
--- a/Packages/PeelCore/Sources/PeelCommandLine/Commands/AppCommands.swift
+++ b/Packages/PeelCore/Sources/PeelCommandLine/Commands/AppCommands.swift
@@ -132,6 +132,10 @@ struct LeftoversCommand: AsyncParsableCommand {
@OptionGroup var output: OutputOptions
+ static func inTheTrash(_ app: InstalledApp) -> String {
+ "\(Output.plain(app.name)) is already in the Trash. What it left behind can still be moved."
+ }
+
struct Report: Encodable {
let app: AppRecord
/// Nil when the app bundle couldn't be measured. Written as `null`, never left out, so a script always
@@ -195,6 +199,9 @@ struct LeftoversCommand: AsyncParsableCommand {
if let stays {
Output.note("\(stays.description) While it stays, `peel uninstall` moves none of its files.")
}
+ if uninstallation.isAppInTheTrash {
+ Output.note(Self.inTheTrash(target))
+ }
Self.notes(uninstallation, homebrew: homebrew, hidden: uninstallation.scan.leftovers.count - leftovers.count)
if output.json {
let appSize = uninstallation.isAppMeasured ? uninstallation.appSize : nil
@@ -436,7 +443,9 @@ struct UninstallCommand: AsyncParsableCommand {
/// Whether the app's icon comes out of the Dock: once the app itself is in the Trash, unless `--keep-in-dock`.
static func takesOutDockIcon(of app: InstalledApp, after result: TrashResult, keeping: Bool) -> Bool {
- !keeping && result.trashed.contains { $0.originalURL == app.url }
+ guard !keeping else { return false }
+ return TrashService.isInsideATrash(app.url) ? !result.trashed.isEmpty
+ : result.trashed.contains { $0.originalURL == app.url }
}
/// What the plan says about the app's icon in the Dock, which History puts back with the app.
@@ -584,6 +593,9 @@ struct UninstallCommand: AsyncParsableCommand {
/// Throws when Peel never resets the privacy permissions of `target`. Called for `--reset-privacy` before
/// anything is listed: skipping the reset quietly would remove the app and leave its permissions on record.
static func refuseIfPrivacyCannotBeReset(_ target: InstalledApp) throws {
+ guard !TrashService.isInsideATrash(target.url) else {
+ throw CommandFailure("macOS can't reset the privacy permissions of an app in the Trash. Leave out --reset-privacy, or put it back first.")
+ }
guard !PrivacyReset.isAllowed(for: target) else { return }
throw CommandFailure("Peel never resets privacy permissions for \(Output.plain(target.name)). Leave out --reset-privacy to remove it anyway.")
}
@@ -616,9 +628,6 @@ struct UninstallCommand: AsyncParsableCommand {
let exclusions = await ExclusionStore().load()
try AppLookup.refuseIfExcluded(target, by: exclusions)
let service = TrashService(exclusions: exclusions)
- guard !service.isInsideATrash(target.url) else {
- throw CommandFailure("\(Output.plain(target.name)) is already in the Trash. Empty it, or put it back first.")
- }
let running = try Self.note(for: await Self.whileRunning(target, among: apps), dryRun: dryRun)
let homebrew = await CaskLookup.evidence(for: target)
let uninstallation = await ProgressLine.counting {
@@ -631,7 +640,8 @@ struct UninstallCommand: AsyncParsableCommand {
)
}
let access = try Self.note(for: Self.whyItStays(uninstallation), dryRun: dryRun)
- [running, access].compactMap(\.self).forEach(Output.note)
+ let inTheTrash = uninstallation.isAppInTheTrash ? LeftoversCommand.inTheTrash(target) : nil
+ [running, access, inTheTrash].compactMap(\.self).forEach(Output.note)
if let note = UnreadableHistory.note() {
Output.note(note)
@@ -690,7 +700,8 @@ struct UninstallCommand: AsyncParsableCommand {
}
let privacy = reset.map { Self.privacyOutcome($0, app: target, after: result) }
if isInTheDock, Self.takesOutDockIcon(of: target, after: result, keeping: keepInDock) {
- _ = await DockTiles().takeOut([target.url], foundAt: result.trashedAt)
+ let forgotten: Set<URL> = TrashService.isInsideATrash(target.url) ? [target.url] : []
+ _ = await DockTiles().takeOut([target.url], foundAt: result.trashedAt, forgetting: forgotten)
}
let references = await ShellReferences.find(naming: result.trashed.map(\.originalURL))
diff --git a/Packages/PeelCore/Sources/PeelCommandLine/Support/UninstallPlan.swift b/Packages/PeelCore/Sources/PeelCommandLine/Support/UninstallPlan.swift
index 04b4c8ee..4235b9e1 100644
--- a/Packages/PeelCore/Sources/PeelCommandLine/Support/UninstallPlan.swift
+++ b/Packages/PeelCore/Sources/PeelCommandLine/Support/UninstallPlan.swift
@@ -45,7 +45,9 @@ struct UninstallPlan {
refusal: (URL) -> TrashFailure.Reason?
) -> UninstallPlan {
let app = uninstallation.app.url
- let selection = keepLeftovers ? [app] : uninstallation.suggestedSelection(canUseHelper: false)
+ // An app already in the Trash doesn't move again, and what it left behind still can.
+ let bundle: Set<URL> = uninstallation.isAppInTheTrash ? [] : [app]
+ let selection = keepLeftovers ? bundle : uninstallation.suggestedSelection(canUseHelper: false)
let ordered = [app] + uninstallation.removalOrder(of: selection).filter { $0 != app }
let leftovers = Dictionary(
uninstallation.scan.leftovers.map { ($0.url, $0) },
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/CommandLineTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/CommandLineTests.swift
index 2c2a6f91..31a94496 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/CommandLineTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/CommandLineTests.swift
@@ -851,6 +851,21 @@ struct CommandLineTests {
#expect(alone.needsReview == 0)
}
+ @Test func leavesAnAppAlreadyInTheTrashWhereItIsAndMovesWhatItLeft() throws {
+ let directory = try TemporaryDirectory()
+ let bundle = directory.url.appending(path: "home/.Trash/Editor.app", directoryHint: .isDirectory)
+ let app = InstalledApp(url: bundle, bundleIdentifier: "org.example.editor", name: "Editor")
+ let cache = URL(filePath: "/Users/me/Library/Caches/org.example.editor")
+ var inTheTrash = uninstallation(app: app, leftovers: [leftover(cache)])
+ inTheTrash.isAppInTheTrash = true
+
+ let plan = UninstallPlan.make(inTheTrash, keepLeftovers: false, refusal: { _ in nil })
+ #expect(plan.items.map(\.url) == [cache])
+ #expect(plan.appStays == nil)
+
+ #expect(UninstallPlan.make(inTheTrash, keepLeftovers: true, refusal: { _ in nil }).items.isEmpty)
+ }
+
/// The list is drawn from the guard's own answer, so `--dry-run` can't promise what the real run refuses.
@Test func saysWhatWouldStayInsteadOfListingItAsMoving() {
let app = InstalledApp(url: URL(filePath: "/Applications/Editor.app", directoryHint: .isDirectory), bundleIdentifier: "com.example.editor", name: "Editor")
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/SeveralAppsPageTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/SeveralAppsPageTests.swift
new file mode 100644
index 00000000..3b6698b4
--- /dev/null
+++ b/Packages/PeelCore/Tests/PeelCoreTests/SeveralAppsPageTests.swift
@@ -0,0 +1,11 @@
+import Foundation
+import Testing
+
+struct SeveralAppsPageTests {
+ @Test func scansAgainWhenWhatHomebrewKnowsArrives() throws {
+ let view = LineLengthTests.repository.appending(path: "Peel/Views/MultipleAppsView.swift")
+ let source = try String(contentsOf: view, encoding: .utf8)
+
+ #expect(source.contains(".task(id: homebrew.evidenceRevision)"))
+ }
+}
diff --git a/Peel/Views/AppDetailView.swift b/Peel/Views/AppDetailView.swift
index b02a4aa5..0f9ed1b5 100644
--- a/Peel/Views/AppDetailView.swift
+++ b/Peel/Views/AppDetailView.swift
@@ -431,9 +431,11 @@ struct AppDetailView: View {
/// What the row has to say for itself beyond the match: who else uses it, and why Peel left the checkmark off.
private func warning(for leftover: Leftover) -> String? {
var lines: [String] = []
- if plan.appStays, !plan.app.isSystemProtected, plan.removedElsewhere == nil,
- leftover.match.heldBack != .holdsAnExclusion {
- lines.append(String(localized: "Not selected: it stays with \(plan.app.name)."))
+ if plan.appStays, plan.removedElsewhere == nil, leftover.match.heldBack != .holdsAnExclusion {
+ // Two literals, so the string catalog finds both.
+ lines.append(plan.app.isSystemProtected
+ ? String(localized: "Not selected: it belongs to an app macOS keeps, so it is in use.")
+ : String(localized: "Not selected: it stays with \(plan.app.name)."))
}
if leftover.match.isShared {
let users = leftover.match.sharedWith.map(library.name(forReference:))
diff --git a/Peel/Views/MultipleAppsView.swift b/Peel/Views/MultipleAppsView.swift
index 4509aee6..ba302cd8 100644
--- a/Peel/Views/MultipleAppsView.swift
+++ b/Peel/Views/MultipleAppsView.swift
@@ -164,7 +164,8 @@ struct MultipleAppsView: View {
}
.forceQuitOffer(quitting)
.onDisappear { quitting.giveUp() }
- .task {
+ // Keyed to what Homebrew knows: evidence that arrives after the page opened is a reason to look again.
+ .task(id: homebrew.evidenceRevision) {
// Selecting apps one by one rebuilds this page after each change, and each build scans every selected
// app. The short wait lets the selection settle: a newer change cancels this task before it scans.
try? await Task.sleep(for: .milliseconds(300))
diff --git a/Peel/Views/ResetSheet.swift b/Peel/Views/ResetSheet.swift
index a66033bd..dbba85c4 100644
--- a/Peel/Views/ResetSheet.swift
+++ b/Peel/Views/ResetSheet.swift
@@ -187,6 +187,8 @@ struct ResetSheet: View {
}
}
}
+ .dimmedWhileBusy(plan.isResetting)
+ .disabled(plan.isResetting)
.scrollBarBelowSectionHeaders()
.scanState(phase, scan: plan.scanRun) {
if plan.isExcluded {