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.

Recommend nothing of an app that stays, on its own page

Țugui Dragoș0169bf908ba9
diff --git a/Packages/PeelCore/Sources/PeelCore/Removal/Uninstallation.swift b/Packages/PeelCore/Sources/PeelCore/Removal/Uninstallation.swift
index dca04d93..4f6aeb17 100644
--- a/Packages/PeelCore/Sources/PeelCore/Removal/Uninstallation.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Removal/Uninstallation.swift
@@ -384,21 +384,36 @@ public struct Uninstallation: Sendable {
&& (match.confidence == .certain || isInItsNamespace)
}
- /// How many items could move once selected, and their total size: what a section header shows and the
- /// page's total adds up. Rows Peel leaves alone are not counted.
- public func movable(among leftovers: [Leftover], withApp: Bool) -> (count: Int, size: SizeTotal) {
- guard removedElsewhere == nil else { return (0, SizeTotal([])) }
- let movable = leftovers.filter { $0.match.heldBack?.cannotBeMoved != true }
+ /// How many items a checkbox can select now, and their total size: what a section header shows and the page's
+ /// total adds up. Rows Peel leaves alone, and those waiting for the helper, are not counted.
+ public func movable(
+ among leftovers: [Leftover],
+ withApp: Bool,
+ canUseHelper: Bool
+ ) -> (count: Int, size: SizeTotal) {
+ let selectable = selectable(canUseHelper: canUseHelper)
+ let movable = leftovers.filter { selectable.contains($0.url) }
var sizes = Dictionary(movable.map { ($0.url, $0.isMeasured ? $0.size : nil) }) { first, _ in first }
var count = movable.count
- if withApp, !app.isSystemProtected, app.enclosingPackage == nil, !isExcluded, !isAppBeyondTheHelper,
- !isAppInTheTrash {
+ if withApp, selectable.contains(app.url) {
sizes.updateValue(isAppMeasured ? appSize : nil, forKey: app.url)
count += 1
}
return (count, SizeTotal(movingItemsAt: sizes))
}
+ /// A list of `rows` on the app's page, for its Select menu: what a checkbox can select now, and what Peel
+ /// selects for the person, which is nothing while the app stays.
+ public func selectableRows(_ rows: [URL], canUseHelper: Bool) -> SelectableRows<URL> {
+ let selectable = selectable(canUseHelper: canUseHelper)
+ let suggested = suggestedSelection(canUseHelper: canUseHelper)
+ return SelectableRows(
+ rows: rows,
+ selectable: rows.filter(selectable.contains),
+ recommended: rows.filter(suggested.contains)
+ )
+ }
+
public var privilegedURLs: Set<URL> {
guard !isExcluded, removedElsewhere == nil else { return [] }
var urls = Set(
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/UninstallationTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/UninstallationTests.swift
index d6d93a4b..85510872 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/UninstallationTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/UninstallationTests.swift
@@ -52,7 +52,7 @@ struct UninstallationTests {
#expect(plan.appStays(canUseHelper: true))
#expect(plan.suggestedSelection(canUseHelper: true).isEmpty)
#expect(plan.selectable(canUseHelper: true).isEmpty)
- #expect(plan.movable(among: plan.scan.leftovers, withApp: true).count == 0)
+ #expect(plan.movable(among: plan.scan.leftovers, withApp: true, canUseHelper: true).count == 0)
#expect(plan.privilegedURLs.isEmpty)
#expect(plan.removalOrder(of: [agent.url, daemon.url, support.url]).isEmpty)
}
@@ -443,7 +443,7 @@ struct UninstallationTests {
#expect(plan.removedElsewhere == .byRemovePeel)
#expect(plan.suggestedSelection(canUseHelper: true).isEmpty)
#expect(plan.removalOrder(of: [peel.url, own.url]).isEmpty)
- #expect(plan.movable(among: [own], withApp: true).count == 0)
+ #expect(plan.movable(among: [own], withApp: true, canUseHelper: true).count == 0)
#expect(plan.privilegedURLs.isEmpty)
#expect(plan.unreviewedSelection == [peel.url, own.url], "Remove Peel no longer takes what is Peel's")
@@ -491,7 +491,7 @@ struct UninstallationTests {
#expect(plan.isAppBeyondTheHelper == (isBeyond && !isKept))
#expect(plan.suggestedSelection(canUseHelper: true).contains(app.url) == isOffered)
#expect(plan.privilegedURLs.contains(app.url) == isOffered)
- #expect(plan.movable(among: [], withApp: true).count == (isOffered ? 1 : 0))
+ #expect(plan.movable(among: [], withApp: true, canUseHelper: true).count == (isOffered ? 1 : 0))
#expect(item.isBeyondTheHelper == (isBeyond && !isKept))
#expect(bulk.suggestedSelection(canUseHelper: true).contains(app.url) == isOffered)
#expect(bulk.privilegedURLs.contains(app.url) == isOffered)
@@ -519,9 +519,11 @@ struct UninstallationTests {
let documents = leftover("container").heldBack(.holdsDocuments)
let plan = uninstallation(leftovers: [own, named, slow, beyond, excluded, documents])
- let recommended = plan.movable(among: plan.scan.leftovers.filter(\.match.isRecommended), withApp: true)
- let review = plan.movable(among: plan.scan.leftovers.filter { !$0.match.isRecommended }, withApp: false)
- let total = plan.movable(among: plan.scan.leftovers, withApp: true)
+ let picked = plan.scan.leftovers.filter(\.match.isRecommended)
+ let others = plan.scan.leftovers.filter { !$0.match.isRecommended }
+ let recommended = plan.movable(among: picked, withApp: true, canUseHelper: true)
+ let review = plan.movable(among: others, withApp: false, canUseHelper: true)
+ let total = plan.movable(among: plan.scan.leftovers, withApp: true, canUseHelper: true)
#expect(recommended.count == 2)
#expect(recommended.size == SizeTotal(known: 11_000, isComplete: true))
@@ -531,12 +533,28 @@ struct UninstallationTests {
#expect(total.size == SizeTotal(known: recommended.size.known + review.size.known, isComplete: false))
}
+ @Test func anAppThatStaysRecommendsNothingAndCountsOnlyWhatCanGo() {
+ let own = leftover("com.example.app")
+ let daemon = leftover("com.example.app.daemon.plist", requiresPrivileges: true)
+ let plan = uninstallation(appRequiresPrivileges: true, leftovers: [own, daemon])
+ let rows = [plan.app.url, own.url, daemon.url]
+
+ let withoutHelper = plan.selectableRows(rows, canUseHelper: false)
+ #expect(withoutHelper.recommended.isEmpty)
+ #expect(withoutHelper.notRecommendedAdded(by: []) == [own.url])
+ #expect(plan.movable(among: [own, daemon], withApp: true, canUseHelper: false).count == 1)
+
+ let withHelper = plan.selectableRows(rows, canUseHelper: true)
+ #expect(Set(withHelper.recommended) == Set(rows))
+ #expect(plan.movable(among: [own, daemon], withApp: true, canUseHelper: true).count == 3)
+ }
+
/// A Homebrew cask can name a folder inside one the scan found, such as Steam's bundle inside its Application
/// Support folder: both are listed, and the bytes they share are counted once.
@Test func theTotalCountsARowInsideAnotherRowOnce() {
let plan = uninstallation(leftovers: [leftover("Steam"), leftover("Steam/Steam.AppBundle")])
- let total = plan.movable(among: plan.scan.leftovers, withApp: false)
+ let total = plan.movable(among: plan.scan.leftovers, withApp: false, canUseHelper: true)
#expect(total.size == SizeTotal(known: 1_000, isComplete: true))
}
@@ -598,7 +616,7 @@ struct UninstallationTests {
#expect(plan.isAppInTheTrash)
#expect(plan.suggestedSelection(canUseHelper: true).map(\.lastPathComponent) == ["org.example.app.plist"])
#expect(!plan.selectable(canUseHelper: true).contains(bundle))
- #expect(plan.movable(among: plan.scan.leftovers, withApp: true).count == 1)
+ #expect(plan.movable(among: plan.scan.leftovers, withApp: true, canUseHelper: true).count == 1)
#expect(!plan.privilegedURLs.contains(bundle))
let several = await BulkUninstallation.prepare(
@@ -631,7 +649,8 @@ struct UninstallationTests {
#expect(plan.appStays(canUseHelper: true))
#expect(plan.suggestedSelection(canUseHelper: true).isEmpty)
#expect(!plan.selectable(canUseHelper: true).contains(bundle))
- #expect(plan.movable(among: plan.scan.leftovers, withApp: true).count == plan.scan.leftovers.count)
+ let leftovers = plan.scan.leftovers
+ #expect(plan.movable(among: leftovers, withApp: true, canUseHelper: true).count == leftovers.count)
let several = await BulkUninstallation.prepare(
[installed],
diff --git a/Peel/Model/RemovalPlan.swift b/Peel/Model/RemovalPlan.swift
index 1b1b7d7a..29622038 100644
--- a/Peel/Model/RemovalPlan.swift
+++ b/Peel/Model/RemovalPlan.swift
@@ -114,6 +114,15 @@ final class RemovalPlan {
/// What a checkbox can select now.
var selectable: Set<URL> { choices.selectable }
+ var appStays: Bool {
+ uninstallation?.appStays(canUseHelper: canUseHelper) ?? false
+ }
+
+ func selectableRows(_ rows: [URL]) -> SelectableRows<URL> {
+ uninstallation?.selectableRows(rows, canUseHelper: canUseHelper)
+ ?? SelectableRows(rows: rows, selectable: [], recommended: [])
+ }
+
/// The revision of the exclusions the last scan read, nil before the first.
private(set) var exclusionsRevision: Int?
@@ -147,9 +156,7 @@ final class RemovalPlan {
let leftovers = result.scan.leftovers
recommended = leftovers.filter(\.match.isRecommended)
needsReview = leftovers.filter { !$0.match.isRecommended }
- recommendedMovable = result.movable(among: recommended, withApp: true)
- reviewMovable = result.movable(among: needsReview, withApp: false)
- total = result.movable(among: leftovers, withApp: true).size
+ countMovable(in: result)
leftoverSizes = Dictionary(
leftovers.map { ($0.url, ($0.size, $0.isMeasured)) },
uniquingKeysWith: { first, _ in first }
@@ -167,6 +174,13 @@ final class RemovalPlan {
self.canUseHelper = canUseHelper
guard let uninstallation else { return }
selectedURLs = choices.update(selectedURLs, in: uninstallation, canUseHelper: canUseHelper)
+ countMovable(in: uninstallation)
+ }
+
+ private func countMovable(in result: Uninstallation) {
+ recommendedMovable = result.movable(among: recommended, withApp: true, canUseHelper: canUseHelper)
+ reviewMovable = result.movable(among: needsReview, withApp: false, canUseHelper: canUseHelper)
+ total = result.movable(among: result.scan.leftovers, withApp: true, canUseHelper: canUseHelper).size
}
/// What each package put outside the app is worked out here, off the main actor, because it takes an `lstat` per
diff --git a/Peel/Views/AppDetailView.swift b/Peel/Views/AppDetailView.swift
index dfe8fe24..86efa56d 100644
--- a/Peel/Views/AppDetailView.swift
+++ b/Peel/Views/AppDetailView.swift
@@ -285,19 +285,12 @@ struct AppDetailView: View {
"Everything selected here goes to the Trash together when you click Move to Trash. Nothing is deleted outright: History can put it back while it’s in the Trash."
),
movable: plan.recommendedMovable,
- list: SelectableRows(
- rows: recommendedRows, selectable: recommendedSelectable, recommended: recommendedSelectable
- ),
+ list: plan.selectableRows(recommendedRows),
place: Text("Recommended")
)
}
}
- /// The Recommended rows a checkbox can select, all of them recommended.
- private var recommendedSelectable: [URL] {
- recommendedRows.filter(plan.selectable.contains)
- }
-
private var recommendedRows: [URL] {
[plan.app.url] + plan.recommended.map(\.url)
}
@@ -318,11 +311,7 @@ struct AppDetailView: View {
"These are here because Peel is less sure about them, another app on this Mac uses them too, or Peel held them back for the reason each row gives. Nothing here is selected for you: read each one and select only what you recognize."
),
movable: plan.reviewMovable,
- list: SelectableRows(
- rows: plan.needsReview.map(\.url),
- selectable: plan.needsReview.map(\.url).filter(plan.selectable.contains),
- recommended: []
- ),
+ list: plan.selectableRows(plan.needsReview.map(\.url)),
place: Text("Review Before Removing")
)
}
@@ -395,6 +384,10 @@ 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 leftover.match.isShared {
let users = leftover.match.sharedWith.map(library.name(forReference:))
+ leftover.match.otherCopies.map(\.abbreviatedPath)
diff --git a/SAFETY.md b/SAFETY.md
index 98211a8c..a95ac2b0 100644
--- a/SAFETY.md
+++ b/SAFETY.md
@@ -326,11 +326,11 @@ Only matches Peel is `certain` or `likely` about, and only when nothing else ins
keep anyone from logging in. No public tool lists every rule, so Peel shows it, on the app's page, in Orphaned
Files, and in Package Receipts, and leaves it to its maker's uninstaller.
- **An app that stays keeps its files.** Nothing at all is selected for an app that would stay: one macOS keeps, one
- that is part of another app, one the helper may not move, or one that needs the helper while it cannot act. An app
- that is part of another, such as a helper app inside the app it serves, is never moved on its own, from the app or
- from `peel`: it would be cut out of the app it belongs to. When you remove several apps at once and deselect one of
- them, it stays too: its files leave the selection, those it shares with the other apps included, and selecting it
- again brings them back.
+ that is part of another app, one the helper may not move, or one that needs the helper while it cannot act. Its files
+ say why they aren't selected, and Select All asks before it takes them. An app that is part of another, such as a
+ helper app inside the app it serves, is never moved on its own, from the app or from `peel`: it would be cut out of
+ the app it belongs to. When you remove several apps at once and deselect one of them, it stays too: its files leave
+ the selection, those it shares with the other apps included, and selecting it again brings them back.
- **What macOS installed stays macOS's.** Something one of Apple's own installer packages put on the Mac, as its
receipt shows, is never listed with an app, whatever it is named, nor among what an uninstall leaves for an
administrator, such as a folder Xcode installed that is named for Chrome.