#!/bin/bash

# Launches IrScrutinizer on MacOS as an app.

HERE=$(cd "$(dirname "$0")"; pwd)

RES="${HERE}/../Resources/Java/repo"

# Set to the preferred Java VM, >= 1.7 required.
JAVA=$(which java)

# Cannot just give "$@" to the program, since double clicking stuffs junk in $@. Grrr...
if [ -f "$JAVA" ] && [ -x "$JAVA" ] ; then
    cd ${RES}
    exec "${JAVA}" -Xdock:icon="${RES}/IrScrutinizer.icns" -Xdock:name="IrScrutinizer" \
       -jar "${RES}/IrScrutinizer-jar-with-dependencies.jar" > "${HOME}/.IrScrutinizer.err" 2>&1
else
    # display error message with applescript
    osascript -e "tell application \"System Events\" to display dialog \"Error launching IrScrutinizer.\n\nJava JDK (not just JRE) is needed.\nVisit http://java.com for more information...\" with title \"IrScrutinizer\" buttons {\" OK \"} default button 1"
    exit 1
fi
