#! /bin/bash

OAUTH_RESPONSE_TYPE=code
OAUTH_CHALLENGE_METHOD=S256
OAUTH_CLIENT_ID="964c8802-eeaa-4e70-8783-6e65d019d7c6"
OAUTH_SCOPE="offline openid"
OAUTH_REDIRECT_URI="http://localhost:1420/auth/callback"
OAUTH_SERVER_BASE_URL="https://oauth2.playtron.red/oauth2"
OAUTH_SERVER_TOKEN_URL="https://oauth2.playtron.red/oauth2/token"
OAUTH_CLIENT_SERVER_PORT=1420
OAUTH_GRANT_TYPE="authorization_code"
PLAYTRON_GAMESCOPE_SESSION=1
CLIENTCMD="switcherooctl launch grid"
FACTORY_RESET_SENTINEL="/tmp/playtron-factory-reset-sentinel"

# remove the potentially large disk stress test file
# in case it was left behind by the stress test tool
rm -f /var/home/playtron/stress-test-disk.dat

if [[ ! -e "$HOME/.local/share/playtron/tools" ]] && command -v /usr/libexec/playtron/dev-session-trigger > /dev/null; then
	# only launch the dev session trigger script if the FTUE has not been completed
	/usr/libexec/playtron/dev-session-trigger &
fi

if lspci | grep -i vga | grep -i nvidia > /dev/null; then
	# Fixes lag in DirectX12 games when using an Nvidia GPU
	GAMESCOPE_DISABLE_EXPLICIT_SYNC=1
else
	GAMESCOPE_DISABLE_EXPLICIT_SYNC=0
fi

post_client_shutdown() {
	if [[ -e "$FACTORY_RESET_SENTINEL" ]]; then
		OPTION=$(cat $FACTORY_RESET_SENTINEL)
	        rm -f "$FACTORY_RESET_SENTINEL"
		pkexec playtron-factory-reset $OPTION
	fi
}
