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
Ask whether a receipt's app is excluded when it is forgotten
Țugui Dragoș14748eccf2af
diff --git a/Packages/PeelCore/Sources/PeelCore/Packages/PackageActions.swift b/Packages/PeelCore/Sources/PeelCore/Packages/PackageActions.swiftindex d9379d46..81510380 100644--- a/Packages/PeelCore/Sources/PeelCore/Packages/PackageActions.swift+++ b/Packages/PeelCore/Sources/PeelCore/Packages/PackageActions.swift@@ -56,7 +56,8 @@ public enum PackageActions {var refused: [TrashFailure] = []for receipt in receipts {let own = receiptFiles(of: receipt.identifier, onVolume: receipt.volume)- if receipt.installedAppIsExcluded {+ // Asked now, with the exclusions this removal goes by: one can come after the scan the receipt is from.+ if receipt.apps.contains(where: service.excludes) {refused += own.map { TrashFailure(url: $0, reason: .guarded(.excluded)) }} else if own.isEmpty {// Named by the file macOS would keep, so the failure says which receipt rather than which disk. Withdiff --git a/Packages/PeelCore/Sources/PeelCore/Packages/PackageReceipt.swift b/Packages/PeelCore/Sources/PeelCore/Packages/PackageReceipt.swiftindex 46c3475b..cd90611c 100644--- a/Packages/PeelCore/Sources/PeelCore/Packages/PackageReceipt.swift+++ b/Packages/PeelCore/Sources/PeelCore/Packages/PackageReceipt.swift@@ -53,15 +53,16 @@ public struct PackageReceipt: Sendable, Hashable, Identifiable {/// True when the package's scripts put its files in place: it installed into a temporary folder, or listed/// nothing. Its receipt then doesn't say where they are, so nothing is judged left or gone from it.public var installedThroughItsScripts = false- /// The names of the apps the package put on this Mac that are still where it put them.- public var installedApps: [String] = []- /// Whether one of those apps is excluded in Settings, which leaves its receipt alone too.- public var installedAppIsExcluded = false+ /// The apps the package put on this Mac that are still where it put them. Excluding one leaves the receipt alone+ /// too, which is asked of the exclusions as they stand whenever it counts.+ public var apps: [InstalledApp] = []/// The name macOS gave the package when it installed it, such as "AdGuard", if its install history keeps one.public var name: String?public var id: String { identifier }+ public var installedApps: [String] { apps.map(\.name).sorted() }+/// What forgetting the package's files could free now, as an orphan group counts it. Unknown when the file list/// is, since an empty list then says nothing about what is left.public func movable(canUseHelper: Bool) -> SizeTotal {diff --git a/Packages/PeelCore/Sources/PeelCore/Packages/PackageReceipts.swift b/Packages/PeelCore/Sources/PeelCore/Packages/PackageReceipts.swiftindex b1ee15f6..6948638c 100644--- a/Packages/PeelCore/Sources/PeelCore/Packages/PackageReceipts.swift+++ b/Packages/PeelCore/Sources/PeelCore/Packages/PackageReceipts.swift@@ -370,8 +370,7 @@ public enum PackageReceipts {nothingLeftOnDisk: listing != nil && !throughScripts && found.onDisk.isEmpty,isFileListKnown: listing != nil,installedThroughItsScripts: throughScripts,- installedApps: apps.map(\.name).sorted(),- installedAppIsExcluded: apps.contains(where: exclusions.excludes)+ apps: apps),paths: files.map { path(of: $0, in: installLocation).path(percentEncoded: false) },installLocation: installLocation.path(percentEncoded: false)diff --git a/Packages/PeelCore/Tests/PeelCoreTests/PackageReceiptsTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/PackageReceiptsTests.swiftindex 106a02aa..3f3cce3d 100644--- a/Packages/PeelCore/Tests/PeelCoreTests/PackageReceiptsTests.swift+++ b/Packages/PeelCore/Tests/PeelCoreTests/PackageReceiptsTests.swift@@ -332,17 +332,31 @@ struct PackageReceiptsTests {#expect(scan.receipts.first { $0.identifier == "org.example.mixer.pkg" }?.installedApps == ["Mixer"])#expect(scan.receipts.first { $0.identifier == "org.example.gone.pkg" }?.installedApps == [])- #expect(scan.receipts.allSatisfy { !$0.installedAppIsExcluded })let excluding = Exclusions(bundleIdentifiers: ["org.example.mixer"])let kept = await PackageReceipts.list(exclusions: excluding, pkgutil: pkgutil, environment: environment)let mixer = try #require(kept.receipts.first { $0.identifier == "org.example.mixer.pkg" })- #expect(mixer.installedAppIsExcluded)+ #expect(mixer.apps.contains(where: excluding.excludes))try directory.file("private/var/db/receipts/org.example.mixer.pkg.bom", bytes: 16)try directory.file("private/var/db/receipts/org.example.mixer.pkg.plist", bytes: 16)let forgotten = await PackageActions.forget(mixer, exclusions: excluding)#expect(forgotten.trashed.isEmpty)#expect(forgotten.failures.map(\.reason) == [.guarded(.excluded), .guarded(.excluded)])++ // Read before the app was excluded, and forgotten after: the question can outlive the scan it came from.+ let readBefore = try #require(scan.receipts.first { $0.identifier == "org.example.mixer.pkg" })+ let moved = Mutex<[URL]>([])+ let service = TrashService(+ environment: environment, exclusions: excluding,+ moveThroughHelper: { urls in+ moved.withLock { $0 += urls }+ return TrashResult(trashed: urls.map { TrashedItem(originalURL: $0, trashedURL: $0, date: .now) })+ },+ moveToTrash: { _ in throw CocoaError(.fileWriteNoPermission) }+ )+ let late = await PackageActions.forget([readBefore], through: service)+ #expect(moved.withLock { $0 }.isEmpty)+ #expect(late.failures.map(\.reason) == [.guarded(.excluded), .guarded(.excluded)])}@Test func namesAPackageAsMacOSsInstallHistoryDoes() throws {diff --git a/Peel/Views/Packages/PackageDetailView.swift b/Peel/Views/Packages/PackageDetailView.swiftindex dc7e96b8..c188683a 100644--- a/Peel/Views/Packages/PackageDetailView.swift+++ b/Peel/Views/Packages/PackageDetailView.swift@@ -80,7 +80,7 @@ struct PackageDetailView: View {.minimumTarget()}.buttonStyle(.borderless)- .disabled(!helper.canAct || !history.mayMove || receipt.installedAppIsExcluded)+ .disabled(!helper.canAct || !history.mayMove || isForAnExcludedApp).help(forgetHelp)}}@@ -130,8 +130,13 @@ struct PackageDetailView: View {.forgetReceiptDialog(for: $receiptToForget, forget: packages.forget)}+ /// Read from the exclusions, not the scan, so it holds as soon as they change.+ private var isForAnExcludedApp: Bool {+ receipt.apps.contains(where: ExclusionsStore.shared.exclusions.excludes)+ }+private var forgetHelp: Text {- if receipt.installedAppIsExcluded {+ if isForAnExcludedApp {return Text("The app this package installed is excluded in Settings, so Peel leaves its receipt alone too.")}return helper.canAct