#!/usr/bin/env bash

# Define the base command with common options
command="pkexec btrfs-assistant --xdg-runtime=\"${XDG_RUNTIME_DIR}\""

# Add xdg-desktop option if XDG_CURRENT_DESKTOP is set
if [[ -n ${XDG_CURRENT_DESKTOP} ]]; then
    command="${command} --xdg-desktop=\"${XDG_CURRENT_DESKTOP}\""
fi

# Add platform and display options when using Wayland
if [[ -n "${WAYLAND_DISPLAY}" ]]; then
    command="${command} --display=\"${WAYLAND_DISPLAY}\""
    if [[ -n "${QT_QPA_PLATFORM}" ]]; then
        command="${command} --platform=\"${QT_QPA_PLATFORM}\""
    fi
fi

# Add platformtheme option if QT_QPA_PLATFORMTHEME is set
if [[ -n ${QT_QPA_PLATFORMTHEME} ]]; then
    command="${command} --platformtheme=\"${QT_QPA_PLATFORMTHEME}\""
fi

# Add style-override option if QT_STYLE_OVERRIDE is set
if [[ -n ${QT_STYLE_OVERRIDE} ]]; then
    command="${command} --style-override=\"${QT_STYLE_OVERRIDE}\""
fi

# Execute the constructed command
eval "$command"
