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.

Forget Receipt says why it failed, in the alert every removal uses

Țugui Dragoșe4e20a627466
diff --git a/Localization/Peel/Localizable.xcstrings b/Localization/Peel/Localizable.xcstrings
index 38744f57..aea858f0 100644
--- a/Localization/Peel/Localizable.xcstrings
+++ b/Localization/Peel/Localizable.xcstrings
@@ -124310,112 +124310,6 @@
}
}
},
- "The receipt couldn’t be moved to the Trash." : {
- "localizations" : {
- "cs" : {
- "stringUnit" : {
- "state" : "translated",
- "value" : "Záznam o instalaci nelze přesunout do koše."
- }
- },
- "de" : {
- "stringUnit" : {
- "state" : "translated",
- "value" : "Die Quittung konnte nicht in den Papierkorb gelegt werden."
- }
- },
- "es" : {
- "stringUnit" : {
- "state" : "translated",
- "value" : "No se ha podido trasladar el recibo a la papelera."
- }
- },
- "fr" : {
- "stringUnit" : {
- "state" : "translated",
- "value" : "Impossible de placer le reçu dans la corbeille."
- }
- },
- "it" : {
- "stringUnit" : {
- "state" : "translated",
- "value" : "Impossibile spostare la ricevuta nel Cestino."
- }
- },
- "ja" : {
- "stringUnit" : {
- "state" : "translated",
- "value" : "レシートをゴミ箱に入れられませんでした。"
- }
- },
- "ko" : {
- "stringUnit" : {
- "state" : "translated",
- "value" : "수신 정보를 휴지통으로 이동할 수 없습니다."
- }
- },
- "nl" : {
- "stringUnit" : {
- "state" : "translated",
- "value" : "Het installatiebewijs kon niet naar de prullenmand worden verplaatst."
- }
- },
- "pl" : {
- "stringUnit" : {
- "state" : "translated",
- "value" : "Nie udało się przenieść potwierdzenia do Kosza."
- }
- },
- "pt" : {
- "stringUnit" : {
- "state" : "translated",
- "value" : "Não foi possível mover o recibo para o Lixo."
- }
- },
- "ro" : {
- "stringUnit" : {
- "state" : "translated",
- "value" : "Recipisa nu a putut fi mutată în Coș."
- }
- },
- "ru" : {
- "stringUnit" : {
- "state" : "translated",
- "value" : "Не удалось переместить квитанцию в Корзину."
- }
- },
- "sv" : {
- "stringUnit" : {
- "state" : "translated",
- "value" : "Kvittot kunde inte flyttas till papperskorgen."
- }
- },
- "tr" : {
- "stringUnit" : {
- "state" : "translated",
- "value" : "Makbuz Çöp Sepeti’ne taşınamadı."
- }
- },
- "uk" : {
- "stringUnit" : {
- "state" : "translated",
- "value" : "Не вдалося перемістити квитанцію в Смітник."
- }
- },
- "zh-Hans" : {
- "stringUnit" : {
- "state" : "translated",
- "value" : "未能将回执移到废纸篓。"
- }
- },
- "zh-Hant" : {
- "stringUnit" : {
- "state" : "translated",
- "value" : "無法將收據丟到「垃圾桶」。"
- }
- }
- }
- },
"The receipt goes to the Trash, so macOS no longer counts the package as installed. What it installed stays where it is." : {
"localizations" : {
"cs" : {
diff --git a/Packages/PeelCore/Sources/PeelCore/Packages/PackageActions.swift b/Packages/PeelCore/Sources/PeelCore/Packages/PackageActions.swift
index baa6d2c0..6838893a 100644
--- a/Packages/PeelCore/Sources/PeelCore/Packages/PackageActions.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Packages/PackageActions.swift
@@ -9,8 +9,12 @@ public enum PackageActions {
/// folder (empty, starting with `.`, or holding a `/`) gets no files.
static func receiptFiles(of identifier: String, onVolume volume: URL) -> [URL] {
guard !identifier.isEmpty, !identifier.hasPrefix("."), !identifier.contains("/") else { return [] }
- let folder = volume.appending(path: "private/var/db/receipts", directoryHint: .isDirectory)
- return ["bom", "plist"].map { folder.appending(path: identifier + "." + $0) }.filter(\.isThere)
+ return ["bom", "plist"].map { receiptsFolder(onVolume: volume).appending(path: identifier + "." + $0) }
+ .filter(\.isThere)
+ }
+
+ private static func receiptsFolder(onVolume volume: URL) -> URL {
+ volume.appending(path: "private/var/db/receipts", directoryHint: .isDirectory)
}
/// Moves the receipt to the Trash, so macOS stops counting the package as installed and History can put
@@ -24,7 +28,9 @@ public enum PackageActions {
static func forget(_ receipt: PackageReceipt, through service: TrashService) async -> TrashResult {
let files = receiptFiles(of: receipt.identifier, onVolume: receipt.volume)
guard !files.isEmpty else {
- return TrashResult(failures: [TrashFailure(url: receipt.volume, reason: .failed(Self.misplacedReceipt))])
+ // Named by the file macOS would keep, so the failure says which receipt rather than which disk.
+ let missing = receiptsFolder(onVolume: receipt.volume).appending(path: receipt.identifier + ".plist")
+ return TrashResult(failures: [TrashFailure(url: missing, reason: .failed(Self.misplacedReceipt))])
}
return await service.trash(files, usingHelperFor: Set(files))
}
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/PackageActionsTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/PackageActionsTests.swift
index ef0c95f7..4b42afeb 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/PackageActionsTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/PackageActionsTests.swift
@@ -59,7 +59,8 @@ struct PackageActionsTests {
#expect(result.failures.isEmpty)
}
- /// A receipt that is not there is a failure the user is told about, not a silent success.
+ /// A receipt that is not there is a failure the user is told about, not a silent success, and it names the
+ /// receipt rather than the disk it was looked for on.
@Test func aReceiptThatIsNotThereIsAFailure() async throws {
let directory = try TemporaryDirectory()
let service = TrashService(
@@ -70,6 +71,6 @@ struct PackageActionsTests {
let result = await PackageActions.forget(receipt("com.example.gone", on: directory.url), through: service)
#expect(result.trashed.isEmpty)
- #expect(!result.failures.isEmpty)
+ #expect(result.failures.map(\.url.lastPathComponent) == ["com.example.gone.plist"])
}
}
diff --git a/Peel/Views/Packages/ForgetReceiptDialog.swift b/Peel/Views/Packages/ForgetReceiptDialog.swift
index d9af68d3..4d4df56b 100644
--- a/Peel/Views/Packages/ForgetReceiptDialog.swift
+++ b/Peel/Views/Packages/ForgetReceiptDialog.swift
@@ -5,12 +5,12 @@ import SwiftUI
/// the app it installed. The receipt goes to the Trash and is recorded in History, like any other removal.
struct ForgetReceiptDialog: ViewModifier {
@Environment(RemovalHistoryStore.self) private var history
+ @Environment(RemovalOutcome.self) private var outcome
@Binding var receipt: PackageReceipt?
/// Forgets the receipt, records it with the closure it is given, then scans the receipts again, keeping its page
/// busy until all three are done. History is written first, because a scan can take a while and History is how
/// the user puts the receipt back.
let forget: (PackageReceipt, _ record: (TrashResult) async -> Void) async -> TrashResult
- @State private var failure: String?
func body(content: Content) -> some View {
content
@@ -24,20 +24,13 @@ struct ForgetReceiptDialog: ViewModifier {
}
await history.record(result, tool: .packages, source: receipt.identifier, sizes: sizes)
}
- if !result.failures.isEmpty {
- failure = result.failures.map { $0.url.abbreviatedPath }.joined(separator: "\n")
- }
+ outcome.report(result)
}
}
Button("Cancel", role: .cancel) {}
} message: { _ in
Text("The receipt goes to the Trash, so macOS no longer counts the package as installed. What it installed stays where it is.")
}
- .alert("The receipt couldn’t be moved to the Trash.", isPresented: isShowingFailure) {
- Button("OK", role: .cancel) {}
- } message: {
- Text(verbatim: failure ?? "")
- }
}
private var isAsking: Binding<Bool> {
@@ -46,13 +39,6 @@ struct ForgetReceiptDialog: ViewModifier {
set: { if !$0 { receipt = nil } }
)
}
-
- private var isShowingFailure: Binding<Bool> {
- Binding(
- get: { failure != nil },
- set: { if !$0 { failure = nil } }
- )
- }
}
extension View {