#!/usr/bin/env bash
export MOZ_ENABLE_WAYLAND=1
echo $MOZ_ENABLE_WAYLAND

# Check to see if librewolf is running
if [ $(pgrep -c librewolf) -gt 0 ]; then
    echo "ff running"

    if [ "$XDG_SESSION_TYPE" = "x11" ]; then
        #X11
        ffrg=$(wmctrl -lx | rg librewolf | awk '{print $1}')
        # echo $emacsrg

        if [ -z $ffrg ]; then
            exec librewolf
            exit
        else
            exec wmctrl -ia $ffrg
            exit
        fi
    else
        if [ "$KDE_FULL_SESSION" = "true" ]; then
            echo "KDE"
            exec /home/chris/bin/ww -fa librewolf -c librewolf
            exit
        else
            # WAYLAND
            ffrg=$(hyprctl clients | rg ff)

            ffwin=$(echo $ffrg | sed 's/.*\: //')
            # echo $ffwin

            exec hyprctl dispatch focuswindow "class:lw"
            exit
        fi
    fi
else
    exec librewolf --name "lw"
fi