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.

Say Unknown for Homebrew's counts when it didn't say what is installed

Țugui Dragoș91c9fb1a47ba
diff --git a/Localization/Peel/Localizable.xcstrings b/Localization/Peel/Localizable.xcstrings
index ae3f3573..d4f08fa8 100644
--- a/Localization/Peel/Localizable.xcstrings
+++ b/Localization/Peel/Localizable.xcstrings
@@ -188469,6 +188469,119 @@
}
}
},
+ "Unknown (Homebrew count)" : {
+ "extractionState" : "extracted_with_value",
+ "localizations" : {
+ "cs" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Neznámá"
+ }
+ },
+ "de" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Unbekannt"
+ }
+ },
+ "en" : {
+ "stringUnit" : {
+ "state" : "new",
+ "value" : "Unknown"
+ }
+ },
+ "es" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Desconocido"
+ }
+ },
+ "fr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Inconnue"
+ }
+ },
+ "it" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Sconosciuta"
+ }
+ },
+ "ja" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "不明"
+ }
+ },
+ "ko" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "알 수 없음"
+ }
+ },
+ "nl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Onbekend"
+ }
+ },
+ "pl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Nieznana"
+ }
+ },
+ "pt" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Desconhecido"
+ }
+ },
+ "ro" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Necunoscută"
+ }
+ },
+ "ru" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Неизвестно"
+ }
+ },
+ "sv" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Okänd"
+ }
+ },
+ "tr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Bilinmiyor"
+ }
+ },
+ "uk" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Невідомо"
+ }
+ },
+ "zh-Hans" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "未知"
+ }
+ },
+ "zh-Hant" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "未知"
+ }
+ }
+ }
+ },
"Unknown (Homebrew location)" : {
"extractionState" : "extracted_with_value",
"localizations" : {
diff --git a/Peel/Model/HomebrewLibrary.swift b/Peel/Model/HomebrewLibrary.swift
index 79e0d532..955d48aa 100644
--- a/Peel/Model/HomebrewLibrary.swift
+++ b/Peel/Model/HomebrewLibrary.swift
@@ -192,8 +192,10 @@ final class HomebrewLibrary {
overrides.contains(.cleansUp) ? [] : outdated.filter(\.joinsUpgradeAll)
}
- func count(of kind: HomebrewPackage.Kind) -> Int {
- (packages ?? []).count { $0.kind == kind }
+ /// How many packages of `kind` are installed, or nil while Homebrew hasn't said what is installed.
+ func count(of kind: HomebrewPackage.Kind) -> Int? {
+ guard hasAnswered else { return nil }
+ return (packages ?? []).count { $0.kind == kind }
}
/// Reads again whether Homebrew is installed, which the sidebar's default for the Homebrew page follows.
diff --git a/Peel/Views/Homebrew/HomebrewList.swift b/Peel/Views/Homebrew/HomebrewList.swift
index 8dd4a46d..c67b2e18 100644
--- a/Peel/Views/Homebrew/HomebrewList.swift
+++ b/Peel/Views/Homebrew/HomebrewList.swift
@@ -30,6 +30,10 @@ struct HomebrewList: View {
.listRowSeparator(.hidden)
}
installation
+ // On macOS 27 what Homebrew said, or didn't, comes right under its section, before maintenance.
+ if #available(macOS 27, *) {
+ empty
+ }
overridden
maintenance
health
@@ -37,7 +41,9 @@ struct HomebrewList: View {
retired(homebrew.retired)
updates(outdated)
alreadyGone(homebrew.alreadyGone)
- empty
+ if #unavailable(macOS 27) {
+ empty
+ }
}
section(Text("Formulae"), packages: byKind[.formula] ?? [])
section(Text("Casks"), packages: byKind[.cask] ?? [])
@@ -208,10 +214,10 @@ struct HomebrewList: View {
}
.labeledContentStyle(.oneLine)
LabeledContent("Formulae") {
- Text(homebrew.count(of: .formula), format: .number).monospacedDigit()
+ count(of: .formula)
}
LabeledContent("Casks") {
- Text(homebrew.count(of: .cask), format: .number).monospacedDigit()
+ count(of: .cask)
}
} header: {
heading(
@@ -393,6 +399,13 @@ struct HomebrewList: View {
}
}
+ private func count(of kind: HomebrewPackage.Kind) -> Text {
+ guard let count = homebrew.count(of: kind) else {
+ return Text(verbatim: String(localized: "Unknown (Homebrew count)", defaultValue: "Unknown"))
+ }
+ return Text(count, format: .number).monospacedDigit()
+ }
+
@ViewBuilder
private var empty: some View {
if let problem = homebrew.couldNotRead {
diff --git a/PeelTests/HomebrewCountTests.swift b/PeelTests/HomebrewCountTests.swift
new file mode 100644
index 00000000..3ddae1d1
--- /dev/null
+++ b/PeelTests/HomebrewCountTests.swift
@@ -0,0 +1,14 @@
+import Foundation
+@testable import Peel
+import PeelCore
+import Testing
+
+@MainActor
+struct HomebrewCountTests {
+ @Test func countsNothingBeforeHomebrewSaidWhatIsInstalled() {
+ let homebrew = HomebrewLibrary()
+
+ #expect(homebrew.count(of: .formula) == nil)
+ #expect(homebrew.count(of: .cask) == nil)
+ }
+}