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
Read an app's Dock tile and package receipts again with each scan
Țugui Dragoș07d0ab6503d1
diff --git a/Peel/Model/BulkRemovalPlan.swift b/Peel/Model/BulkRemovalPlan.swiftindex 7bc1f68c..8d84df10 100644--- a/Peel/Model/BulkRemovalPlan.swift+++ b/Peel/Model/BulkRemovalPlan.swift@@ -31,6 +31,8 @@ final class BulkRemovalPlan {private(set) var filesToReview: [BulkUninstallation.Item] = []/// The chosen apps already in the Trash, which neither go nor stay: only what they left behind can move.private(set) var appsInTheTrash: Set<URL> = []+ /// The chosen apps the Dock holds a tile for, read once per scan, so Rescan shows it as it is now.+ private(set) var appsInTheDock: Set<URL> = []/// What Peel selects for the person, worked out again whenever the helper changes.private(set) var suggested: Set<URL> = []var selectable: Set<URL> { choices.selectable }@@ -100,6 +102,7 @@ final class BulkRemovalPlan {self.installedApps = installedAppssuggested = result.suggestedSelection(canUseHelper: self.canUseHelper)selectedURLs = choices.update(selectedURLs, in: result, canUseHelper: self.canUseHelper)+ appsInTheDock = await DockTiles().holding(apps.map(\.url))}/// Brings the selection in line with the helper as it is now, without scanning again.diff --git a/Peel/Model/RemovalPlan.swift b/Peel/Model/RemovalPlan.swiftindex 42a55193..7b5d65fa 100644--- a/Peel/Model/RemovalPlan.swift+++ b/Peel/Model/RemovalPlan.swift@@ -22,6 +22,11 @@ final class RemovalPlan {/// and finding the uninstaller lists whole folders, such as Applications.private(set) var vendorUninstaller: URL?private(set) var systemExtensions: [String] = []+ /// Read once per scan as well, so Rescan shows them as they are now: whether the Dock holds a tile for the app,+ /// and the receipts of the packages that installed it, with what each put outside the app.+ private(set) var hasDockTile = false+ private(set) var packageReceipts: [PackageReceipt] = []+ private(set) var filesOutside: [PackageReceipt.ID: [PackageReceipt.Item]] = [:]var selectedURLs: Set<URL> = []private var choices = UninstallSelection()/// Whether the helper can act, as last heard, so a scan that lands after it changed selects by what is true now.@@ -108,16 +113,22 @@ final class RemovalPlan {) async {self.canUseHelper = canUseHelperlet app = app- guard let (result, bundle, revision) = await scanRun.run({+ guard let (result, bundle, installed, revision) = await scanRun.run({let revision = ExclusionsStore.shared.revision+ let exclusions = ExclusionsStore.shared.exclusionslet result = await Uninstallation.prepare(app,installedApps: installedApps,- exclusions: ExclusionsStore.shared.exclusions,+ exclusions: exclusions,casks: casks,receipts: receipts)- return (result, await Self.look(inside: app), revision)+ return (+ result,+ await Self.look(inside: app),+ await Self.packageReceipts(of: app, exclusions: exclusions),+ revision+ )}) else { return }uninstallation = resultexclusionsRevision = revision@@ -133,8 +144,10 @@ final class RemovalPlan {)self.installedApps = installedApps(vendorUninstaller, systemExtensions) = bundle+ (packageReceipts, filesOutside) = installedselectedURLs = choices.update(selectedURLs, in: result, canUseHelper: self.canUseHelper)defaultRoles = await DefaultApps.roles(of: app)+ hasDockTile = !(await DockTiles().holding([app.url])).isEmpty}/// Brings the selection in line with the helper as it is now, without scanning again.@@ -144,6 +157,20 @@ final class RemovalPlan {selectedURLs = choices.update(selectedURLs, in: uninstallation, canUseHelper: canUseHelper)}+ /// What each package put outside the app is worked out here, off the main actor, because it takes an `lstat` per+ /// file and the page is redrawn whenever a checkbox changes.+ @concurrent+ private nonisolated static func packageReceipts(+ of app: InstalledApp,+ exclusions: Exclusions+ ) async -> ([PackageReceipt], [PackageReceipt.ID: [PackageReceipt.Item]]) {+ let receipts = await PackageReceipts.receipts(installing: app.url, exclusions: exclusions)+ let files = receipts.map {+ ($0.id, VendorRemoval.filesOutsideBundle(of: $0, app: app, otherReceipts: receipts))+ }+ return (receipts, Dictionary(files, uniquingKeysWith: { first, _ in first }))+ }+@concurrentprivate nonisolated static func look(inside app: InstalledAppdiff --git a/Peel/Views/AppDetailView.swift b/Peel/Views/AppDetailView.swiftindex 285f2bbb..928b81a3 100644--- a/Peel/Views/AppDetailView.swift+++ b/Peel/Views/AppDetailView.swift@@ -13,7 +13,6 @@ struct AppDetailView: View {@State private var isRescanning = false@State private var resetsPrivacy = false@State private var removesDockTile = true- @State private var hasDockTile = false@State private var isConfirmingPrivacyReset = false/// The result of the last privacy reset started from the More menu, shown under the buttons.@State private var privacyReset: PrivacyReset.Result?@@ -77,9 +76,6 @@ struct AppDetailView: View {guard !Task.isCancelled, !(plan.scan == nil && plan.scanRun.wasStopped) else { return }await rescan()}- .task(id: plan.app.url) {- hasDockTile = !(await DockTiles().holding([plan.app.url])).isEmpty- }.rescanOnExclusionChange(scannedUnder: plan.exclusionsRevision) { await rescan() }.onChange(of: helper.canAct) { _, canAct inplan.follow(canUseHelper: canAct)@@ -180,11 +176,11 @@ struct AppDetailView: View {if PrivacyReset.isAllowed(bundleIdentifier: plan.app.bundleIdentifier), !plan.isAppInTheTrash {PrivacyResetRow(isOn: $resetsPrivacy, detail: PrivacyResetRow.beforeTheMove)}- if hasDockTile, !plan.isPeel {+ if plan.hasDockTile, !plan.isPeel {DockTileRow(isOn: $removesDockTile)}defaultsSection- PackageReceiptSection(app: plan.app, isExcluded: plan.isExcluded)+ PackageReceiptSection(plan: plan, rescan: rescan)}.dimmedWhileBusy(isAtWork).disabled(plan.isRemoving)diff --git a/Peel/Views/MultipleAppsView.swift b/Peel/Views/MultipleAppsView.swiftindex 553c1c70..722c9f4a 100644--- a/Peel/Views/MultipleAppsView.swift+++ b/Peel/Views/MultipleAppsView.swift@@ -11,7 +11,6 @@ struct MultipleAppsView: View {@State private var quitting = QuitBeforeRemoving()@State private var resetsPrivacy = false@State private var removesDockTiles = true- @State private var appsInTheDock: Set<URL> = []@State private var isRescanning = false@State private var questionTitle = Text(verbatim: "")@State private var questionNote = Text(verbatim: "")@@ -100,7 +99,7 @@ struct MultipleAppsView: View {}) {PrivacyResetRow(isOn: $resetsPrivacy, detail: PrivacyResetRow.beforeTheMove)}- if !appsInTheDock.isEmpty {+ if !plan.appsInTheDock.isEmpty {DockTileRow(isOn: $removesDockTiles)}}@@ -162,9 +161,6 @@ struct MultipleAppsView: View {guard !Task.isCancelled, !(plan.bulk == nil && plan.scanRun.wasStopped) else { return }await rescan()}- .task(id: plan.apps.map(\.url)) {- appsInTheDock = await DockTiles().holding(plan.apps.map(\.url))- }.rescanOnExclusionChange(scannedUnder: plan.exclusionsRevision) { await rescan() }.onChange(of: helper.canAct) { _, canAct inplan.follow(canUseHelper: canAct)@@ -360,7 +356,8 @@ struct MultipleAppsView: View {outcome.report(result, privacy: privacy, keptTheirFiles: kept.map(\.name))if removesDockTiles {let moved = Set(result.trashed.map(\.originalURL))- _ = await DockTiles().takeOut(appsInTheDock.filter(moved.contains).sorted { $0.path < $1.path })+ // Asked of every app that moved, since one opened after the last scan has a tile now.+ _ = await DockTiles().takeOut(plan.apps.map(\.url).filter(moved.contains).sorted { $0.path < $1.path })}if let state = AppManagement.state(after: result,diff --git a/Peel/Views/VendorNotes.swift b/Peel/Views/VendorNotes.swiftindex 845ea9e9..3fff68b6 100644--- a/Peel/Views/VendorNotes.swift+++ b/Peel/Views/VendorNotes.swift@@ -35,24 +35,17 @@ struct PackageReceiptSection: View {/// How many files are listed per receipt. The rest are counted, and the Package Receipts page lists them all.private static let mostListed = 12- let app: InstalledApp- /// True when the app is excluded. Its receipt then can't be forgotten, since the page promises that an- /// excluded app's files are left alone.- var isExcluded = false- @State private var receipts: [PackageReceipt] = []- /// What each package put outside the app. It is worked out once, with the receipts and off the main- /// actor, because it takes an `lstat` per file and the page is redrawn whenever a checkbox changes.- @State private var filesOutside: [PackageReceipt.ID: [PackageReceipt.Item]] = [:]+ let plan: RemovalPlan+ /// Scans the page again, which reads the receipts again: a receipt forgotten here also leaves its lists.+ let rescan: () async -> Void@State private var receiptToForget: PackageReceipt?@State private var isForgetting = false- /// The revision of the exclusions the last load read, nil before the first.- @State private var loadedUnder: Int?var body: some View {Group {- if !receipts.isEmpty {+ if !plan.packageReceipts.isEmpty {Section {- ForEach(receipts) { receipt in+ ForEach(plan.packageReceipts) { receipt inrows(for: receipt)}} header: {@@ -63,32 +56,12 @@ struct PackageReceiptSection: View {}}}- .task(id: app.id) { await load() }- .rescanOnExclusionChange(scannedUnder: loadedUnder) { await load() }.forgetReceiptDialog(for: $receiptToForget, forget: forget)}- private func load() async {- let revision = ExclusionsStore.shared.revision- (receipts, filesOutside) = await Self.receipts(of: app, exclusions: ExclusionsStore.shared.exclusions)- loadedUnder = revision- }-- @concurrent- private nonisolated static func receipts(- of app: InstalledApp,- exclusions: Exclusions- ) async -> ([PackageReceipt], [PackageReceipt.ID: [PackageReceipt.Item]]) {- let receipts = await PackageReceipts.receipts(installing: app.url, exclusions: exclusions)- let files = receipts.map {- ($0.id, VendorRemoval.filesOutsideBundle(of: $0, app: app, otherReceipts: receipts))- }- return (receipts, Dictionary(files, uniquingKeysWith: { first, _ in first }))- }-@ViewBuilderprivate func rows(for receipt: PackageReceipt) -> some View {- let files = filesOutside[receipt.id] ?? []+ let files = plan.filesOutside[receipt.id] ?? []VStack(alignment: .leading, spacing: 6) {HStack(spacing: 8) {Text(verbatim: receipt.identifier)@@ -103,8 +76,9 @@ struct PackageReceiptSection: View {.minimumTarget()}.buttonStyle(.borderless)- .disabled(isForgetting || !helper.canAct || isExcluded)- .help(isExcluded ? Text(.excludedApp) : helper.canAct ? Text("The receipt goes to the Trash. Files stay where they are.") : Text("Needs Peel’s helper. Settings says why it can’t act yet."))+ // The page promises that an excluded app's files are left alone, its receipt included.+ .disabled(isForgetting || !helper.canAct || plan.isExcluded)+ .help(plan.isExcluded ? Text(.excludedApp) : helper.canAct ? Text("The receipt goes to the Trash. Files stay where they are.") : Text("Needs Peel’s helper. Settings says why it can’t act yet."))}if files.isEmpty {Text("Outside the app, Peel found nothing that belongs to this package alone.")@@ -149,7 +123,7 @@ struct PackageReceiptSection: View {await record(result)return result}- await load()+ await rescan()return result}}