#!/bin/sh

export DISPLAY=:1
DIALOG_TITLE="Restart TV"

# check if dialog window is already shown
# DOES NOT WORK - ACPI won't call this script again if previous instance
# is still running; ACPI events are queueing...
/usr/bin/xwininfo -name "$DIALOG_TITLE" 2> /tmp/xwininfo.log

if [[ $? = 0 ]]; then
	# dialog window is already shown, so kill it and exit
	wmctrl -c "$DIALOG_TITLE"
	exit 1
fi

echo $? > /tmp/p.ret

/usr/bin/zenity --question --text="Really restart TV applications?"
if [[ $? = 0 ]]; then
	kill `cat /var/local/run/htpc/wm.pid`
fi
