Skip to content

Add http-proxy update management to menubar app#180

Merged
paolomainardi merged 5 commits into
masterfrom
copilot/fix-179
Sep 9, 2025
Merged

Add http-proxy update management to menubar app#180
paolomainardi merged 5 commits into
masterfrom
copilot/fix-179

Conversation

Copilot AI commented Sep 8, 2025

Copy link
Copy Markdown
Contributor

User description

This PR implements comprehensive http-proxy update management in the Sparkdock menubar app, allowing users to receive notifications and trigger updates for the http-proxy system directly from the menu bar.

Current Status

  • Implement http-proxy update checking command
  • Add menubar app integration for http-proxy updates
  • Add comprehensive testing
  • Refactor duplicated code: Combined runSparkdockCheck and runHttpProxyCheck functions

Problem

Users had no way to check for or manage http-proxy updates through the menubar app. While sjust http-proxy-install-update existed for updating, there was no mechanism to:

  • Check if http-proxy updates were available
  • Display update status in the menubar
  • Trigger updates through the UI

Solution

Added complete http-proxy update support following the exact same patterns as existing Sparkdock and Brew update management:

Command Line Interface

  • New sparkdock http-proxy-check-updates command
  • Checks /opt/sparkdock/http-proxy git repository for updates
  • Returns exit code 0 when updates available, 1 when up to date

Menubar App Integration

  • Http-proxy status line: Shows current update status with color coding
  • Upgrade button: Appears when updates are available, runs sjust http-proxy-install-update
  • Automatic checking: Integrated into network monitoring and system wake events
  • Manual triggers: Click status line to manually check for updates

Code Quality Improvements

  • Code deduplication: Combined runSparkdockCheck() and runHttpProxyCheck() functions into a generic runSparkdockCommand(_ command: String) function
  • Maintainability: Reduced code from 94 lines to 55 lines (-39 lines, 48 deletions, 9 additions)
  • Consistency: Both functions now use identical logic with only the command parameter differing

Visual Changes

Sparkdock Menu Bar - Http-proxy Update Support

The menubar now displays:

  • Before: Sparkdock status + Brew status + upgrade buttons
  • After: Sparkdock status + Brew status + Http-proxy status + upgrade buttons including Upgrade Http-proxy

Status colors follow existing conventions:

  • 🟡 Yellow: Checking for updates...
  • 🟠 Orange: Updates available
  • 🟢 Green: Up to date

Implementation Details

Shell Script (bin/sparkdock.macos)

# New function to check http-proxy updates
check_http_proxy_updates() {
    HTTP_PROXY_DIR="/opt/sparkdock/http-proxy"
    
    if [ ! -d "${HTTP_PROXY_DIR}" ]; then
        return 1
    fi
    
    cd "${HTTP_PROXY_DIR}"
    git fetch origin main -q
    LOCAL=$(git rev-parse HEAD)
    REMOTE=$(git rev-parse origin/main)
    
    if [ "$LOCAL" != "$REMOTE" ]; then
        echo "Http-proxy updates available:"
        git --no-pager log --oneline HEAD..origin/main
        return 0
    fi
    return 1
}

# New command handler
if [ "$1" = "http-proxy-check-updates" ] ; then
    if check_http_proxy_updates; then
        notify "Http-proxy updates are available. Run 'sjust http-proxy-install-update' to update."
        exit 0  # Updates available
    fi
    exit 1  # No updates available
fi

Swift App Integration (Refactored)

  • Added hasHttpProxyUpdates state variable
  • Added httpProxyStatusMenuItem and upgradeHttpProxyMenuItem
  • Refactored: Combined runSparkdockCheck() and runHttpProxyCheck() into generic runSparkdockCommand() function
  • Added upgradeHttpProxy() action that executes sjust http-proxy-install-update
  • Integrated into all update flows: checkForUpdates(), network monitoring, system wake

Pattern Consistency

The implementation follows the exact same patterns as existing Sparkdock and Brew updates:

  • Same async timeout handling with structured concurrency
  • Same UI update patterns and color schemes
  • Same menu item visibility logic
  • Same command execution patterns
  • Same integration points (38 integration points added)
  • Improved: Eliminated code duplication between check functions

Testing

  • Added unit tests for new menu item tags
  • Added tests for http-proxy upgrade command
  • Comprehensive integration testing verified all functionality
  • No existing functionality was broken or modified

Usage

  • Command line: sparkdock http-proxy-check-updates
  • Menubar: Http-proxy status line shows update status and is clickable
  • Automatic: Updates checked on network changes and system wake
  • Manual upgrade: Click "Upgrade Http-proxy" button when updates are available

The http-proxy repository at /opt/sparkdock/http-proxy is checked using the same git-based approach as the main Sparkdock repository, ensuring consistency and reliability.

Fixes #179.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.


PR Type

Enhancement


Description

  • Add http-proxy update management to menubar app

  • Implement http-proxy update checking command in sparkdock.macos

  • Refactor duplicated code by combining check functions

  • Add comprehensive testing for http-proxy functionality


Changes walkthrough 📝

Relevant files
Enhancement
main.swift
Add http-proxy update management to menubar                           

src/menubar-app/Sources/SparkdockManager/main.swift

  • Add http-proxy status line and upgrade button to menu
  • Implement runHttpProxyCheck() function for update checking
  • Refactor runSparkdockCheck() and runHttpProxyCheck() into generic
    runSparkdockCommand()
  • Update UI logic to handle http-proxy updates alongside existing
    Sparkdock and Brew updates
  • +70/-7   
    sparkdock.macos
    Add http-proxy update checking command                                     

    bin/sparkdock.macos

  • Add check_http_proxy_updates() function to check git repository
    updates
  • Add http-proxy-check-updates command line option
  • Check /opt/sparkdock/http-proxy directory for git updates
  • +36/-0   
    Tests
    SparkdockManagerTests.swift
    Add tests for http-proxy functionality                                     

    src/menubar-app/Tests/SparkdockManagerTests/SparkdockManagerTests.swift

  • Add test for new upgradeHttpProxy menu item tag uniqueness
  • Add test for http-proxy upgrade command validation
  • Add test for http-proxy check updates command validation
  • +14/-0   

    Need help?
  • Type /help how to ... in the comments thread for any questions about PR-Agent usage.
  • Check out the documentation for more information.
  • …acos
    
    Co-authored-by: paolomainardi <8747+paolomainardi@users.noreply.github.com>
    Comment thread src/menubar-app/Sources/SparkdockManager/main.swift Outdated
    …ration
    
    Co-authored-by: paolomainardi <8747+paolomainardi@users.noreply.github.com>
    Copilot AI changed the title [WIP] Menubar: http-proxy update must be managed Add http-proxy update management to menubar app Sep 8, 2025
    Copilot AI requested a review from paolomainardi September 8, 2025 15:20
    …plication
    
    Co-authored-by: paolomainardi <8747+paolomainardi@users.noreply.github.com>
    @paolomainardi paolomainardi marked this pull request as ready for review September 8, 2025 15:35
    Copilot AI review requested due to automatic review settings September 8, 2025 15:35

    Copilot AI left a comment

    Copy link
    Copy Markdown
    Contributor

    Choose a reason for hiding this comment

    The reason will be displayed to describe this comment to others. Learn more.

    Pull Request Overview

    This PR adds comprehensive http-proxy update management to the Sparkdock menubar app, providing users with notifications and the ability to trigger updates for the http-proxy system directly from the menu bar interface.

    • Implements http-proxy update checking via a new sparkdock http-proxy-check-updates command
    • Adds menubar UI integration with status display and upgrade button functionality
    • Refactors duplicate code by combining check functions into a generic command runner

    Reviewed Changes

    Copilot reviewed 2 out of 3 changed files in this pull request and generated no comments.

    File Description
    src/menubar-app/Sources/SparkdockManager/main.swift Core implementation with UI components, refactored command runner, and http-proxy integration
    src/menubar-app/Tests/SparkdockManagerTests/SparkdockManagerTests.swift Unit tests for new menu item tags and http-proxy commands

    @paolomainardi paolomainardi left a comment

    Copy link
    Copy Markdown
    Member

    Choose a reason for hiding this comment

    The reason will be displayed to describe this comment to others. Learn more.

    LGTM

    @sparkfabrik-ai-bot

    Copy link
    Copy Markdown

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

    🎫 Ticket compliance analysis ✅

    179 - PR Code Verified

    Compliant requirements:

    • Add command "sparkdock http-proxy-check-updates" similar to existing sparkdock command
    • Display message similar to Sparkdock and Brew update notifications
    • Add "Upgrade http-proxy" button that runs the sjust command when clicked
    • Implement mechanism to trigger sjust http-proxy-install-update when git repository has updates

    Requires further human verification:

    • Visual appearance and user experience of the menubar notifications
    • Integration testing with actual git repository updates
    • Terminal command execution behavior in real environment

    ⏱️ Estimated effort to review: 3 🔵🔵🔵⚪⚪
    🧪 PR contains tests
    🔒 No security concerns identified
    ⚡ Recommended focus areas for review

    Error Handling

    The check_http_proxy_updates function lacks proper error handling for git operations and doesn't validate if the directory is actually a valid git repository before performing git operations.

    check_http_proxy_updates() {
        HTTP_PROXY_DIR="/opt/sparkdock/http-proxy"
    
        # Check if http-proxy directory exists
        if [ ! -d "${HTTP_PROXY_DIR}" ]; then
            return 1
        fi
    
        cd "${HTTP_PROXY_DIR}"
    
        # Ensure it's a git repository
        if [ ! -d ".git" ]; then
            return 1
        fi
    
        git fetch origin main -q
        LOCAL=$(git rev-parse HEAD)
        REMOTE=$(git rev-parse origin/main)
    
        if [ "$LOCAL" != "$REMOTE" ]; then
            echo "Http-proxy updates available:"
            git --no-pager log --oneline HEAD..origin/main
            return 0
        fi
        return 1
    }
    Code Duplication

    While the PR mentions refactoring duplicated code, the runSparkdockCommand function is generic but the logging messages still contain hardcoded references that may not be appropriate for all commands.

            AppConstants.logger.error("Sparkdock command '\(command)' process timed out after \(AppConstants.processTimeout) seconds")
            return false
        }
    
        return terminationStatus == 0
    } catch {
        AppConstants.logger.error("Failed to run sparkdock command '\(command)': \(error.localizedDescription)")
        return false

    @sparkfabrik-ai-bot

    Copy link
    Copy Markdown

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Impact
    General
    Preserve original working directory

    The function changes directory without preserving the original working directory,
    which could affect subsequent operations. Store and restore the original directory
    to maintain proper state.

    bin/sparkdock.macos [55-80]

     check_http_proxy_updates() {
         HTTP_PROXY_DIR="/opt/sparkdock/http-proxy"
    +    ORIGINAL_DIR=$(pwd)
         
         # Check if http-proxy directory exists
         if [ ! -d "${HTTP_PROXY_DIR}" ]; then
             return 1
         fi
         
         cd "${HTTP_PROXY_DIR}"
         
         # Ensure it's a git repository
         if [ ! -d ".git" ]; then
    +        cd "${ORIGINAL_DIR}"
             return 1
         fi
         
         git fetch origin main -q
         LOCAL=$(git rev-parse HEAD)
         REMOTE=$(git rev-parse origin/main)
         
    +    cd "${ORIGINAL_DIR}"
    +    
         if [ "$LOCAL" != "$REMOTE" ]; then
             echo "Http-proxy updates available:"
    +        cd "${HTTP_PROXY_DIR}"
             git --no-pager log --oneline HEAD..origin/main
    +        cd "${ORIGINAL_DIR}"
             return 0
         fi
         return 1
     }
    Suggestion importance[1-10]: 7

    __

    Why: This is a good practice suggestion that prevents potential side effects from directory changes. The implementation correctly stores and restores the working directory, improving code robustness.

    Medium
    Add command validation before execution

    The hardcoded command "sjust http-proxy-install-update" may fail if the sjust
    command is not available or not in PATH. Consider adding error handling or
    validation to check if the command exists before execution.

    src/menubar-app/Sources/SparkdockManager/main.swift [640-643]

     @objc private func upgradeHttpProxy() {
         guard hasHttpProxyUpdates else { return }
    -    executeTerminalCommand("sjust http-proxy-install-update")
    +    // Validate command exists before execution
    +    let command = "which sjust > /dev/null 2>&1 && sjust http-proxy-install-update || echo 'Error: sjust command not found'"
    +    executeTerminalCommand(command)
     }
    Suggestion importance[1-10]: 6

    __

    Why: The suggestion addresses a valid concern about hardcoded command execution, but the proposed solution using shell command chaining is overly complex and may not integrate well with the existing executeTerminalCommand method.

    Low
    Add git fetch error handling

    The git fetch command may fail due to network issues or authentication problems, but
    there's no error handling. Add error checking to handle fetch failures gracefully.

    bin/sparkdock.macos [70-72]

    -git fetch origin main -q
    +if ! git fetch origin main -q 2>/dev/null; then
    +    cd "${ORIGINAL_DIR}"
    +    return 1
    +fi
     LOCAL=$(git rev-parse HEAD)
     REMOTE=$(git rev-parse origin/main)
    Suggestion importance[1-10]: 6

    __

    Why: Adding error handling for git fetch is a reasonable improvement, but the suggestion doesn't account for the directory restoration logic from suggestion 2, making the implementation incomplete in the current context.

    Low

    @paolomainardi paolomainardi merged commit 133e6a5 into master Sep 9, 2025
    5 checks passed
    Copilot AI added a commit that referenced this pull request Apr 20, 2026
    …proach
    
    Replaces the previous completion that leaked JUST_JUSTFILE into global env
    with a self-contained _sjust() function that scopes JUST_JUSTFILE to a
    subprocess, following the pattern from archlinux-ansible-provisioner PR #180.
    
    Key improvements:
    - JUST_JUSTFILE scoped to subshell (no env leaking)
    - Uses clap completion protocol directly
    - Filters out just's --* flags from completions
    - No dependency on source-ing just's completion function
    
    Agent-Logs-Url: https://github.com/sparkfabrik/sparkdock/sessions/8e3ff904-e27a-4f67-a1d1-d51fe1acec22
    
    Co-authored-by: Monska85 <62102073+Monska85@users.noreply.github.com>
    paolomainardi added a commit that referenced this pull request Apr 23, 2026
    Move the sjust zsh completion script from inline content (duplicated in Makefile and Ansible playbook) to a single source file at sjust/completions/_sjust, matching the pattern used in archlinux-ansible-provisioner PR #180. Both Makefile and Ansible now copy this file instead of generating it.
    
    Refs: #423
    Assisted-by: opencode/github-copilot/claude-opus-4.6
    paolomainardi added a commit that referenced this pull request Apr 23, 2026
    * fix(sjust): sjust autocomplete working again with just 1.50+
    
    * refactor(sjust): use self-contained clap completion like archlinux approach
    
    Replaces the previous completion that leaked JUST_JUSTFILE into global env
    with a self-contained _sjust() function that scopes JUST_JUSTFILE to a
    subprocess, following the pattern from archlinux-ansible-provisioner PR #180.
    
    Key improvements:
    - JUST_JUSTFILE scoped to subshell (no env leaking)
    - Uses clap completion protocol directly
    - Filters out just's --* flags from completions
    - No dependency on source-ing just's completion function
    
    Agent-Logs-Url: https://github.com/sparkfabrik/sparkdock/sessions/8e3ff904-e27a-4f67-a1d1-d51fe1acec22
    
    Co-authored-by: Monska85 <62102073+Monska85@users.noreply.github.com>
    
    * refactor(sjust): extract completion to standalone file
    
    Move the sjust zsh completion script from inline content (duplicated in Makefile and Ansible playbook) to a single source file at sjust/completions/_sjust, matching the pattern used in archlinux-ansible-provisioner PR #180. Both Makefile and Ansible now copy this file instead of generating it.
    
    Refs: #423
    Assisted-by: opencode/github-copilot/claude-opus-4.6
    
    ---------
    
    Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
    Co-authored-by: Monska85 <62102073+Monska85@users.noreply.github.com>
    Co-authored-by: Paolo Mainardi <paolomainardi@gmail.com>
    Co-authored-by: Paolo Mainardi <paolo.mainardi@sparkfabrik.com>
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Projects

    None yet

    Development

    Successfully merging this pull request may close these issues.

    Menubar: http-proxy update must be managed

    3 participants