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.

The menu bar panel counts updates as the menu bar item does

Țugui Dragoșbaeab34f332b
diff --git a/Peel/Model/AppLibrary.swift b/Peel/Model/AppLibrary.swift
index a6950024..85ef1536 100644
--- a/Peel/Model/AppLibrary.swift
+++ b/Peel/Model/AppLibrary.swift
@@ -88,16 +88,16 @@ final class AppLibrary {
private var updateRounds = UpdateRounds<InstalledApp.ID>() {
didSet {
if updateRounds.checking.isEmpty {
- heldUpdateCount = nil
+ heldUpdates = nil
} else if oldValue.checking.isEmpty {
- heldUpdateCount = appsWithUpdates.count
+ heldUpdates = Set(appsWithUpdates.map(\.id))
}
}
}
var appsCheckingForUpdates: Set<InstalledApp.ID> { updateRounds.checking }
- /// The update count when the current round of checks began. The menu bar shows it until the round ends,
- /// rather than a count that climbs as answers arrive seconds apart.
- private var heldUpdateCount: Int?
+ /// The apps with an update when the current round of checks began. The menu bar shows them until the round
+ /// ends, rather than a count that climbs as answers arrive seconds apart.
+ private var heldUpdates: Set<InstalledApp.ID>?
private(set) var sizes: [InstalledApp.ID: Int64] = [:] {
didSet { sizesRevision += 1 }
}
@@ -569,12 +569,15 @@ final class AppLibrary {
var appsWithUpdates: [InstalledApp] { apps.filter(hasUpdate) }
- /// The count the menu bar shows. It follows `hasUpdate(_:)`, but while a round of checks runs it keeps
- /// the count from when the round began.
- var menuBarUpdateCount: Int {
- heldUpdateCount ?? appsWithUpdates.count
+ /// The apps the menu bar item and its panel count. They follow `hasUpdate(_:)`, but while a round of checks runs
+ /// they are the ones from when the round began.
+ var menuBarUpdates: [InstalledApp] {
+ guard let heldUpdates else { return appsWithUpdates }
+ return apps.filter { heldUpdates.contains($0.id) }
}
+ var menuBarUpdateCount: Int { menuBarUpdates.count }
+
var updateSource: UpdateSource {
UpdateSource(rawValue: UserDefaults.standard.string(forKey: SettingsKey.updateSource) ?? "") ?? .automatic
}
diff --git a/Peel/Views/MenuBarPanel.swift b/Peel/Views/MenuBarPanel.swift
index e586158c..7da8d426 100644
--- a/Peel/Views/MenuBarPanel.swift
+++ b/Peel/Views/MenuBarPanel.swift
@@ -99,7 +99,7 @@ struct MenuBarPanel: View {
/// made room yet. Clipped, because a half-unfolded row would otherwise draw over the footer.
@ViewBuilder
private var updates: some View {
- let waiting = library.appsWithUpdates
+ let waiting = library.menuBarUpdates
VStack(spacing: 0) {
if let first = waiting.first {
Divider().padding(.leading, Self.wordsInset)