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.

Tell receipts apart in the question before Forget All

Țugui Dragoș7e0c0677ed80
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 8542a0ca..3382f733 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -547,6 +547,8 @@ its changes the way [Keep a Changelog](https://keepachangelog.com/) suggests.
- Lists a package installed for your account alone, and Forget Receipt and an uninstall find its receipt in your
Library.
+- The question before Forget All names each receipt by its identifier when the packages of one installer share a name,
+ which it repeated.
- A folder is offered whole only when nothing inside it is missing from the receipt, and every item follows its app's
rules, an app that uninstalls itself with its warning.
- A package placed by its own scripts is never called a receipt only, a package installed into an app offers the app
diff --git a/Packages/PeelCore/Sources/PeelCore/Packages/PackageReceipt.swift b/Packages/PeelCore/Sources/PeelCore/Packages/PackageReceipt.swift
index 40230977..ed3b36e9 100644
--- a/Packages/PeelCore/Sources/PeelCore/Packages/PackageReceipt.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Packages/PackageReceipt.swift
@@ -63,6 +63,15 @@ public struct PackageReceipt: Sendable, Hashable, Identifiable {
/// `version` is the package's own number.
public var productVersion: String?
+ /// What a list in a question calls each of `receipts`: its name, unless another of them has it too, as the packages
+ /// of one installer do, which is no way to tell them apart.
+ public static func names(of receipts: [PackageReceipt]) -> [String] {
+ let counts = Dictionary(receipts.compactMap(\.name).map { ($0, 1) }, uniquingKeysWith: +)
+ return receipts.map { receipt in
+ receipt.name.flatMap { counts[$0] == 1 ? $0 : nil } ?? receipt.identifier
+ }
+ }
+
/// A package can be installed on the startup disk and for an account too, each with a receipt of its own.
public var id: String {
let place = volume.path(percentEncoded: false)
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/PackageReceiptsTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/PackageReceiptsTests.swift
index 36ef5059..71d006fc 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/PackageReceiptsTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/PackageReceiptsTests.swift
@@ -1260,4 +1260,21 @@ struct PackageReceiptsTests {
#expect(history["org.example.a"] == InstallHistory.Entry(name: "Tools", version: "26.5"))
#expect(history["org.example.b"] == InstallHistory.Entry(name: "Plain", version: nil))
}
+
+ @Test func aQuestionNamesAReceiptByANameOnlyItHas() {
+ func receipt(_ identifier: String, _ name: String?) -> PackageReceipt {
+ var receipt = PackageReceipt(
+ identifier: identifier, version: "1", installDate: nil, volume: URL(filePath: "/"), items: []
+ )
+ receipt.name = name
+ return receipt
+ }
+
+ let names = PackageReceipt.names(of: [
+ receipt("org.example.word", "Office"), receipt("org.example.excel", "Office"),
+ receipt("org.example.tool", "Tool"), receipt("org.example.plain", nil),
+ ])
+
+ #expect(names == ["org.example.word", "org.example.excel", "Tool", "org.example.plain"])
+ }
}
diff --git a/Peel/Views/Packages/ForgetReceiptDialog.swift b/Peel/Views/Packages/ForgetReceiptDialog.swift
index 7ad95bf5..24b9ed54 100644
--- a/Peel/Views/Packages/ForgetReceiptDialog.swift
+++ b/Peel/Views/Packages/ForgetReceiptDialog.swift
@@ -75,7 +75,7 @@ struct ForgetReceiptsDialog: ViewModifier {
Button("Forget All") { forget(receipts) }
Button("Cancel", role: .cancel) {}
} message: { receipts in
- Text("Their receipts go to the Trash, so macOS no longer counts these packages as installed. Nothing they put on this Mac is left, and History can put the receipts back.\n\n\(RemovalFailureAlert.firstItems(receipts.map { $0.name ?? $0.identifier }).joined(separator: "\n"))")
+ Text("Their receipts go to the Trash, so macOS no longer counts these packages as installed. Nothing they put on this Mac is left, and History can put the receipts back.\n\n\(RemovalFailureAlert.firstItems(PackageReceipt.names(of: receipts)).joined(separator: "\n"))")
}
}