#! /bin/bash

if [ $AUTOSTART = false ]; then
	Xdialog --title "$LOC_HEADER" --screen-center --buttons-style text --no-cancel --ok-label "$LOC_START" --logbox /tmp/pstopwatch-clock $WINDOW_SIZE
	if [ $? != 0 ]; then
		rm /tmp/pstopwatch*
		echo running > /tmp/pstopwatch-status
		exit
	fi
else
	export AUTOSTART=false #only skip start-window first run
fi
if [ "$CLOCK" = "true" ]; then
	"$APPDIR"/pstopwatch_clock &
else
	"$APPDIR"/pstopwatch_counter &
fi
Xdialog --title "$LOC_HEADER" --screen-center $BUTTON_STOP --logbox /tmp/pstopwatch-clock $WINDOW_SIZE
if [ "$BUTTON_STOP" = '--no-buttons' ]; then #no stop button --> kill
	killall -q pstopwatch_counter
	killall -q pstopwatch_clock
	killall -q $COMMAND_ALARM
	exit
fi
echo stop > /tmp/pstopwatch-status
tail /tmp/pstopwatch-clock | grep -v "^$" > /tmp/pstopwatch-clock
"$APPDIR"/pstopwatch_mainloop