feat: better chec-updates logging#162
Conversation
Co-authored-by: paolomainardi <8747+paolomainardi@users.noreply.github.com>
Co-authored-by: paolomainardi <8747+paolomainardi@users.noreply.github.com>
5c581ed to
19a0767
Compare
There was a problem hiding this comment.
Pull Request Overview
This PR enhances the check-updates functionality by adding Homebrew package update detection to the existing Sparkdock update checking. The menu bar app now monitors both Sparkdock updates and outdated Homebrew packages, providing a unified view of system update status.
Key changes:
- Added Homebrew package monitoring with dynamic brew path detection
- Enhanced UI to display combined update status for both Sparkdock and Homebrew
- Added new menu item for upgrading Homebrew packages when outdated packages are detected
Reviewed Changes
Copilot reviewed 2 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/menubar-app/Sources/SparkdockManager/main.swift | Added Homebrew update checking, new menu item for brew upgrades, and enhanced UI to show combined update status |
| src/menubar-app/Tests/SparkdockManagerTests/SparkdockManagerTests.swift | Added test coverage for new menu item tags and Homebrew command validation |
| private func runBrewOutdatedCheck() async -> Int { | ||
| // Use 'which' to find the brew binary dynamically | ||
| guard let brewPath = await findBrewPath() else { | ||
| AppConstants.logger.warning("Homebrew not found in PATH") | ||
| return 0 | ||
| } | ||
|
|
||
| let process = Process() | ||
| process.executableURL = URL(fileURLWithPath: "/bin/sh") | ||
| process.arguments = ["-c", "\(brewPath) outdated --quiet | wc -l"] |
There was a problem hiding this comment.
The findBrewPath() function is called on every update check, which involves spawning a process and executing which brew. Consider caching the brew path after the first successful lookup to avoid repeated process execution overhead.
| executeTerminalCommand("brew upgrade") | ||
| } | ||
|
|
||
|
|
There was a problem hiding this comment.
The brew upgrade command is executed without validating the brew path, potentially allowing execution of any brew binary found in PATH. Consider using the cached brew path from findBrewPath() to ensure you're executing the expected binary.
| executeTerminalCommand("brew upgrade") | |
| } | |
| guard let brewPath = findBrewPath() else { | |
| showErrorAlert("Brew Not Found", "Could not find the Homebrew binary. Please ensure Homebrew is installed.") | |
| return | |
| } | |
| executeTerminalCommand("\"\(brewPath)\" upgrade") | |
| } | |
| // Returns the path to the Homebrew binary, or nil if not found | |
| private func findBrewPath() -> String? { | |
| let possiblePaths = [ | |
| "/usr/local/bin/brew", | |
| "/opt/homebrew/bin/brew" | |
| ] | |
| for path in possiblePaths { | |
| if FileManager.default.isExecutableFile(atPath: path) { | |
| return path | |
| } | |
| } | |
| // Fallback: try to locate brew in PATH | |
| let whichProcess = Process() | |
| let pipe = Pipe() | |
| whichProcess.executableURL = URL(fileURLWithPath: "/usr/bin/which") | |
| whichProcess.arguments = ["brew"] | |
| whichProcess.standardOutput = pipe | |
| do { | |
| try whichProcess.run() | |
| whichProcess.waitUntilExit() | |
| let data = pipe.fileHandleForReading.readDataToEndOfFile() | |
| if let output = String(data: data, encoding: .utf8)? | |
| .trimmingCharacters(in: .whitespacesAndNewlines), | |
| !output.isEmpty, | |
| FileManager.default.isExecutableFile(atPath: output) { | |
| return output | |
| } | |
| } catch { | |
| // Ignore errors, return nil below | |
| } | |
| return nil | |
| } |
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
PR Code Suggestions ✨Explore these optional code suggestions:
|
PR Type
Enhancement
Description
Add Homebrew package update checking to menu bar app
Implement dynamic brew binary path detection using 'which'
Add upgrade brew packages menu item with count display
Improve update status display with combined indicators
Changes walkthrough 📝
main.swift
Add Homebrew integration with update checkingsrc/menubar-app/Sources/SparkdockManager/main.swift
upgradeBrewmenu item tag and corresponding UI elementsfindBrewPath()to dynamically locate brew binaryrunBrewOutdatedCheck()to count outdated packagesupgradeBrew()action to execute brew upgrade commandSparkdockManagerTests.swift
Add tests for Homebrew integration featuressrc/menubar-app/Tests/SparkdockManagerTests/SparkdockManagerTests.swift
upgradeBrewTagmenu item uniqueness/usr/bin/whichcommand existencesparkdock.macos
Improve update availability logging outputbin/sparkdock.macos