#!/bin/sh
##################################################################################
#
# Twobob generalised starter for a fronter serviced application.
#
##################################################################################

cd /mnt/us/extensions/pente

#setup helpful variables...

		EXTENSION=/mnt/us/extensions

export	LD_LIBRARY_PATH=${EXTENSION}/pente/usr/lib:/usr/lib:/lib	

		PLATFORM="$(cat /sys/devices/platform/mxc_epdc_fb/graphics/fb0/modes)"

		SSSTATE=`lipc-get-prop com.lab126.powerd preventScreenSaver` 

# be certin we only have one instance

killall -9 pente &> /dev/null
usleep 500

#check for patch (Active)

if [ ! -d /tmp/twobob/xdg/awesome/ ]; then

		if [ -d /mnt/us/extensions/fronter/arch ]; then
	
			eips 3 37 "FRONTER dir not activated. Installing patch"
			sleep 2
			/mnt/us/extensions/fronter/arch/mount.sh &

		else

			eips 3 37 "FRONTER patch not installed." 	
			eips 3 38 "please install it, then retry"
		fi

	sleep 2
	exit;
fi

# Okay we seem likely to start the game at this point so...

# prevent SS from bothering us mid game.
lipc-set-prop com.lab126.powerd preventScreenSaver 1 


#uncomment for your ver.

if [ "$PLATFORM" = "${PLATFORM/758/}" ]; then
#Touch

# Insert your Touch Specific Start command here
# NOTE: In THIS instance pente is an application that will return to process without a backgrounding &
# we will run pente -nostealth to emulate a usual "blocking" apps activity for the same of this demo
# THEN we will add a & - because you WILL want one AFTER the app call (whether the app is blocking or not)
# always add one...

${EXTENSION}/pente/usr/bin/pente -nocolor -noiconic -geometry 800x600 -x11 -nostealth &  

fi

if [ "$PLATFORM" != "${PLATFORM/758/}" ]; then
#It's a PW

# Insert your Paperwhite Specific Start command here

${EXTENSION}/pente/usr/bin/pente -nocolor -noiconic -geometry 1024x758 -x11 -nostealth &

fi

# check if we should restore the setting once per minute

while :

do 	
	if [ -n "`pidof pente`" ]
    then
        sleep 60

    else
    	lipc-set-prop com.lab126.powerd preventScreenSaver "$SSSTATE"
		exit;
    fi

done

# all done.

