Skip to content

Commit

Permalink
Add preference to only upgrade formula
Browse files Browse the repository at this point in the history
  • Loading branch information
Zaid Kokaja committed Nov 6, 2022
1 parent 9c28d01 commit 0bfe3ad
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 26 deletions.
11 changes: 8 additions & 3 deletions Brewlet/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,11 @@ class AppDelegate: NSObject, NSApplicationDelegate, PreferencesDelegate {
*/
@IBAction func update_upgrade(sender: NSMenuItem?) {
let animation = animateIcon()

var upgrade_command = "upgrade"
if self.userDefaults.bool(forKey: "dontUpgradeCasks") {
upgrade_command += " --formula"
}

// Determine which packages to include
let includeDependencies = self.userDefaults.bool(forKey: "includeDependencies")
Expand All @@ -148,18 +153,18 @@ class AppDelegate: NSObject, NSApplicationDelegate, PreferencesDelegate {

let shouldUpgrade = self.packages.filter(criterion).count > 0

let command = shouldUpgrade && sender != nil ? "upgrade" : "update"
let command = shouldUpgrade && sender != nil ? upgrade_command : "update"
let tmpFile = getLogFile()

let updateItem = self.statusMenu.item(withTag: self.name2tag["update"]!)!
updateItem.isEnabled = false
updateItem.title = command == "upgrade" ? "Upgrading..." : "Updating..."
updateItem.title = command == "update" ? "Updating..." : "Upgrading..."

let packageItem = self.statusMenu.item(withTag: self.name2tag["packages"]!)!
packageItem.isEnabled = false

self.run_command(arguments: [command], fileRedirect: tmpFile) { _,_ in
os_log("Ran %s command.", type: .info, command)
os_log("Ran command: `%s`.", type: .info, command)

updateItem.isEnabled = true
animation.invalidate()
Expand Down
6 changes: 6 additions & 0 deletions Brewlet/PreferencesController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class PreferencesController: NSWindowController {
@IBOutlet weak var shareAnalytics: NSButton!
@IBOutlet weak var autoUpgrade: NSButton!
@IBOutlet weak var dontNotifyAvailable: NSButton!
@IBOutlet weak var dontUpgradeCasks: NSButton!
@IBOutlet weak var brewPath: NSTextField!
@IBOutlet weak var intel: NSButton!
@IBOutlet weak var appleSilicon: NSButton!
Expand Down Expand Up @@ -103,6 +104,11 @@ class PreferencesController: NSWindowController {
UserDefaults.standard.set(sender.state == .on, forKey: "dontNotify")
}

@IBAction func dontUpgradeCasksChanged(_ sender: NSButton) {
os_log("Update don't upgrade casks: %s", type: .info, sender.state == .on ? "on" : "off")
UserDefaults.standard.set(sender.state == .on, forKey: "dontUpgradeCasks")
}

@IBAction func updateIntervalChanged(_ sender: NSSlider) {

var seconds: TimeInterval? = nil
Expand Down

0 comments on commit 0bfe3ad

Please sign in to comment.