#!/bin/bash

# HINT: Run "sh ./makagiga.sh" if your file system does not allow executable (+x) scripts

# HACK: jayatanaag.jar causes MAJOR crashes and other CRITICAL issues.
if [[ "${JAVA_TOOL_OPTIONS}" =~ "javaagent" ]]; then
	unset JAVA_TOOL_OPTIONS
fi

# HINT: Set "JAVA_HOME" to use custom Java version
#JAVA_HOME=~/apps/jdk-VERSION

launcher=java

if [[ -n "$APPDIR" && -n "$APPIMAGE" && -d "$APPDIR" ]]; then
	cd "$APPDIR"
fi

resolved_path=$(realpath "$0")
dir=$(dirname "$resolved_path")

if [ -x "${dir}/java-linux-x64/bin/java" ]; then
	launcher="${dir}/java-linux-x64/bin/java"
elif [[ -n "$JAVA_HOME" && -x "${JAVA_HOME}/bin/java" ]]; then
	launcher="${JAVA_HOME}/bin/java"
fi

"$launcher" "-Djava.properties.date=#" -Xms32m -Xmx256m -jar "${dir}/makagiga.jar" $portable_arg "${@}"
