#!/usr/bin/env bash
# macOS wrapper for pikerd to handle missing XDG_RUNTIME_DIR

# Set up runtime directory for macOS if not already set
if [ -z "$XDG_RUNTIME_DIR" ]; then
    # Use macOS standard temp directory with user-specific subdirectory
    export XDG_RUNTIME_DIR="/tmp/piker-runtime-$(id -u)"

    # Create the directory if it doesn't exist
    if [ ! -d "$XDG_RUNTIME_DIR" ]; then
        mkdir -p "$XDG_RUNTIME_DIR"
        # Set proper permissions (only user can access)
        chmod 700 "$XDG_RUNTIME_DIR"
    fi

    echo "Set XDG_RUNTIME_DIR to: $XDG_RUNTIME_DIR"
fi

# Run pikerd with all passed arguments
exec uv run pikerd "$@"