#!/bin/bash

############################################################
## Auto restart discord when it silently decides to crash ##
############################################################

# toggle like behaviour
if [ -e /tmp/instantos/discord ]; then
    echo "discord restart disabled"
    rm /tmp/instantos/discord
    exit
else
    echo "discord restart enabled"
    mkdir /tmp/instantos
    touch /tmp/instantos/discord
fi

while :; do
    if ! [ -e /tmp/instantos/discord ]; then
        exit
    fi

    if command -v discord; then
        if ! pgrep discord; then
            discord
        fi
    elif command -v Discord; then
        if ! pgrep Discord; then
            Discord
        fi
    fi

    sleep 10
done
