#!/bin/bash

# Wrapper to launch walker with elephant provider, or fallback to rofi if walker is missing.

if command -v walker >/dev/null 2>&1; then
    # Ensure elephant is running before launching walker
    if ! pgrep -x elephant > /dev/null; then
        setsid uwsm-app -- elephant &
    fi

    # Ensure walker service is running
    if ! pgrep -f "walker --gapplication-service" > /dev/null; then
        setsid uwsm-app -- walker --gapplication-service &
    fi

    exec uwsm-app -- walker --width 644 --maxheight 300 --minheight 300 "$@"
elif command -v rofi >/dev/null 2>&1; then
    # Convert walker arguments to rofi arguments if possible
    # This is a very basic mapping for --dmenu
    if [[ "$*" == *"--dmenu"* ]]; then
        exec rofi -dmenu "$@"
    else
        exec rofi -show drun
    fi
else
    notify-send "Error" "Neither walker nor rofi found." -u critical
    exit 1
fi
