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
Name every open app that keeps part of a removal
Țugui Dragoșeb4fa3b3b92f
diff --git a/Localization/Peel/Localizable.xcstrings b/Localization/Peel/Localizable.xcstringsindex d4f08fa8..cf4970ff 100644--- a/Localization/Peel/Localizable.xcstrings+++ b/Localization/Peel/Localizable.xcstrings@@ -34267,6 +34267,112 @@}}},+ "Deselect Them" : {+ "localizations" : {+ "cs" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Odznačit je"+ }+ },+ "de" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Auswahl aufheben"+ }+ },+ "es" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Anular su selección"+ }+ },+ "fr" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Les désélectionner"+ }+ },+ "it" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Deselezionali"+ }+ },+ "ja" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "それらを選択解除"+ }+ },+ "ko" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "해당 항목 선택 해제"+ }+ },+ "nl" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Deselecteer ze"+ }+ },+ "pl" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Usuń ich zaznaczenie"+ }+ },+ "pt" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Desmarcá-los"+ }+ },+ "ro" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Deselectați‑le"+ }+ },+ "ru" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Снять с них выбор"+ }+ },+ "sv" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Avmarkera dem"+ }+ },+ "tr" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Bunların Seçimini Kaldır"+ }+ },+ "uk" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Зняти вибір з них"+ }+ },+ "zh-Hans" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "取消选择它们"+ }+ },+ "zh-Hant" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "取消選取它們"+ }+ }+ }+ },"Details" : {"localizations" : {"cs" : {@@ -135332,6 +135438,112 @@}}},+ "Quit %@ before removing their files." : {+ "localizations" : {+ "cs" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Než odstraníte soubory aplikací %@, ukončete je."+ }+ },+ "de" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Beende „%@“, bevor du die zugehörigen Dateien entfernst."+ }+ },+ "es" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Sal de %@ antes de eliminar sus archivos."+ }+ },+ "fr" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Quittez %@ avant de supprimer leurs fichiers."+ }+ },+ "it" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Esci da %@ prima di rimuovere i loro file."+ }+ },+ "ja" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "ファイルをゴミ箱に入れる前に、%@を終了してください。"+ }+ },+ "ko" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "파일을 제거하기 전에 %@을(를) 종료하십시오."+ }+ },+ "nl" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Stop %@ voordat je hun bestanden verwijdert."+ }+ },+ "pl" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Zakończ aplikacje %@, zanim przeniesiesz ich pliki do Kosza."+ }+ },+ "pt" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Encerre %@ antes de remover os arquivos deles."+ }+ },+ "ro" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Închideți %@ înainte de a le elimina fișierele."+ }+ },+ "ru" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Завершите %@, прежде чем удалять их файлы."+ }+ },+ "sv" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Avsluta %@ innan du tar bort deras filer."+ }+ },+ "tr" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "%@ dosyalarını kaldırmadan önce uygulamalardan çıkın."+ }+ },+ "uk" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "Завершіть програми %@, перш ніж вилучати їхні файли."+ }+ },+ "zh-Hans" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "请先退出“%@”,再移除它们的文件。"+ }+ },+ "zh-Hant" : {+ "stringUnit" : {+ "state" : "translated",+ "value" : "移除它們的檔案前,請先結束%@。"+ }+ }+ }+ },"Quit %@ before uninstalling." : {"localizations" : {"cs" : {diff --git a/Peel/Model/SelectionCarrier.swift b/Peel/Model/SelectionCarrier.swiftindex bf019e6a..a578bf74 100644--- a/Peel/Model/SelectionCarrier.swift+++ b/Peel/Model/SelectionCarrier.swift@@ -75,8 +75,9 @@ final class SelectionCarrier {)}- func appToQuit(among parts: [CarriedSelection.Part]) -> String? {- parts.lazy.compactMap { part in self.tool(of: part)?.appToQuit(for: part) }.first+ /// The parts an open app keeps, each with that app, in the order of `parts`.+ func kept(among parts: [CarriedSelection.Part]) -> [(part: CarriedSelection.Part, app: String)] {+ parts.compactMap { part in self.tool(of: part)?.appToQuit(for: part).map { (part, $0) } }}func deselect(_ part: CarriedSelection.Part) {diff --git a/Peel/Views/RemovalBar.swift b/Peel/Views/RemovalBar.swiftindex 4b943914..6462da1b 100644--- a/Peel/Views/RemovalBar.swift+++ b/Peel/Views/RemovalBar.swift@@ -9,7 +9,8 @@ struct RemovalBar: View {/// What the question asks about: the parts as they were when Move to Trash was pressed.@State private var question: [CarriedSelection.Part] = []@State private var isAsking = false- @State private var appToQuit = ""+ /// The open apps that keep part of the selection from moving, and those parts.+ @State private var kept: (apps: [String], parts: [CarriedSelection.Part]) = ([], [])@State private var isAskingToQuit = false@State private var isShowingPages = false/// The page's own words under the question, worked out when Move to Trash was pressed.@@ -249,7 +250,10 @@ struct RemovalBar: View {} message: {questionMessage}- .alert("Quit \(appToQuit) before removing its files.", isPresented: $isAskingToQuit) {+ .alert(quitTitle, isPresented: $isAskingToQuit) {+ Button("Deselect Them") {+ for part in kept.parts { carrier.deselect(part) }+ }Button("OK", role: .cancel) {}}}@@ -263,11 +267,18 @@ struct RemovalBar: View {.id(total.textKind)}- /// Asks before moving anything, unless an open app keeps one of the parts: then nothing moves until it quits- /// or its part is deselected.+ private var quitTitle: Text {+ guard kept.apps.count > 1 else { return Text("Quit \(kept.apps.first ?? "") before removing its files.") }+ return Text("Quit \(RemovalFailureAlert.listed(kept.apps)) before removing their files.")+ }++ /// Asks before moving anything, unless open apps keep some of the parts: then nothing moves until they quit or+ /// their parts are deselected, which the alert offers.private func ask(about parts: [CarriedSelection.Part]) {- if let app = carrier.appToQuit(among: parts) {- appToQuit = app+ let keptNow = carrier.kept(among: parts)+ if !keptNow.isEmpty {+ var named: Set<String> = []+ kept = (keptNow.map(\.app).filter { named.insert($0).inserted }, keptNow.map(\.part))isAskingToQuit = true} else {question = partsdiff --git a/PeelTests/SelectionCarrierTests.swift b/PeelTests/SelectionCarrierTests.swiftnew file mode 100644index 00000000..04d55b02--- /dev/null+++ b/PeelTests/SelectionCarrierTests.swift@@ -0,0 +1,48 @@+import Foundation+@testable import Peel+import PeelCore+import Testing++@MainActor+struct SelectionCarrierTests {+ private final class OpenApps: CarriesSelection {+ let openApps: [String: String]+ init(_ openApps: [String: String]) { self.openApps = openApps }+ var carriedParts: [CarriedSelection.Part] { [] }+ func appToQuit(for part: CarriedSelection.Part) -> String? { openApps[part.page.scope] }+ func move(_ part: CarriedSelection.Part, apps: AppLibrary) async -> TrashResult? { nil }+ func refresh(after parts: [CarriedSelection.Part], apps: AppLibrary) async {}+ func deselect(_ part: CarriedSelection.Part) {}+ }++ private func part(_ scope: String) -> CarriedSelection.Part {+ CarriedSelection.Part(+ page: Tool.developer.page(scope), title: scope, source: scope, sourceKey: nil,+ sizes: [URL(filePath: "/Users/me/Library/Caches/\(scope)"): 4_096]+ )+ }++ @Test func namesEveryOpenAppThatKeepsAPart() throws {+ let folder = FileManager.default.temporaryDirectory.appending(path: "PeelTests-\(UUID().uuidString)")+ defer { try? FileManager.default.removeItem(at: folder) }+ let made = try MadeUpDefaults()+ defer { made.forget() }+ let carrier = SelectionCarrier(+ tools: [.developer: OpenApps(["chrome": "Google Chrome", "slack": "Slack"])],+ apps: AppLibrary(+ defaults: made.defaults, releaseNotesStore: ReleaseNotesStore(url: folder.appending(path: "notes.json"))+ ),+ history: RemovalHistoryStore(+ log: RemovalLog(url: folder.appending(path: "removals.json")),+ refusals: RefusalLog(url: folder.appending(path: "refusals.json")),+ knowsTheExclusions: { true }+ ),+ outcome: RemovalOutcome()+ )++ let kept = carrier.kept(among: [part("chrome"), part("npm"), part("slack")])++ #expect(kept.map(\.app) == ["Google Chrome", "Slack"])+ #expect(kept.map(\.part.page.scope) == ["chrome", "slack"])+ }+}