#
# ~/.bash_profile
#

[[ -f ~/.bashrc ]] && . ~/.bashrc

# First boot volume configuration - run before startup sound
if [[ -f ~/.firstboot ]]; then
    # Initialize speech system which will start pipewire
    spd-say "Configuring volume"
    
    # Wait for pipewire to become available
    wait=0
    volume=50
    while [[ $wait -lt 30 ]]; do
        if pgrep pipewire &> /dev/null ; then
            wait=30 # We don't want to continue the loop
        else
            sleep 1
            continue
        fi
        while [[ $volume -le 130 ]]; do
            clear
            spd-say "If this is loud enough, press enter."
            if read -t4 ; then
                break
            else
                ((volume+=5))
            fi
            pactl set-sink-volume @DEFAULT_SINK@ "${volume}%"
        done
        ((wait++))
    done
    # Remove marker so this only runs once
    rm -f ~/.firstboot
fi

if ! [[ -e "/tmp/startup_complete" ]]; then
    #FEXLoader ~/.fex-emu/RootFS/ArchLinux/usr/bin/speech-dispatcher
    touch "/tmp/startup_complete"
    play -qV0 /usr/share/sounds/stormux/start.opus
fi
if [[ "$(tty)" == "/dev/tty1" ]]; then
    /usr/local/bin/diagnostics.sh
    exec /usr/local/bin/game_launcher.py
    exit
fi
