#!/bin/bash

#This app is part of the MX-Event-Sounds Package

#startup sound
#/usr/local/bin/startupsound &
#startupsound is now launched by a .desktop file in ~/.config/autostart/
#

###initialize app 

#create configuration file

if [ -a ~/.config/mx-sounds/mx-login-logout_sounds.conf ]; then
	echo "Configuration File Found!"
	else
	mkdir ~/.config/mx-sounds
	echo "#true is enabled, false is disabled">>~/.config/mx-sounds/mx-login-logout_sounds.conf
	echo "startup=false">>~/.config/mx-sounds/mx-login-logout_sounds.conf
	echo "logout=false">>~/.config/mx-sounds/mx-login-logout_sounds.conf
fi

#create initial startupsound startup desktop file in ~/.config/autostart if not present

if [ -a ~/.config/autostart/zstartup-sound.desktop ]; then
	echo "Startup file found!"
	else
	echo "[Desktop Entry]">>~/.config/autostart/zstartup-sound.desktop
	echo "Encoding=UTF-8">>~/.config/autostart/zstartup-sound.desktop
	echo "Version=0.9.4">>~/.config/autostart/zstartup-sound.desktop
	echo "Type=Application">>~/.config/autostart/zstartup-sound.desktop
	echo "Name=Startup-sound">>~/.config/autostart/zstartup-sound.desktop
	echo "Comment=startupsound at login">>~/.config/autostart/zstartup-sound.desktop
	echo "Exec=/usr/local/bin/startupsound">>~/.config/autostart/zstartup-sound.desktop
	echo "OnlyShowIn=XFCE;">>~/.config/autostart/zstartup-sound.desktop
	echo "StartupNotify=false">>~/.config/autostart/zstartup-sound.desktop
	echo "Terminal=false">>~/.config/autostart/zstartup-sound.desktop
	echo "Hidden=false">>~/.config/autostart/zstartup-sound.desktop
fi

#move startupsound.conf and logoutsound.conf if necessary
if [ ~/.config/startupsound.conf -nt ~/.config/mx-sounds/startupsound.conf ]; then
	cp ~/.config/startupsound.conf ~/.config/mx-sounds/startupsound.conf
	rm -f ~/.config/startupsound.conf
fi


##initialize app complete


# run the real xfce4-session exectuable
/usr/bin/xfce4-session

#logout sound
#move startupsound.conf and logoutsound.conf if necessary
if [ ~/.config/logoutsound.conf -nt ~/.config/mx-sounds/logoutsound.conf ]; then
	cp ~/.config/logoutsound.conf ~/.config/mx-sounds/logoutsound.conf
	rm -f ~/.config/logoutsound.conf
fi

/usr/local/bin/logoutsound
