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.

Several apps' page works out its lists once per scan

Țugui Dragoșe37a4aafc15e
diff --git a/Packages/PeelCore/Sources/PeelCore/Removal/BulkUninstallation.swift b/Packages/PeelCore/Sources/PeelCore/Removal/BulkUninstallation.swift
index 999bcf0d..3cd5d887 100644
--- a/Packages/PeelCore/Sources/PeelCore/Removal/BulkUninstallation.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Removal/BulkUninstallation.swift
@@ -41,16 +41,13 @@ public struct BulkUninstallation: Sendable {
public let uninstallations: [Uninstallation]
public let items: [Item]
-
- public var apps: [InstalledApp] { uninstallations.map(\.app) }
/// The size of what could be moved, counted by the same rule as an app's own page: nothing the user
/// excluded, no app macOS protects, and no row that can never be moved. An unmeasured row is never counted
/// as zero: it makes the total incomplete.
- public var total: SizeTotal {
- SizeTotal(items
- .filter { !$0.isExcluded && !$0.isPeels && !($0.isApplication && $0.isKeptByMacOS) && !$0.isBeyondTheHelper && !$0.isInTheTrash && $0.match?.heldBack?.cannotBeMoved != true }
- .map { $0.isMeasured ? $0.size : nil })
- }
+ public let total: SizeTotal
+ public let privilegedURLs: Set<URL>
+
+ public var apps: [InstalledApp] { uninstallations.map(\.app) }
public var needsFullDiskAccess: Bool {
uninstallations.contains { $0.scan.needsFullDiskAccess }
}
@@ -59,8 +56,13 @@ public struct BulkUninstallation: Sendable {
}
public init(uninstallations: [Uninstallation]) {
+ let items = Self.merge(uninstallations)
self.uninstallations = uninstallations
- items = Self.merge(uninstallations)
+ self.items = items
+ total = SizeTotal(items
+ .filter { !$0.isExcluded && !$0.isPeels && !($0.isApplication && $0.isKeptByMacOS) && !$0.isBeyondTheHelper && !$0.isInTheTrash && $0.match?.heldBack?.cannotBeMoved != true }
+ .map { $0.isMeasured ? $0.size : nil })
+ privilegedURLs = Set(items.filter { $0.requiresPrivileges && !$0.isExcluded && !$0.isPeels && !$0.isBeyondTheHelper && !$0.isInTheTrash && !($0.isApplication && $0.isKeptByMacOS) }.map(\.url))
}
@concurrent
@@ -111,10 +113,6 @@ public struct BulkUninstallation: Sendable {
Set(uninstallations.filter { !$0.isAppInTheTrash && !selected.contains($0.app.url) }.map(\.app.bundleIdentifier))
}
- public var privilegedURLs: Set<URL> {
- Set(items.filter { $0.requiresPrivileges && !$0.isExcluded && !$0.isPeels && !$0.isBeyondTheHelper && !$0.isInTheTrash && !($0.isApplication && $0.isKeptByMacOS) }.map(\.url))
- }
-
/// Returns the selection in the order it is moved: leftovers first, then the apps. Excluded items and Peel's
/// are left out.
public func removalOrder(of selection: Set<URL>) -> [URL] {
diff --git a/Peel/Model/BulkRemovalPlan.swift b/Peel/Model/BulkRemovalPlan.swift
index e7e8b6ff..eef706f8 100644
--- a/Peel/Model/BulkRemovalPlan.swift
+++ b/Peel/Model/BulkRemovalPlan.swift
@@ -16,10 +16,25 @@ final class BulkRemovalPlan {
var isRemoving: Bool { question.isRemoving }
/// Every installed app as of the last scan, to tell a chosen app's processes from another installed app's.
private var installedApps: [InstalledApp] = []
- var selectedURLs: Set<URL> = []
+ var selectedURLs: Set<URL> = [] {
+ didSet { staying = bulk?.staying(selected: selectedURLs) ?? [] }
+ }
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.
private var canUseHelper = false
+ /// Worked out once per scan, because the page reads each of these on every change, and its list builds every
+ /// row again for each one.
+ private(set) var applications: [BulkUninstallation.Item] = []
+ /// The files Peel would select if their apps go, as an app's own page lists them under Recommended.
+ private(set) var recommendedFiles: [BulkUninstallation.Item] = []
+ /// The files nothing selects for the person, as an app's own page lists them under Review Before Removing.
+ 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> = []
+ private var measuredSizes: [URL: Int64] = [:]
+ /// The bundle identifiers of the chosen apps that stay (`BulkUninstallation.staying(selected:)`), worked out
+ /// again whenever the selection changes.
+ private(set) var staying: Set<String> = []
init(apps: [InstalledApp]) {
self.apps = apps
@@ -29,10 +44,7 @@ final class BulkRemovalPlan {
/// What a confirmation would ask about now: the selection, with the sizes this scan measured.
var request: RemovalRequest {
- RemovalRequest(
- urls: selectedURLs,
- sizes: [URL: Int64](measured: items.filter { selectedURLs.contains($0.url) }.map { ($0.url, $0.isMeasured ? $0.size : nil) })
- )
+ RemovalRequest(urls: selectedURLs, sizes: [URL: Int64](measured: selectedURLs.map { ($0, measuredSizes[$0]) }))
}
var total: SizeTotal { bulk?.total ?? SizeTotal(known: 0, isComplete: true) }
@@ -54,16 +66,6 @@ final class BulkRemovalPlan {
}
}
- /// The chosen apps already in the Trash, which neither go nor stay: only what they left behind can move.
- var appsInTheTrash: Set<URL> {
- Set(bulk?.uninstallations.filter(\.isAppInTheTrash).map(\.app.url) ?? [])
- }
-
- /// The bundle identifiers of the chosen apps that stay (`BulkUninstallation.staying(selected:)`).
- var staying: Set<String> {
- bulk?.staying(selected: selectedURLs) ?? []
- }
-
/// The revision of the exclusions the last scan read, nil before the first.
private(set) var exclusionsRevision: Int?
@@ -82,6 +84,11 @@ final class BulkRemovalPlan {
}) else { return }
bulk = result
exclusionsRevision = revision
+ applications = result.items.filter(\.isApplication)
+ recommendedFiles = result.items.filter { !$0.isApplication && $0.isRecommended }
+ filesToReview = result.items.filter { !$0.isApplication && !$0.isRecommended }
+ appsInTheTrash = Set(result.uninstallations.filter(\.isAppInTheTrash).map(\.app.url))
+ measuredSizes = [URL: Int64](measured: result.items.map { ($0.url, $0.isMeasured ? $0.size : nil) })
self.installedApps = installedApps
selectedURLs = choices.update(selectedURLs, in: result, canUseHelper: self.canUseHelper)
}
diff --git a/Peel/Views/MultipleAppsView.swift b/Peel/Views/MultipleAppsView.swift
index 108be052..1a6ddcb2 100644
--- a/Peel/Views/MultipleAppsView.swift
+++ b/Peel/Views/MultipleAppsView.swift
@@ -13,6 +13,8 @@ struct MultipleAppsView: View {
@State private var removesDockTiles = false
@State private var appsInTheDock: Set<URL> = []
@State private var isRescanning = false
+ @State private var questionTitle = Text(verbatim: "")
+ @State private var questionNote = Text(verbatim: "")
@Environment(RemovalOutcome.self) private var outcome
init(apps: [InstalledApp]) {
@@ -37,7 +39,7 @@ struct MultipleAppsView: View {
Section {
RemovalColumnHeaders()
- ForEach(Array(applications.enumerated()), id: \.element.id) { index, item in
+ ForEach(Array(plan.applications.enumerated()), id: \.element.id) { index, item in
row(item, isFirst: index == 0)
}
.listRowSeparator(.hidden)
@@ -45,10 +47,10 @@ struct MultipleAppsView: View {
Text("Apps")
}
- if !recommendedFiles.isEmpty {
+ if !plan.recommendedFiles.isEmpty {
Section {
RemovalColumnHeaders()
- ForEach(Array(recommendedFiles.enumerated()), id: \.element.id) { index, item in
+ ForEach(Array(plan.recommendedFiles.enumerated()), id: \.element.id) { index, item in
row(item, isFirst: index == 0)
}
.listRowSeparator(.hidden)
@@ -57,10 +59,10 @@ struct MultipleAppsView: View {
}
}
- if !filesToReview.isEmpty {
+ if !plan.filesToReview.isEmpty {
Section {
RemovalColumnHeaders()
- ForEach(Array(filesToReview.enumerated()), id: \.element.id) { index, item in
+ ForEach(Array(plan.filesToReview.enumerated()), id: \.element.id) { index, item in
row(item, isFirst: index == 0)
}
.listRowSeparator(.hidden)
@@ -107,17 +109,14 @@ struct MultipleAppsView: View {
}
}
}
- .confirmationDialog(
- Text.movingToTrash(plan.question.request?.urls.count ?? 0, plan.question.request?.total ?? SizeTotal([])),
- isPresented: Bindable(plan.question).isAsking
- ) {
+ .confirmationDialog(questionTitle, isPresented: Bindable(plan.question).isAsking) {
Button("Move to Trash") {
guard let request = plan.question.start() else { return }
Task { await remove(request) }
}
Button("Cancel", role: .cancel) {}
} message: {
- removalNote
+ questionNote
}
.alert("Quit these apps before removing them.", isPresented: Bindable(quitting).isAsking) {
Button("Quit Apps") { quitting.quit() }
@@ -162,20 +161,6 @@ struct MultipleAppsView: View {
return plan.scanRun.wasStopped ? .stopped : .scanning(.walk)
}
- private var applications: [BulkUninstallation.Item] {
- plan.items.filter(\.isApplication)
- }
-
- /// The files Peel would select if their apps go, as an app's own page lists them under Recommended.
- private var recommendedFiles: [BulkUninstallation.Item] {
- plan.items.filter { !$0.isApplication && $0.isRecommended }
- }
-
- /// The files nothing selects for the person, as an app's own page lists them under Review Before Removing.
- private var filesToReview: [BulkUninstallation.Item] {
- plan.items.filter { !$0.isApplication && !$0.isRecommended }
- }
-
private var header: some View {
HStack(alignment: .center, spacing: 18) {
AppStack(apps: plan.apps)
@@ -262,8 +247,7 @@ struct MultipleAppsView: View {
}
/// Under the question: which of the chosen apps go and which stay, and the privacy reset, which History can't undo.
- private var removalNote: Text {
- let urls = plan.question.request?.urls ?? []
+ private func note(about urls: Set<URL>) -> Text {
let going = plan.apps.filter { urls.contains($0.url) }
let staying = plan.apps.filter { !urls.contains($0.url) && !plan.appsInTheTrash.contains($0.url) }
var lines: [Text] = []
@@ -291,10 +275,17 @@ struct MultipleAppsView: View {
resetsPrivacy ? PrivacyReset.apps(among: plan.apps, moving: urls) : []
}
- /// Asks the question once the apps have quit, since none of their files moves while they run.
+ /// Asks the question once the apps have quit, since none of their files moves while they run. Its words are
+ /// worked out here, once, rather than with every change of the page: the note compares every chosen app with
+ /// every other.
private func requestRemoval() {
let plan = plan
- quitting.check(plan.runningProcesses) { plan.question.ask(plan.request) }
+ quitting.check(plan.runningProcesses) {
+ let request = plan.request
+ questionTitle = Text.movingToTrash(request.urls.count, request.total)
+ questionNote = note(about: request.urls)
+ plan.question.ask(request)
+ }
}
/// One removal, from the privacy reset before the move to the scan after it, with the page busy throughout.