From be49480732356a48c5630d5328f238a47945aea0 Mon Sep 17 00:00:00 2001 From: maxsoch Date: Mon, 6 Jul 2026 22:03:19 +0200 Subject: [PATCH] add UserDefaults-backed Settings storage MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Settings enum holds all upcoming settings-window preferences. Booleans default to false (disabled by default); includeGreedyCasks and confirmBeforeUpgradeAll default to true via register(defaults:), which provides fallbacks without writing to disk. Launch-at-login is not stored here — SMAppService will be its source of truth. Co-Authored-By: Claude Fable 5 --- BrewBar/BrewBarApp.swift | 2 ++ BrewBar/Settings.swift | 47 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 BrewBar/Settings.swift diff --git a/BrewBar/BrewBarApp.swift b/BrewBar/BrewBarApp.swift index 2179076..a57dd7f 100644 --- a/BrewBar/BrewBarApp.swift +++ b/BrewBar/BrewBarApp.swift @@ -43,6 +43,8 @@ class AppDelegate: NSObject, NSApplicationDelegate { // MARK: - Menu func applicationDidFinishLaunching(_: Notification) { + Settings.registerDefaults() + statusItem = NSStatusBar.system.statusItem(withLength: NSStatusItem.variableLength) setMenuBarIcon("brewbar-uptodate") diff --git a/BrewBar/Settings.swift b/BrewBar/Settings.swift new file mode 100644 index 0000000..60ab21b --- /dev/null +++ b/BrewBar/Settings.swift @@ -0,0 +1,47 @@ +import Foundation + +/// UserDefaults-backed app settings. Booleans read false for unset keys, +/// which covers the disabled-by-default settings; enabled-by-default ones +/// get their fallback via registerDefaults() (consulted only when the user +/// has never changed the value — nothing is written to disk). +/// +/// Launch-at-login is intentionally absent: SMAppService is its source of +/// truth, so storing a copy here could only drift out of sync. +enum Settings { + static func registerDefaults() { + UserDefaults.standard.register(defaults: [ + "includeGreedyCasks": true, + "confirmBeforeUpgradeAll": true, + ]) + } + + static var autoUpgradeFormulae: Bool { + get { UserDefaults.standard.bool(forKey: "autoUpgradeFormulae") } + set { UserDefaults.standard.set(newValue, forKey: "autoUpgradeFormulae") } + } + + static var autoUpgradeCasks: Bool { + get { UserDefaults.standard.bool(forKey: "autoUpgradeCasks") } + set { UserDefaults.standard.set(newValue, forKey: "autoUpgradeCasks") } + } + + static var notifyOnNewUpdates: Bool { + get { UserDefaults.standard.bool(forKey: "notifyOnNewUpdates") } + set { UserDefaults.standard.set(newValue, forKey: "notifyOnNewUpdates") } + } + + static var showCountInMenuBar: Bool { + get { UserDefaults.standard.bool(forKey: "showCountInMenuBar") } + set { UserDefaults.standard.set(newValue, forKey: "showCountInMenuBar") } + } + + static var includeGreedyCasks: Bool { + get { UserDefaults.standard.bool(forKey: "includeGreedyCasks") } + set { UserDefaults.standard.set(newValue, forKey: "includeGreedyCasks") } + } + + static var confirmBeforeUpgradeAll: Bool { + get { UserDefaults.standard.bool(forKey: "confirmBeforeUpgradeAll") } + set { UserDefaults.standard.set(newValue, forKey: "confirmBeforeUpgradeAll") } + } +}