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
Keeping one of several apps keeps its files
Țugui Dragoșc8c38e02f317
diff --git a/ARCHITECTURE.md b/ARCHITECTURE.mdindex 7738e344..eb41720f 100644--- a/ARCHITECTURE.md+++ b/ARCHITECTURE.md@@ -72,7 +72,8 @@ Take the most common case, uninstalling an app. Every other page follows the samthat would stay. The user can change the selection freely, and what they choose stays through the page'slater scans and as the helper comes and goes: `KeptSelection` keeps the checkbox of every row they couldalready choose and gives Peel's suggestion only to a row they could not, and every page that selects for the- user and scans again on its own keeps its choices by it.+ user and scans again on its own keeps its choices by it. Among several apps, one whose bundle the user+ deselects stays, and its files leave the selection with it (`UninstallSelection`).5. **Move.** The question before the move freezes what it asks about, and the move takes exactly that(`RemovalQuestion`, which also runs one removal at a time and holds the page's scans until it is over).`TrashService` asks `RemovalGuard` about each item first, holds the folder around the item open, asks againdiff --git a/Localization/Peel/Localizable.xcstrings b/Localization/Peel/Localizable.xcstringsindex 8a5fbd5e..676438fc 100644--- a/Localization/Peel/Localizable.xcstrings+++ b/Localization/Peel/Localizable.xcstrings@@ -12193,6 +12193,112 @@}}},+ "Apps that go: %@" : {+ "localizations" : {+ "cs" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Aplikace, které se přesunou do koše: %@"+ }+ },+ "de" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Apps, die entfernt werden: %@"+ }+ },+ "es" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Apps que se van: %@"+ }+ },+ "fr" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Apps qui partent : %@"+ }+ },+ "it" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "App che vanno nel Cestino: %@"+ }+ },+ "ja" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "ゴミ箱に入るアプリ: %@"+ }+ },+ "ko" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "제거되는 앱: %@"+ }+ },+ "nl" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Apps die naar de prullenmand gaan: %@"+ }+ },+ "pl" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Aplikacje, które trafią do Kosza: %@"+ }+ },+ "pt" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Apps que vão para o Lixo: %@"+ }+ },+ "ro" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Aplicații care pleacă: %@"+ }+ },+ "ru" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Приложения, которые перемещаются в Корзину: %@"+ }+ },+ "sv" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Appar som flyttas: %@"+ }+ },+ "tr" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Gidecek uygulamalar: %@"+ }+ },+ "uk" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Програми, які буде вилучено: %@"+ }+ },+ "zh-Hans" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "将移除的App:%@"+ }+ },+ "zh-Hant" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "會移除的App:%@"+ }+ }+ }+ },"Apps that run in the background will appear here." : {"localizations" : {"cs" : {@@ -12299,6 +12405,112 @@}}},+ "Apps that stay: %@" : {+ "localizations" : {+ "cs" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Aplikace, které zůstanou: %@"+ }+ },+ "de" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Apps, die bleiben: %@"+ }+ },+ "es" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Apps que se quedan: %@"+ }+ },+ "fr" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Apps qui restent : %@"+ }+ },+ "it" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "App che restano: %@"+ }+ },+ "ja" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "残るアプリ: %@"+ }+ },+ "ko" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "남는 앱: %@"+ }+ },+ "nl" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Apps die blijven: %@"+ }+ },+ "pl" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Aplikacje, które pozostaną zainstalowane: %@"+ }+ },+ "pt" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Apps que ficam: %@"+ }+ },+ "ro" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Aplicații care rămân: %@"+ }+ },+ "ru" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Приложения, которые остаются: %@"+ }+ },+ "sv" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Appar som stannar kvar: %@"+ }+ },+ "tr" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Kalacak uygulamalar: %@"+ }+ },+ "uk" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Програми, які лишаться: %@"+ }+ },+ "zh-Hans" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "将保留的App:%@"+ }+ },+ "zh-Hant" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "會保留的App:%@"+ }+ }+ }+ },"Apps that use it may stop working." : {"localizations" : {"cs" : {@@ -32506,6 +32718,112 @@}}},+ "Found for %@" : {+ "localizations" : {+ "cs" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Nalezeno pro: %@"+ }+ },+ "de" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Gefunden für %@"+ }+ },+ "es" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Encontrado para %@"+ }+ },+ "fr" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Trouvé pour %@"+ }+ },+ "it" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Trovato per %@"+ }+ },+ "ja" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@について見つかりました"+ }+ },+ "ko" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@의 항목으로 찾음"+ }+ },+ "nl" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Gevonden voor %@"+ }+ },+ "pl" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Znaleziono dla aplikacji %@"+ }+ },+ "pt" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Encontrado para %@"+ }+ },+ "ro" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Găsit pentru %@"+ }+ },+ "ru" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Найдено для: %@"+ }+ },+ "sv" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Hittades för %@"+ }+ },+ "tr" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@ için bulundu"+ }+ },+ "uk" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Знайдено для: %@"+ }+ },+ "zh-Hans" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "为%@找到"+ }+ },+ "zh-Hant" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "為%@找到"+ }+ }+ }+ },"Free up space from inside the provider’s app" : {"localizations" : {"cs" : {@@ -64992,6 +65310,112 @@}}},+ "Not selected: it stays with %@." : {+ "localizations" : {+ "cs" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Nevybráno: zůstane, stejně jako aplikace %@."+ }+ },+ "de" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Nicht ausgewählt: Es bleibt bei %@."+ }+ },+ "es" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Sin seleccionar: se queda con %@."+ }+ },+ "fr" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Non sélectionné : cet élément reste avec %@."+ }+ },+ "it" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Non selezionato: resta con %@."+ }+ },+ "ja" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "未選択: %@と一緒に残ります。"+ }+ },+ "ko" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "선택되지 않음: 이 항목은 %@과(와) 함께 남습니다."+ }+ },+ "nl" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Niet geselecteerd: dit blijft bij %@."+ }+ },+ "pl" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Nie zaznaczono: zostaje, tak jak %@."+ }+ },+ "pt" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Não selecionado: fica com %@."+ }+ },+ "ro" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Neselectat: rămâne împreună cu %@."+ }+ },+ "ru" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Не выбрано: это остается, как и %@."+ }+ },+ "sv" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Inte markerad: den stannar kvar tillsammans med %@."+ }+ },+ "tr" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Seçilmedi: %@ ile birlikte kalır."+ }+ },+ "uk" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Не вибрано: елемент лишається разом із %@."+ }+ },+ "zh-Hans" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "未选择:它会随%@一起保留。"+ }+ },+ "zh-Hant" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "未選取:它會隨%@一起保留。"+ }+ }+ }+ },"Not selected: macOS wouldn’t let Peel read inside, so what is in there isn’t known. If Peel doesn’t have Full Disk Access yet, giving it in System Settings may let it see." : {"localizations" : {"cs" : {diff --git a/Packages/PeelCore/Sources/PeelCore/Removal/BulkUninstallation.swift b/Packages/PeelCore/Sources/PeelCore/Removal/BulkUninstallation.swiftindex a1c394fa..5317331f 100644--- a/Packages/PeelCore/Sources/PeelCore/Removal/BulkUninstallation.swift+++ b/Packages/PeelCore/Sources/PeelCore/Removal/BulkUninstallation.swift@@ -1,7 +1,7 @@public import Foundation-/// An uninstall of several apps at once. Each file is listed once, and a file shared only among the chosen-/// apps is safe to remove, since all of them are going.+/// An uninstall of several apps at once. Each file is listed once, and a file shared only among the chosen apps+/// can go with them, unless one of them stays (`staying(selected:)`).public struct BulkUninstallation: Sendable {public struct Item: Sendable, Hashable, Identifiable {public let url: URL@@ -89,6 +89,18 @@ public struct BulkUninstallation: Sendable {}.map(\.url))}+ /// The files of the app with `identifier`: its leftovers, and what it shares with another chosen app. Two copies+ /// of an app share these, and each has a bundle of its own.+ public func files(of identifier: String) -> Set<URL> {+ Set(items.filter { !$0.isApplication && $0.apps.contains(identifier) }.map(\.url))+ }++ /// The bundle identifiers of the chosen apps that stay: each one with a copy whose bundle is not selected. That+ /// includes an app that cannot go (`Uninstallation.appStays(canUseHelper:)`), since its bundle never is.+ public func staying(selected: Set<URL>) -> Set<String> {+ Set(uninstallations.filter { !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.isApplication && $0.isKeptByMacOS) }.map(\.url))}diff --git a/Packages/PeelCore/Sources/PeelCore/Removal/KeptSelection.swift b/Packages/PeelCore/Sources/PeelCore/Removal/KeptSelection.swiftindex 26ba9298..48f442ff 100644--- a/Packages/PeelCore/Sources/PeelCore/Removal/KeptSelection.swift+++ b/Packages/PeelCore/Sources/PeelCore/Removal/KeptSelection.swift@@ -24,6 +24,11 @@ public struct KeptSelection: Sendable {return made}+ /// True when the person could choose `url` after the last update.+ public func hasOffered(_ url: URL) -> Bool {+ offered[url] != nil+ }+/// Forgets what was chosen for `urls`, so the next update gives them Peel's suggestion as if they were new.public mutating func forget(_ urls: Set<URL>) {for url in urls {diff --git a/Packages/PeelCore/Sources/PeelCore/Removal/UninstallSelection.swift b/Packages/PeelCore/Sources/PeelCore/Removal/UninstallSelection.swiftindex 23762ea5..3d0794a9 100644--- a/Packages/PeelCore/Sources/PeelCore/Removal/UninstallSelection.swift+++ b/Packages/PeelCore/Sources/PeelCore/Removal/UninstallSelection.swift@@ -5,56 +5,103 @@ public import Foundation////// When an app comes to stay, what it holds was chosen for it going, so none of it stays selected: its files would/// go and leave it without them. When it can go again, Peel's suggestion comes back for it only if the person left-/// the selection as Peel made it.+/// the selection as Peel made it. On several apps' page, an app whose bundle the person deselects stays too, and+/// selecting the bundle again brings back its files as they were (`personChanged(from:to:in:)`). Two copies of an+/// app share its files, which stay while either copy does, and each copy's bundle goes or stays on its own.public struct UninstallSelection: Sendable {+ /// Whether an app stays, and what it holds: its files, and the bundle of each chosen copy.+ private struct App {+ var stays: Bool+ var files: Set<URL>+ var bundles: Set<URL>+ }+private var kept = KeptSelection()- /// Whether each app stayed at the last update, by bundle identifier.+ /// Whether each app stayed at the last change, by bundle identifier.private var stayed: [String: Bool] = [:]+ /// The files each app the person keeps had selected when they kept it, by bundle identifier.+ private var setAside: [String: Set<URL>] = [:]/// What a checkbox can select as of the last update.public private(set) var selectable: Set<URL> = []public init() {}public mutating func update(_ selected: Set<URL>, in uninstallation: Uninstallation, canUseHelper: Bool) -> Set<URL> {- let holds = Set(uninstallation.scan.leftovers.map(\.url)).union([uninstallation.app.url])+ let app = App(+ stays: uninstallation.appStays(canUseHelper: canUseHelper),+ files: Set(uninstallation.scan.leftovers.map(\.url)),+ bundles: [uninstallation.app.url]+ )return update(selected,- apps: [uninstallation.app.bundleIdentifier: (uninstallation.appStays(canUseHelper: canUseHelper), holds)],+ apps: [uninstallation.app.bundleIdentifier: app],selectable: uninstallation.selectable(canUseHelper: canUseHelper),suggested: uninstallation.suggestedSelection(canUseHelper: canUseHelper))}public mutating func update(_ selected: Set<URL>, in bulk: BulkUninstallation, canUseHelper: Bool) -> Set<URL> {- var apps: [String: (stays: Bool, holds: Set<URL>)] = [:]+ let selectable = bulk.selectable(canUseHelper: canUseHelper)+ var apps: [String: App] = [:]for uninstallation in bulk.uninstallations {let identifier = uninstallation.app.bundleIdentifier- let stays = uninstallation.appStays(canUseHelper: canUseHelper) || apps[identifier]?.stays == true- apps[identifier] = (stays, Set(bulk.items.filter { $0.apps.contains(identifier) }.map(\.url)))+ let bundle = uninstallation.app.url+ let isKept = kept.hasOffered(bundle) && selectable.contains(bundle) && !selected.contains(bundle)+ var app = apps[identifier] ?? App(stays: false, files: bulk.files(of: identifier), bundles: [])+ app.stays = app.stays || uninstallation.appStays(canUseHelper: canUseHelper) || isKept+ app.bundles.insert(bundle)+ apps[identifier] = app}return update(selected,apps: apps,- selectable: bulk.selectable(canUseHelper: canUseHelper),+ selectable: selectable,suggested: bulk.suggestedSelection(canUseHelper: canUseHelper))}- /// `apps` says, for each app by bundle identifier, whether it stays now and every item it holds.+ /// Carries a change the person made on several apps' page from `previous` to `selected` over to the files of+ /// each app it touches: an app whose bundle they deselect stays, so none of its files stays selected, and once+ /// every copy of it is selected again its files come back as they were.+ public mutating func personChanged(+ from previous: Set<URL>,+ to selected: Set<URL>,+ in bulk: BulkUninstallation+ ) -> Set<URL> {+ let staying = bulk.staying(selected: selected)+ var result = selected+ for identifier in bulk.staying(selected: previous).symmetricDifference(staying) {+ let files = bulk.files(of: identifier)+ if staying.contains(identifier) {+ setAside[identifier] = result.intersection(files)+ result.subtract(files)+ } else {+ result.formUnion((setAside.removeValue(forKey: identifier) ?? []).intersection(selectable))+ }+ stayed[identifier] = staying.contains(identifier)+ }+ return result+ }++ /// `apps` says, for each app by bundle identifier, whether it stays now and what it holds.private mutating func update(_ selected: Set<URL>,- apps: [String: (stays: Bool, holds: Set<URL>)],+ apps: [String: App],selectable: Set<URL>,suggested: Set<URL>) -> Set<URL> {var suggested = suggestedlet isAsMade = selected == kept.madefor (identifier, app) in apps {+ if app.stays {+ suggested.subtract(app.files)+ }guard let before = stayed[identifier], before != app.stays else { continue }+ let holds = app.files.union(app.bundles)if app.stays || isAsMade {- kept.forget(app.holds)+ kept.forget(holds)} else {- suggested.subtract(app.holds)+ suggested.subtract(holds)}}stayed = apps.mapValues(\.stays)diff --git a/Packages/PeelCore/Tests/PeelCoreTests/BulkUninstallationTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/BulkUninstallationTests.swiftindex f3904072..b172787b 100644--- a/Packages/PeelCore/Tests/PeelCoreTests/BulkUninstallationTests.swift+++ b/Packages/PeelCore/Tests/PeelCoreTests/BulkUninstallationTests.swift@@ -56,6 +56,23 @@ struct BulkUninstallationTests {}}+ /// An app stays when a copy of it is not selected. Two copies share their files, and neither bundle is one of+ /// them.+ @Test func namesTheAppsThatStayAndTheirFiles() {+ let notes = app("com.example.notes", "Notes")+ let copy = InstalledApp(url: URL(filePath: "/Users/x/Applications/Notes.app"), bundleIdentifier: notes.bundleIdentifier, name: notes.name)+ let mail = app("com.example.mail", "Mail")+ let own = leftover("/Users/x/Library/Caches/com.example.notes", size: 100)+ let shared = leftover("/Users/x/Library/Group Containers/group.com.example", size: 100)+ let bulk = BulkUninstallation(uninstallations: [uninstallation(notes, [own, shared]), uninstallation(copy, [own]), uninstallation(mail, [shared])])++ #expect(bulk.staying(selected: [notes.url, copy.url, mail.url]).isEmpty)+ #expect(bulk.staying(selected: [notes.url, mail.url]) == [notes.bundleIdentifier])+ #expect(bulk.staying(selected: [notes.url, copy.url]) == [mail.bundleIdentifier])+ #expect(bulk.files(of: notes.bundleIdentifier) == [own.url, shared.url])+ #expect(bulk.files(of: mail.bundleIdentifier) == [shared.url])+ }+/// A batch keeps the order an app's own page keeps: what could not be measured first among the leftovers, since/// it is most likely the biggest, then the largest. The apps come after their leftovers.@Test func listsWhatCouldNotBeMeasuredFirst() {diff --git a/Packages/PeelCore/Tests/PeelCoreTests/UninstallSelectionTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/UninstallSelectionTests.swiftindex 4d75269f..c3ddaa3b 100644--- a/Packages/PeelCore/Tests/PeelCoreTests/UninstallSelectionTests.swift+++ b/Packages/PeelCore/Tests/PeelCoreTests/UninstallSelectionTests.swift@@ -143,4 +143,78 @@ struct UninstallSelectionTests {_ = changed.update([], in: bulk, canUseHelper: false)#expect(changed.update([other.url], in: bulk, canUseHelper: true) == [other.url])}++ /// On several apps' page, deselecting one app's bundle keeps that app, so its files leave the selection, the+ /// file it shares with another chosen app included, and the other app keeps its own.+ @Test func deselectingOneOfSeveralAppsLeavesItsFiles() {+ let own = leftover("com.example.app")+ let others = leftover("com.example.other")+ let shared = leftover("com.example.shared")+ let bulk = BulkUninstallation(uninstallations: [uninstallation([own, shared]), uninstallation(of: other, [others, shared])])+ var choices = UninstallSelection()+ let suggested = choices.update([], in: bulk, canUseHelper: true)+ #expect(suggested == [app.url, own.url, shared.url, other.url, others.url])++ let selected = choices.personChanged(from: suggested, to: suggested.subtracting([other.url]), in: bulk)+ #expect(selected == [app.url, own.url])+ #expect(bulk.staying(selected: selected) == [other.bundleIdentifier])+ }++ /// Selecting the bundle again brings back the app's files as they were, and nothing more: a file the person had+ /// deselected before stays deselected.+ @Test func selectingTheBundleAgainBringsBackWhatWasSelected() {+ let others = leftover("com.example.other")+ let agent = leftover("com.example.other.agent")+ let bulk = BulkUninstallation(uninstallations: [uninstallation([]), uninstallation(of: other, [others, agent])])+ var choices = UninstallSelection()+ var selected = choices.update([], in: bulk, canUseHelper: true)+ selected = choices.personChanged(from: selected, to: selected.subtracting([agent.url]), in: bulk)++ selected = choices.personChanged(from: selected, to: selected.subtracting([other.url]), in: bulk)+ #expect(selected == [app.url])+ #expect(choices.personChanged(from: selected, to: selected.union([other.url]), in: bulk) == [app.url, other.url, others.url])+ }++ /// An app the person keeps stays kept through the page's scans: a file of it found later is not selected.+ @Test func aScanAfterAnAppWasKeptSelectsNothingOfIt() {+ let others = leftover("com.example.other")+ let later = leftover("com.example.other.later")+ let before = BulkUninstallation(uninstallations: [uninstallation([]), uninstallation(of: other, [others])])+ var choices = UninstallSelection()+ var selected = choices.update([], in: before, canUseHelper: true)+ selected = choices.personChanged(from: selected, to: selected.subtracting([other.url]), in: before)++ let after = BulkUninstallation(uninstallations: [uninstallation([]), uninstallation(of: other, [others, later])])+ #expect(choices.update(selected, in: after, canUseHelper: true) == [app.url])+ }++ /// Two copies of one app share its files, which stay while either copy does. Keeping one copy keeps them, and+ /// the other copy can still go, through the page's scans too.+ @Test func keepingOneOfTwoCopiesKeepsTheirFilesAndLetsTheOtherGo() {+ let copy = InstalledApp(url: URL(filePath: "/Users/me/Applications/Example.app"), bundleIdentifier: app.bundleIdentifier, name: app.name)+ let own = leftover("com.example.app")+ let bulk = BulkUninstallation(uninstallations: [uninstallation([own]), uninstallation(of: copy, [own])])+ var choices = UninstallSelection()+ let suggested = choices.update([], in: bulk, canUseHelper: true)+ #expect(suggested == [app.url, copy.url, own.url])++ let selected = choices.personChanged(from: suggested, to: suggested.subtracting([copy.url]), in: bulk)+ #expect(selected == [app.url])+ #expect(choices.update(selected, in: bulk, canUseHelper: true) == [app.url])+ }++ /// The files of two copies come back only once both are selected again.+ @Test func theFilesOfTwoCopiesComeBackOnceBothAreSelectedAgain() {+ let copy = InstalledApp(url: URL(filePath: "/Users/me/Applications/Example.app"), bundleIdentifier: app.bundleIdentifier, name: app.name)+ let own = leftover("com.example.app")+ let bulk = BulkUninstallation(uninstallations: [uninstallation([own]), uninstallation(of: copy, [own])])+ var choices = UninstallSelection()+ var selected = choices.update([], in: bulk, canUseHelper: true)++ selected = choices.personChanged(from: selected, to: selected.subtracting([copy.url]), in: bulk)+ selected = choices.personChanged(from: selected, to: selected.subtracting([app.url]), in: bulk)+ selected = choices.personChanged(from: selected, to: selected.union([app.url]), in: bulk)+ #expect(selected == [app.url])+ #expect(choices.personChanged(from: selected, to: selected.union([copy.url]), in: bulk) == [app.url, copy.url, own.url])+ }}diff --git a/Peel/Model/BulkRemovalPlan.swift b/Peel/Model/BulkRemovalPlan.swiftindex 22d5bccb..610e0bbe 100644--- a/Peel/Model/BulkRemovalPlan.swift+++ b/Peel/Model/BulkRemovalPlan.swift@@ -43,11 +43,19 @@ final class BulkRemovalPlan {var unreadableLocations: [SearchLocation] { bulk?.unreadableLocations ?? [] }- /// The chosen apps that are running, helpers included, and whose bundle is selected. An app whose bundle- /// the user deselected stays, so it is neither named nor quit.+ /// The chosen apps that are running, helpers included, with anything of theirs selected. Files never move out+ /// from under a running app, so an app that stays still quits before a file of its own moves.var runningApps: [InstalledApp] {let running = RunningCopies.current- return apps.filter { selectedURLs.contains($0.url) && !RunningCopies.belonging(to: $0, among: running, installedApps: installedApps).isEmpty }+ let owners = Set(items.filter { selectedURLs.contains($0.url) }.flatMap(\.apps))+ return apps.filter { app in+ owners.contains(app.bundleIdentifier) && !RunningCopies.belonging(to: app, among: running, installedApps: installedApps).isEmpty+ }+ }++ /// The bundle identifiers of the chosen apps that stay (`BulkUninstallation.staying(selected:)`).+ var staying: Set<String> {+ bulk?.staying(selected: selectedURLs) ?? []}func quitRunningApps() {@@ -83,6 +91,18 @@ final class BulkRemovalPlan {selectedURLs = choices.update(selectedURLs, in: bulk, canUseHelper: canUseHelper)}+ /// Selects or deselects one row. Deselecting an app's bundle keeps the app, so its files leave the selection+ /// with it (`UninstallSelection.personChanged(from:to:in:)`).+ func setSelected(_ isSelected: Bool, for url: URL) {+ var selected = selectedURLs+ if isSelected {+ selected.insert(url)+ } else {+ selected.remove(url)+ }+ selectedURLs = bulk.map { choices.personChanged(from: selectedURLs, to: selected, in: $0) } ?? selected+ }+/// Moves what `request` asked about, whatever has been selected since.func move(_ request: RemovalRequest) async -> TrashResult {guard let bulk else { return TrashResult() }diff --git a/Peel/Model/RowSelection.swift b/Peel/Model/RowSelection.swiftindex 42003a3f..f72b50ec 100644--- a/Peel/Model/RowSelection.swift+++ b/Peel/Model/RowSelection.swift@@ -6,6 +6,7 @@ import Foundation/// SwiftUI treats every row as changed and rebuilds all of them on every change.protocol RowSelection: AnyObject {var selectedURLs: Set<URL> { get set }+ func setSelected(_ isSelected: Bool, for url: URL)}extension RowSelection {diff --git a/Peel/Views/MultipleAppsView.swift b/Peel/Views/MultipleAppsView.swiftindex 2d35f9d8..e2ed8f28 100644--- a/Peel/Views/MultipleAppsView.swift+++ b/Peel/Views/MultipleAppsView.swift@@ -92,9 +92,7 @@ struct MultipleAppsView: View {}Button("Cancel", role: .cancel) {}} message: {- if !resetting(plan.question.request?.urls ?? []).isEmpty {- Text("The selected apps’ privacy permissions are cleared first, and History can’t bring them back.")- }+ removalNote}.alert("Quit these apps before removing them.", isPresented: $isShowingQuitAlert) {Button("Quit Apps") { plan.quitRunningApps() }@@ -170,6 +168,7 @@ struct MultipleAppsView: View {icon: item.isApplication ? .file(item.url) : .symbol(item.kind?.symbolName ?? "doc"),detail: item.isApplication ? "Application" : item.match?.reason.title,warning: warning(for: item),+ foundFor: item.isApplication ? nil : names(of: item.apps),size: item.size,isMeasured: item.isMeasured,isLocked: item.requiresPrivileges && !helper.canAct,@@ -182,13 +181,21 @@ struct MultipleAppsView: View {)}+ /// The names of the apps with these bundle identifiers, as a list.+ private func names(of identifiers: [String]) -> String {+ identifiers.map(library.name(forBundleIdentifier:)).formatted(.list(type: .and))+ }+/// The warning in a row's note, in the same words an app's own page uses: which other apps use the item,/// and why Peel did not select it or leaves it where it is.private func warning(for item: BulkUninstallation.Item) -> String? {var lines: [String] = []+ let keptBy = item.apps.filter(plan.staying.contains)+ if !item.isApplication, !keptBy.isEmpty, !item.isKeptByMacOS, !item.isPeels, !item.isExcluded {+ lines.append(String(localized: "Not selected: it stays with \(names(of: keptBy))."))+ }if !item.sharedWithOthers.isEmpty {- let names = item.sharedWithOthers.map(library.name(forBundleIdentifier:)).formatted(.list(type: .and))- lines.append(String(localized: "Also used by \(names)"))+ lines.append(String(localized: "Also used by \(names(of: item.sharedWithOthers))"))}if let heldBack = item.match?.heldBack {lines.append(String(localized: heldBack.explanation))@@ -208,6 +215,31 @@ struct MultipleAppsView: View {return lines.isEmpty ? nil : lines.joined(separator: "\n\n")}+ /// 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 ?? []+ let going = plan.apps.filter { urls.contains($0.url) }+ let staying = plan.apps.filter { !urls.contains($0.url) }+ var lines: [Text] = []+ if !going.isEmpty {+ lines.append(Text("Apps that go: \(list(going))"))+ }+ if !staying.isEmpty {+ lines.append(Text("Apps that stay: \(list(staying))"))+ }+ if !resetting(urls).isEmpty {+ lines.append(Text("The selected apps’ privacy permissions are cleared first, and History can’t bring them back."))+ }+ return lines.dropFirst().reduce(lines.first ?? Text(verbatim: "")) { Text("\($0)\n\n\($1)") }+ }++ /// These chosen apps as a list: each by its name, or by where it is when another chosen app has the same name.+ private func list(_ apps: [InstalledApp]) -> String {+ apps.map { app in+ plan.apps.contains { $0.name == app.name && $0.url != app.url } ? app.url.abbreviatedPath : app.name+ }.formatted(.list(type: .and))+ }+/// The apps whose privacy permissions a removal of `urls` resets.private func resetting(_ urls: Set<URL>) -> [InstalledApp] {resetsPrivacy ? PrivacyReset.apps(among: plan.apps, moving: urls) : []diff --git a/Peel/Views/RemovalRow.swift b/Peel/Views/RemovalRow.swiftindex 9589c811..eb21e9de 100644--- a/Peel/Views/RemovalRow.swift+++ b/Peel/Views/RemovalRow.swift@@ -13,6 +13,8 @@ struct RemovalRow: View {/// column is left out.var kind: LocalizedStringResource?var warning: String?+ /// On a page that lists several apps' files, the apps the item was found for, named first in its note.+ var foundFor: String?let size: Int64/// False when the size is not known, such as for a folder that did not answer in time. The row then/// reads "Unknown", never zero.@@ -224,6 +226,12 @@ struct RemovalRow: View {private var explanation: AttributedString {var text = AttributedString()+ if let foundFor {+ text += AttributedString(String(localized: "Found for \(foundFor)"))+ if detail != nil {+ text += AttributedString("\n\n")+ }+ }if let detail {text += AttributedString(String(localized: detail))}diff --git a/SAFETY.md b/SAFETY.mdindex 90476828..b7fec8f2 100644--- a/SAFETY.md+++ b/SAFETY.md@@ -134,7 +134,9 @@ Anything shared with another app is shown and left unselected. Something matchedanother app's folder, or one of Apple's, is shown and never selected, since it is most likely that app's data aboutthis one; so is something matched by name alone at the top of your home folder or of a Library, where a name isonly a guess. And nothing at all is selected for an app that would stay: one macOS keeps, one the helper may not-move, or one that needs the helper while it cannot act.+move, or one that needs the helper while it cannot act. 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.Peel itself is listed on its own page with what it keeps, and nothing of it can be selected there or among otherapps. It is removed only by Remove Peel, in Settings, which takes its helper and login item away first.