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.

Ask to quit with words that fit what runs and what goes

Țugui Dragoș836977c620cb
diff --git a/Localization/Peel/Localizable.xcstrings b/Localization/Peel/Localizable.xcstrings
index 4a02a098..ab96c2c6 100644
--- a/Localization/Peel/Localizable.xcstrings
+++ b/Localization/Peel/Localizable.xcstrings
@@ -134986,6 +134986,112 @@
}
}
},
+ "Quit these apps first." : {
+ "localizations" : {
+ "cs" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Nejprve tyto aplikace ukončete."
+ }
+ },
+ "de" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Beende diese Apps zuerst."
+ }
+ },
+ "es" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Sal primero de estas apps."
+ }
+ },
+ "fr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Quittez d’abord ces apps."
+ }
+ },
+ "it" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Prima esci da queste app."
+ }
+ },
+ "ja" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "先にこれらのアプリを終了してください。"
+ }
+ },
+ "ko" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "먼저 이 앱들을 종료하십시오."
+ }
+ },
+ "nl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Stop eerst deze apps."
+ }
+ },
+ "pl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Najpierw zakończ te aplikacje."
+ }
+ },
+ "pt" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Encerre estes apps primeiro."
+ }
+ },
+ "ro" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Mai întâi închideți aceste aplicații."
+ }
+ },
+ "ru" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Сначала завершите эти приложения."
+ }
+ },
+ "sv" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Avsluta de här apparna först."
+ }
+ },
+ "tr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Önce bu uygulamalardan çıkın."
+ }
+ },
+ "uk" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Спершу завершіть ці програми."
+ }
+ },
+ "zh-Hans" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "请先退出这些App。"
+ }
+ },
+ "zh-Hant" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "請先結束這些App。"
+ }
+ }
+ }
+ },
"Quotation marks stay as you typed them, which code needs." : {
"localizations" : {
"cs" : {
diff --git a/Peel/Model/BulkRemovalPlan.swift b/Peel/Model/BulkRemovalPlan.swift
index b6d7c99f..241188aa 100644
--- a/Peel/Model/BulkRemovalPlan.swift
+++ b/Peel/Model/BulkRemovalPlan.swift
@@ -67,17 +67,40 @@ final class BulkRemovalPlan {
var unreadableLocations: [SearchLocation] { bulk?.unreadableLocations ?? [] }
- /// The processes of the chosen apps with anything of theirs selected that run now, helpers included. Files never
- /// move out from under a running app, so an app that stays still quits before a file of its own moves.
+ /// What the alert asks: an app's own words when one runs, as its page says them, whether it goes or only its files
+ /// do, and for several, the plural when all of them go.
+ static func quitTitle(running: [InstalledApp], going: Set<URL>) -> LocalizedStringResource {
+ if running.count == 1, let app = running.first {
+ return going.contains(app.url) ? "Quit \(app.name) before removing it." : "Quit \(app.name) before removing its files."
+ }
+ return running.allSatisfy { going.contains($0.url) } ? "Quit these apps before removing them." : "Quit these apps first."
+ }
+
+ /// The chosen apps with anything of theirs selected that run now. 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 owningSelected.filter { app in
+ !RunningCopies.belonging(to: app, among: running, installedApps: installedApps).isEmpty
+ }
+ }
+
+ /// The processes of `runningApps`, helpers included, each once: two copies of an app share their helpers.
var runningProcesses: [NSRunningApplication] {
let running = RunningCopies.current
- let owners = Set(items.filter { selectedURLs.contains($0.url) }.flatMap(\.apps))
- return apps.filter { owners.contains($0.reference) }.flatMap { app in
+ var seen: Set<pid_t> = []
+ return owningSelected.flatMap { app in
RunningCopies.belonging(to: app, among: running, installedApps: installedApps)
+ .filter { seen.insert($0.identifier).inserted }
.compactMap { NSRunningApplication(processIdentifier: $0.identifier) }
}
}
+ private var owningSelected: [InstalledApp] {
+ let owners = Set(items.filter { selectedURLs.contains($0.url) }.flatMap(\.apps))
+ return apps.filter { owners.contains($0.reference) }
+ }
+
/// The revision of the exclusions the last scan read, nil before the first.
private(set) var exclusionsRevision: Int?
diff --git a/Peel/Model/QuitBeforeRemoving.swift b/Peel/Model/QuitBeforeRemoving.swift
index 165360fa..798c036d 100644
--- a/Peel/Model/QuitBeforeRemoving.swift
+++ b/Peel/Model/QuitBeforeRemoving.swift
@@ -27,8 +27,14 @@ final class QuitBeforeRemoving {
/// The names of what still runs, for the alerts.
var names: String {
- running.filter { !ended.contains($0.processIdentifier) }.map { $0.localizedName ?? $0.bundleIdentifier ?? "" }
- .formatted(.list(type: .and))
+ let open = running.filter { !ended.contains($0.processIdentifier) }
+ return Self.named(open.map { $0.localizedName ?? $0.bundleIdentifier ?? "" })
+ }
+
+ /// Each name once, and the first few of many, as an alert lists them.
+ static func named(_ names: [String]) -> String {
+ var seen: Set<String> = []
+ return RemovalFailureAlert.listed(names.filter { seen.insert($0).inserted })
}
/// Goes on at once when none of `processes` runs, and otherwise asks the person to quit them first.
diff --git a/Peel/Views/MultipleAppsView.swift b/Peel/Views/MultipleAppsView.swift
index 481413ee..4779c4e7 100644
--- a/Peel/Views/MultipleAppsView.swift
+++ b/Peel/Views/MultipleAppsView.swift
@@ -13,6 +13,7 @@ struct MultipleAppsView: View {
@State private var isRescanning = false
@State private var questionTitle = Text(verbatim: "")
@State private var questionNote = Text(verbatim: "")
+ @State private var quitTitle = Text(verbatim: "")
@Environment(RemovalOutcome.self) private var outcome
init(apps: [InstalledApp]) {
@@ -149,7 +150,7 @@ struct MultipleAppsView: View {
} message: {
questionNote
}
- .alert("Quit these apps before removing them.", isPresented: Bindable(quitting).isAsking) {
+ .alert(quitTitle, isPresented: Bindable(quitting).isAsking) {
Button("Quit Apps") { quitting.quit() }
Button("Cancel", role: .cancel) { quitting.giveUp() }
} message: {
@@ -332,6 +333,9 @@ struct MultipleAppsView: View {
private func requestRemoval() {
let plan = plan
let running = plan.runningProcesses
+ if !running.isEmpty {
+ quitTitle = Text(BulkRemovalPlan.quitTitle(running: plan.runningApps, going: plan.selectedURLs))
+ }
quitting.check(running) {
Task {
if !running.isEmpty {
diff --git a/PeelTests/QuitNamesTests.swift b/PeelTests/QuitNamesTests.swift
new file mode 100644
index 00000000..96826e83
--- /dev/null
+++ b/PeelTests/QuitNamesTests.swift
@@ -0,0 +1,31 @@
+import Foundation
+@testable import Peel
+import PeelCore
+import Testing
+
+@MainActor
+struct QuitNamesTests {
+ @Test func namesEachProcessOnceAndTheFirstFewOfMany() {
+ #expect(QuitBeforeRemoving.named(["Chat", "Chat Helper", "Chat Helper"]) == ["Chat", "Chat Helper"].formatted(.list(type: .and)))
+ let many = QuitBeforeRemoving.named(["A", "B", "C", "D", "E", "F"])
+ #expect(many == RemovalFailureAlert.listed(["A", "B", "C", "D", "E", "F"]))
+ #expect(many.contains("2"))
+ }
+
+ @Test func asksToQuitWithTheWordsThatFitWhatGoes() {
+ let editor = InstalledApp(
+ url: URL(filePath: "/Applications/Editor.app"), bundleIdentifier: "org.example.editor", name: "Editor"
+ )
+ let viewer = InstalledApp(
+ url: URL(filePath: "/Applications/Viewer.app"), bundleIdentifier: "org.example.viewer", name: "Viewer"
+ )
+ let title = { (apps: [InstalledApp], going: Set<URL>) in
+ String(localized: BulkRemovalPlan.quitTitle(running: apps, going: going))
+ }
+
+ #expect(title([editor], [editor.url]) == String(localized: "Quit \(editor.name) before removing it."))
+ #expect(title([editor], []) == String(localized: "Quit \(editor.name) before removing its files."))
+ #expect(title([editor, viewer], [editor.url, viewer.url]) == String(localized: "Quit these apps before removing them."))
+ #expect(title([editor, viewer], [editor.url]) == String(localized: "Quit these apps first."))
+ }
+}