#!/usr/bin/env bash

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

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

        if [ -z $ffrg ]; then
            exec vivaldi
            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 vivaldi-stable)

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

            exec hyprctl dispatch focuswindow "class:vivaldi-stable"
            exit
        fi
    fi
else
    exec vivaldi
fi