#!/usr/bin/env bash
#
# MFA launcher - installed as  <deployment>/MFA/bin/MFA  by build-*.sh.
#
# Layout it expects (siblings of this script's parent dir):
#   MFA/bin/MFA        this file
#   MFA/runtime/       the jlink custom runtime (java + JavaFX)
#   MFA/app/           MarkingSheetGUI.jar, markingSpreadsheet.jar
#   MFA/lib/           third-party jars (POI, JAXB, mail, spellcheck, ...)
#
set -euo pipefail

APP_HOME="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"

# The app reads/writes MFAProperties.txt in the current working directory (its
# "Working Folder"). Run from APP_HOME so settings stay beside the app,
# regardless of where the launcher was invoked from (Finder double-click gives
# cwd=/).
cd "$APP_HOME"

exec "$APP_HOME/runtime/bin/java" \
	-Dfile.encoding=UTF-8 \
	--module-path "$APP_HOME/app:$APP_HOME/lib" \
	--module MarkingSheetGUI/markingGUI.fx.MarkingFxApp \
	"$@"
