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.

Count what a Put Back left in the Trash in its alert's title

Țugui Dragoș8198cae90d35
diff --git a/Localization/Peel/Localizable.xcstrings b/Localization/Peel/Localizable.xcstrings
index 8746866a..48215f14 100644
--- a/Localization/Peel/Localizable.xcstrings
+++ b/Localization/Peel/Localizable.xcstrings
@@ -94297,6 +94297,112 @@
}
}
},
+ "None of these could be put back." : {
+ "localizations" : {
+ "cs" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Žádnou z těchto položek nelze vrátit zpět."
+ }
+ },
+ "de" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Keines dieser Objekte konnte zurückgelegt werden."
+ }
+ },
+ "es" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "No se ha podido restaurar ninguno de estos ítems."
+ }
+ },
+ "fr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Aucun de ces éléments n’a pu être remis à sa place."
+ }
+ },
+ "it" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Non è stato possibile ripristinare nessuno di questi elementi."
+ }
+ },
+ "ja" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "どの項目も戻せませんでした。"
+ }
+ },
+ "ko" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "이 중 어떤 항목도 되돌려 놓을 수 없습니다."
+ }
+ },
+ "nl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Geen van deze onderdelen kon worden teruggezet."
+ }
+ },
+ "pl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Nie udało się przywrócić żadnej z tych rzeczy."
+ }
+ },
+ "pt" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Não foi possível colocar nenhum destes itens de volta."
+ }
+ },
+ "ro" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Niciunul dintre aceste articole nu a putut fi pus înapoi."
+ }
+ },
+ "ru" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Ни один из этих объектов не удалось восстановить."
+ }
+ },
+ "sv" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Inget av de här kunde läggas tillbaka."
+ }
+ },
+ "tr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Bunların hiçbiri yerine konamadı."
+ }
+ },
+ "uk" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Жодного з цих елементів не вдалося повернути."
+ }
+ },
+ "zh-Hans" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "这些项目都未能放回原处。"
+ }
+ },
+ "zh-Hant" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "這些項目都無法還原。"
+ }
+ }
+ }
+ },
"None of what you selected could be moved to the Trash. The reasons are below." : {
"localizations" : {
"cs" : {
@@ -155499,112 +155605,6 @@
}
}
},
- "Some items couldn’t be put back." : {
- "localizations" : {
- "cs" : {
- "stringUnit" : {
- "state" : "translated",
- "value" : "Některé položky nelze vrátit zpět."
- }
- },
- "de" : {
- "stringUnit" : {
- "state" : "translated",
- "value" : "Einige Objekte konnten nicht zurückgelegt werden."
- }
- },
- "es" : {
- "stringUnit" : {
- "state" : "translated",
- "value" : "No se han podido restaurar algunos ítems."
- }
- },
- "fr" : {
- "stringUnit" : {
- "state" : "translated",
- "value" : "Impossible de remettre certains éléments à leur place."
- }
- },
- "it" : {
- "stringUnit" : {
- "state" : "translated",
- "value" : "Impossibile ripristinare alcuni elementi."
- }
- },
- "ja" : {
- "stringUnit" : {
- "state" : "translated",
- "value" : "一部の項目を戻せませんでした。"
- }
- },
- "ko" : {
- "stringUnit" : {
- "state" : "translated",
- "value" : "일부 항목을 되돌려 놓을 수 없습니다."
- }
- },
- "nl" : {
- "stringUnit" : {
- "state" : "translated",
- "value" : "Sommige onderdelen konden niet worden teruggezet."
- }
- },
- "pl" : {
- "stringUnit" : {
- "state" : "translated",
- "value" : "Nie udało się przywrócić niektórych rzeczy."
- }
- },
- "pt" : {
- "stringUnit" : {
- "state" : "translated",
- "value" : "Não foi possível colocar alguns itens de volta."
- }
- },
- "ro" : {
- "stringUnit" : {
- "state" : "translated",
- "value" : "Unele articole nu au putut fi puse înapoi."
- }
- },
- "ru" : {
- "stringUnit" : {
- "state" : "translated",
- "value" : "Некоторые объекты не удалось восстановить."
- }
- },
- "sv" : {
- "stringUnit" : {
- "state" : "translated",
- "value" : "Vissa objekt kunde inte läggas tillbaka."
- }
- },
- "tr" : {
- "stringUnit" : {
- "state" : "translated",
- "value" : "Bazı öğeler yerine konamadı."
- }
- },
- "uk" : {
- "stringUnit" : {
- "state" : "translated",
- "value" : "Деякі елементи не вдалося повернути."
- }
- },
- "zh-Hans" : {
- "stringUnit" : {
- "state" : "translated",
- "value" : "部分项目未能放回原处。"
- }
- },
- "zh-Hant" : {
- "stringUnit" : {
- "state" : "translated",
- "value" : "部分項目無法還原。"
- }
- }
- }
- },
"Some items need administrator access" : {
"localizations" : {
"cs" : {
@@ -205320,6 +205320,346 @@
}
}
},
+ "^[%lld item](inflect: true) couldn’t be put back." : {
+ "localizations" : {
+ "cs" : {
+ "variations" : {
+ "plural" : {
+ "few" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "%lld položky nelze vrátit zpět."
+ }
+ },
+ "many" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "%lld položky nelze vrátit zpět."
+ }
+ },
+ "one" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "%lld položku nelze vrátit zpět."
+ }
+ },
+ "other" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "%lld položek nelze vrátit zpět."
+ }
+ }
+ }
+ }
+ },
+ "de" : {
+ "variations" : {
+ "plural" : {
+ "one" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "%lld Objekt konnte nicht zurückgelegt werden."
+ }
+ },
+ "other" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "%lld Objekte konnten nicht zurückgelegt werden."
+ }
+ }
+ }
+ }
+ },
+ "es" : {
+ "variations" : {
+ "plural" : {
+ "many" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "No se han podido restaurar %lld de ítems."
+ }
+ },
+ "one" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "No se ha podido restaurar un ítem."
+ }
+ },
+ "other" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "No se han podido restaurar %lld ítems."
+ }
+ }
+ }
+ }
+ },
+ "fr" : {
+ "variations" : {
+ "plural" : {
+ "many" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Impossible de remettre %lld d’éléments à leur place."
+ }
+ },
+ "one" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Impossible de remettre %lld élément à sa place."
+ }
+ },
+ "other" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Impossible de remettre %lld éléments à leur place."
+ }
+ }
+ }
+ }
+ },
+ "it" : {
+ "variations" : {
+ "plural" : {
+ "many" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Impossibile ripristinare %lld di elementi."
+ }
+ },
+ "one" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Impossibile ripristinare un elemento."
+ }
+ },
+ "other" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Impossibile ripristinare %lld elementi."
+ }
+ }
+ }
+ }
+ },
+ "ja" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "%lld項目を戻せませんでした。"
+ }
+ },
+ "ko" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "항목 %lld개를 되돌려 놓을 수 없습니다."
+ }
+ },
+ "nl" : {
+ "variations" : {
+ "plural" : {
+ "one" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "%lld onderdeel kon niet worden teruggezet."
+ }
+ },
+ "other" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "%lld onderdelen konden niet worden teruggezet."
+ }
+ }
+ }
+ }
+ },
+ "pl" : {
+ "variations" : {
+ "plural" : {
+ "few" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Nie udało się przywrócić %lld rzeczy."
+ }
+ },
+ "many" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Nie udało się przywrócić %lld rzeczy."
+ }
+ },
+ "one" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Nie udało się przywrócić %lld rzeczy."
+ }
+ },
+ "other" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Nie udało się przywrócić %lld rzeczy."
+ }
+ }
+ }
+ }
+ },
+ "pt" : {
+ "variations" : {
+ "plural" : {
+ "many" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Não foi possível colocar %lld de itens de volta."
+ }
+ },
+ "one" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Não foi possível colocar %lld item de volta."
+ }
+ },
+ "other" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Não foi possível colocar %lld itens de volta."
+ }
+ }
+ }
+ }
+ },
+ "ro" : {
+ "variations" : {
+ "plural" : {
+ "few" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "%lld articole nu au putut fi puse înapoi."
+ }
+ },
+ "one" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "%lld articol nu a putut fi pus înapoi."
+ }
+ },
+ "other" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "%lld de articole nu au putut fi puse înapoi."
+ }
+ }
+ }
+ }
+ },
+ "ru" : {
+ "variations" : {
+ "plural" : {
+ "few" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Не удалось восстановить %lld объекта."
+ }
+ },
+ "many" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Не удалось восстановить %lld объектов."
+ }
+ },
+ "one" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Не удалось восстановить %lld объект."
+ }
+ },
+ "other" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Не удалось восстановить %lld объекта."
+ }
+ }
+ }
+ }
+ },
+ "sv" : {
+ "variations" : {
+ "plural" : {
+ "one" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "%lld objekt kunde inte läggas tillbaka."
+ }
+ },
+ "other" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "%lld objekt kunde inte läggas tillbaka."
+ }
+ }
+ }
+ }
+ },
+ "tr" : {
+ "variations" : {
+ "plural" : {
+ "one" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "%lld öğe yerine konamadı."
+ }
+ },
+ "other" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "%lld öğe yerine konamadı."
+ }
+ }
+ }
+ }
+ },
+ "uk" : {
+ "variations" : {
+ "plural" : {
+ "few" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Не вдалося повернути %lld елементи."
+ }
+ },
+ "many" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Не вдалося повернути %lld елементів."
+ }
+ },
+ "one" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Не вдалося повернути %lld елемент."
+ }
+ },
+ "other" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Не вдалося повернути %lld елемента."
+ }
+ }
+ }
+ }
+ },
+ "zh-Hans" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "%lld个项目未能放回原处。"
+ }
+ },
+ "zh-Hant" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "%lld個項目無法還原。"
+ }
+ }
+ }
+ },
"^[%lld item](inflect: true) left the Trash" : {
"localizations" : {
"cs" : {
diff --git a/Peel/Model/RemovalHistoryStore.swift b/Peel/Model/RemovalHistoryStore.swift
index 65ee00e5..2daf1f6b 100644
--- a/Peel/Model/RemovalHistoryStore.swift
+++ b/Peel/Model/RemovalHistoryStore.swift
@@ -365,7 +365,7 @@ final class RemovalHistoryStore {
guard !stayed.isEmpty else { return }
outcome?.reportPutBack(stayed.map {
RemovalOutcome.PutBackFailure(url: $0.record.originalURL, failure: $0.failure)
- })
+ }, of: undoable.records.count)
// What stayed for a reason that can pass, such as the helper or something in its place, can be asked again.
let again = stayed.filter { !$0.failure.isFinal }.map(\.record)
if !again.isEmpty { self.undoable = (again, undoable.title) }
diff --git a/Peel/Model/RemovalOutcome.swift b/Peel/Model/RemovalOutcome.swift
index ec68a9d3..8229950b 100644
--- a/Peel/Model/RemovalOutcome.swift
+++ b/Peel/Model/RemovalOutcome.swift
@@ -36,6 +36,8 @@ final class RemovalOutcome {
private(set) var historyCouldNotRecord = false
/// What an Undo left in the Trash: Undo is asked from any page, so what came of it is told here.
private(set) var putBackFailures: [PutBackFailure] = []
+ /// How many items that Undo asked to put back.
+ private(set) var putBackAsked = 0
private(set) var movedCount = 0
var isEmpty: Bool {
@@ -48,8 +50,9 @@ final class RemovalOutcome {
historyCouldNotRecord = true
}
- func reportPutBack(_ failures: [PutBackFailure]) {
+ func reportPutBack(_ failures: [PutBackFailure], of asked: Int) {
putBackFailures = failures
+ putBackAsked = asked
}
/// Keeps what the removal could not do, what a restart or an emptied Trash finishes, and what stays for an
@@ -97,5 +100,6 @@ final class RemovalOutcome {
shellReferences = []
historyCouldNotRecord = false
putBackFailures = []
+ putBackAsked = 0
}
}
diff --git a/Peel/Views/History/HistoryDetailView.swift b/Peel/Views/History/HistoryDetailView.swift
index 093ea1c4..9c7e4edc 100644
--- a/Peel/Views/History/HistoryDetailView.swift
+++ b/Peel/Views/History/HistoryDetailView.swift
@@ -14,6 +14,8 @@ struct HistoryDetailView: View {
@State private var isShowingFailures = false
/// This batch's items that stayed in the Trash, in the order the page lists them.
@State private var failures: [(record: RemovalRecord, failure: RestoreFailure)] = []
+ /// How many items the last Put Back asked for, for the alert's title.
+ @State private var askedToPutBack = 0
let batch: RemovalBatch
/// The id of the page's task: the batch, and each time History was read again. When either changes, the page
@@ -49,6 +51,7 @@ struct HistoryDetailView: View {
) {
guard let standing else { return }
let selected = standing.selected(among: batch.records, in: history.selectedIDs)
+ askedToPutBack = selected.count
Task { await history.restore(selected, canUseHelper: helper.canAct) }
}
}
@@ -70,7 +73,10 @@ struct HistoryDetailView: View {
failures = batch.records.compactMap { record in all[record.id].map { (record, $0) } }
isShowingFailures = !failures.isEmpty
}
- .alert("Some items couldn’t be put back.", isPresented: $isShowingFailures) {
+ .alert(
+ Text(verbatim: RestoreFailure.title(stayed: failures.count, of: askedToPutBack)),
+ isPresented: $isShowingFailures
+ ) {
if failures.contains(where: { $0.failure == .needsAppManagement }) {
Button("Open System Settings") { NSWorkspace.shared.open(AppManagement.settingsURL) }
}
diff --git a/Peel/Views/Presentation.swift b/Peel/Views/Presentation.swift
index 873e02c0..57737b3a 100644
--- a/Peel/Views/Presentation.swift
+++ b/Peel/Views/Presentation.swift
@@ -266,6 +266,15 @@ extension RestoreFailure {
}
}
+extension RestoreFailure {
+ /// The title of the alert after a Put Back of `asked` items that left `stayed` of them in the Trash.
+ static func title(stayed: Int, of asked: Int) -> String {
+ asked > 1 && stayed >= asked
+ ? String(localized: "None of these could be put back.")
+ : String(inflecting: "^[\(stayed) item](inflect: true) couldn’t be put back.")
+ }
+}
+
extension CloudRefusal {
/// Why a file's local copy was not freed. Freeing deletes nothing, since the file stays in iCloud, so no
/// way back is offered.
diff --git a/Peel/Views/RemovalFailureAlert.swift b/Peel/Views/RemovalFailureAlert.swift
index 06f40ac9..71ed3739 100644
--- a/Peel/Views/RemovalFailureAlert.swift
+++ b/Peel/Views/RemovalFailureAlert.swift
@@ -88,7 +88,7 @@ struct RemovalFailureAlert: ViewModifier {
return Text("History couldn’t record this removal.")
}
if !outcome.putBackFailures.isEmpty, outcome.failures.isEmpty {
- return Text("Some items couldn’t be put back.")
+ return Text(verbatim: RestoreFailure.title(stayed: outcome.putBackFailures.count, of: outcome.putBackAsked))
}
if #available(macOS 27, *), !outcome.appsStartingFromTheTrash.isEmpty, outcome.failures.isEmpty,
outcome.appsToQuit.isEmpty, outcome.privacy.isEmpty {
diff --git a/PeelTests/PutBackTitleTests.swift b/PeelTests/PutBackTitleTests.swift
new file mode 100644
index 00000000..f8c048ed
--- /dev/null
+++ b/PeelTests/PutBackTitleTests.swift
@@ -0,0 +1,13 @@
+import Foundation
+@testable import Peel
+import PeelCore
+import Testing
+
+@MainActor
+struct PutBackTitleTests {
+ @Test func countsWhatStayedAndSaysWhenNothingWentBack() {
+ #expect(RestoreFailure.title(stayed: 1, of: 1) == "1 item couldn’t be put back.")
+ #expect(RestoreFailure.title(stayed: 2, of: 5) == "2 items couldn’t be put back.")
+ #expect(RestoreFailure.title(stayed: 3, of: 3) == "None of these could be put back.")
+ }
+}
diff --git a/PeelTests/RemovalFailureAlertTests.swift b/PeelTests/RemovalFailureAlertTests.swift
index b887ce74..bb7efe69 100644
--- a/PeelTests/RemovalFailureAlertTests.swift
+++ b/PeelTests/RemovalFailureAlertTests.swift
@@ -30,7 +30,7 @@ struct RemovalFailureAlertTests {
let outcome = RemovalOutcome()
outcome.reportPutBack([
.init(url: URL(filePath: "/Applications/Example.app"), failure: .needsAppManagement),
- ])
+ ], of: 1)
let message = RemovalFailureAlert.message(for: outcome)
diff --git a/PeelTests/RemovalOutcomeTests.swift b/PeelTests/RemovalOutcomeTests.swift
index 00336994..93dd67e2 100644
--- a/PeelTests/RemovalOutcomeTests.swift
+++ b/PeelTests/RemovalOutcomeTests.swift
@@ -74,6 +74,7 @@ struct RemovalOutcomeTests {
await history.undoLastRemoval()
#expect(outcome.putBackFailures.map(\.url.lastPathComponent) == ["Driver"])
+ #expect(outcome.putBackAsked == 2)
#expect(outcome.putBackFailures.first?.failure == .needsHelper)
#expect(history.undoTitle != nil, "what stayed can be put back once the helper can")
}