diff --git a/Brewlet/PreferencesController.swift b/Brewlet/PreferencesController.swift index 76a60bf..033dee0 100644 --- a/Brewlet/PreferencesController.swift +++ b/Brewlet/PreferencesController.swift @@ -24,9 +24,18 @@ class PreferencesController: NSWindowController { @IBOutlet weak var autoUpgrade: NSButton! @IBOutlet weak var dontNotifyAvailable: NSButton! @IBOutlet weak var brewPath: NSTextField! - + @IBOutlet weak var intel: NSButton! + @IBOutlet weak var appleSilicon: NSButton! + @IBOutlet weak var custom: NSButton! + var delegate: PreferencesDelegate? + enum HomebrewPath: String { + case appleSilicon = "/opt/homebrew/bin/brew" + case intel = "/usr/local/bin/brew" + case custom = "" + } + override func windowDidLoad() { super.windowDidLoad() @@ -60,8 +69,20 @@ class PreferencesController: NSWindowController { autoUpgrade.state = defaults.bool(forKey: "autoUpgrade") ? .on : .off dontNotifyAvailable.state = defaults.bool(forKey: "dontNotify") ? .on : .off - let currentBrewPath = defaults.string(forKey: "brewPath") ?? "/usr/local/bin/brew" - brewPath.stringValue = currentBrewPath + #if arch(arm64) + let currentBrewPath = defaults.string(forKey: "brewPath") ?? HomebrewPath.appleSilicon.rawValue + #elseif arch(x86_64) + let currentBrewPath = defaults.string(forKey: "brewPath") ?? HomebrewPath.intel.rawValue + #endif + switch currentBrewPath { + case HomebrewPath.intel.rawValue: + intelSelected(nil) + case HomebrewPath.appleSilicon.rawValue: + appleSiliconSelected(nil) + default: + custom.state = .on + brewPath.stringValue = currentBrewPath + } } @IBAction func includeDependenciesPressed(_ sender: NSButton) { @@ -96,6 +117,34 @@ class PreferencesController: NSWindowController { delegate?.updateIntervalChanged(newInterval: seconds) } + @IBAction func appleSiliconSelected(_ sender: Any?) { + appleSilicon.state = .on + intel.state = .off + custom.state = .off + brewPath.isEnabled = false + let path = HomebrewPath.appleSilicon.rawValue + brewPath.stringValue = path + delegate?.brewPathChanged(newPath: path) + } + + @IBAction func intelSelected(_ sender: Any?) { + intel.state = .on + appleSilicon.state = .off + custom.state = .off + brewPath.isEnabled = false + let path = HomebrewPath.intel.rawValue + brewPath.stringValue = path + delegate?.brewPathChanged(newPath: path) + } + + @IBAction func customSelected(_ sender: Any) { + custom.state = .on + appleSilicon.state = .off + intel.state = .off + brewPath.isEnabled = true + delegate?.brewPathChanged(newPath: brewPath.stringValue) + } + @IBAction func brewPathChanged(_ sender: NSTextField) { // TODO: Validate that the path is valid delegate?.brewPathChanged(newPath: sender.stringValue) diff --git a/Brewlet/PreferencesController.xib b/Brewlet/PreferencesController.xib index bf353ce..c811c4d 100644 --- a/Brewlet/PreferencesController.xib +++ b/Brewlet/PreferencesController.xib @@ -8,10 +8,13 @@ + + + @@ -22,14 +25,14 @@ - + - + - + @@ -39,7 +42,7 @@ - + @@ -48,16 +51,16 @@ - + - + - + @@ -66,7 +69,7 @@ - + @@ -75,7 +78,7 @@ - + @@ -84,7 +87,7 @@ - - + + - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + - +