From 29b9412a344b115a0edc4f8bd44873e9f92aff3f Mon Sep 17 00:00:00 2001 From: maxsoch Date: Mon, 6 Jul 2026 22:08:51 +0200 Subject: [PATCH] add optional outdated count next to the menu bar icon Off by default. The status item button shows both image and title (imagePosition = .imageLeft), so the icon stays visible with the count beside it. Cleared when up to date or when the setting is off; toggling applies immediately from the cached list without refetching. Co-Authored-By: Claude Fable 5 --- BrewBar/BrewBarApp.swift | 10 ++++++++++ BrewBar/SettingsWindowController.swift | 14 ++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/BrewBar/BrewBarApp.swift b/BrewBar/BrewBarApp.swift index ba01324..e228628 100644 --- a/BrewBar/BrewBarApp.swift +++ b/BrewBar/BrewBarApp.swift @@ -49,6 +49,7 @@ class AppDelegate: NSObject, NSApplicationDelegate { Settings.registerDefaults() statusItem = NSStatusBar.system.statusItem(withLength: NSStatusItem.variableLength) + statusItem.button?.imagePosition = .imageLeft // icon stays visible next to the count setMenuBarIcon("brewbar-uptodate") let menu = NSMenu() @@ -268,6 +269,7 @@ class AppDelegate: NSObject, NSApplicationDelegate { self.updateOutdatedMenu(with: lines) self.updateStatus(count: lines.count) + self.updateMenuBarCount() self.notifyIfNeeded(outdated: lines) if lines.isEmpty { self.setMenuBarIcon("brewbar-uptodate") @@ -330,6 +332,14 @@ class AppDelegate: NSObject, NSApplicationDelegate { } } + func updateMenuBarCount() { + if Settings.showCountInMenuBar, !cachedOutdated.isEmpty { + statusItem.button?.title = " \(cachedOutdated.count)" + } else { + statusItem.button?.title = "" + } + } + func updateStatus(count: Int) { if count == 0 { statusMenuItem.title = "✅ All up to date" diff --git a/BrewBar/SettingsWindowController.swift b/BrewBar/SettingsWindowController.swift index 8905f34..a959879 100644 --- a/BrewBar/SettingsWindowController.swift +++ b/BrewBar/SettingsWindowController.swift @@ -20,6 +20,7 @@ class SettingsWindowController: NSWindowController { var autoUpgradeFormulaeCheckbox: NSButton! var autoUpgradeCasksCheckbox: NSButton! var notifyCheckbox: NSButton! + var showCountCheckbox: NSButton! convenience init(appDelegate: AppDelegate) { let window = NSWindow( @@ -116,6 +117,12 @@ class SettingsWindowController: NSWindowController { action: #selector(toggleNotify(_:)) ) + showCountCheckbox = NSButton( + checkboxWithTitle: "Show outdated count in the menu bar", + target: self, + action: #selector(toggleShowCount(_:)) + ) + let stack = NSStackView(views: [ frequencyRow, customRow, @@ -126,6 +133,7 @@ class SettingsWindowController: NSWindowController { caskWarningRow, separator(), notifyCheckbox, + showCountCheckbox, launchAtLoginCheckbox, ]) stack.orientation = .vertical @@ -165,6 +173,7 @@ class SettingsWindowController: NSWindowController { autoUpgradeFormulaeCheckbox.state = Settings.autoUpgradeFormulae ? .on : .off autoUpgradeCasksCheckbox.state = Settings.autoUpgradeCasks ? .on : .off notifyCheckbox.state = Settings.notifyOnNewUpdates ? .on : .off + showCountCheckbox.state = Settings.showCountInMenuBar ? .on : .off } func separator() -> NSBox { @@ -225,6 +234,11 @@ class SettingsWindowController: NSWindowController { } } + @objc func toggleShowCount(_ sender: NSButton) { + Settings.showCountInMenuBar = sender.state == .on + appDelegate?.updateMenuBarCount() // reflect immediately, no refetch needed + } + @objc func toggleLaunchAtLogin(_ sender: NSButton) { do { if sender.state == .on {