#!/bin/bash
# refokal launcher — sets up the bundled Qt runtime environment.
#
# The real binary lives at /opt/refokal/bin/refokal.real with RPATH
# $ORIGIN/../lib so it finds the bundled libs in /opt/refokal/lib. We still
# export LD_LIBRARY_PATH and QT_PLUGIN_PATH so dynamically-loaded components
# (Qt image-format plugins) resolve correctly.
# QML_IMPORT_PATH points the QML engine at the bundled Qt modules under
# /opt/refokal/qml — without it, `import QtQuick.Controls` resolves against
# Qt's compiled-in install path (/opt/Qt/...) which doesn't exist on the
# user's machine, and the UI fails to load ("module is not installed").
cd /opt/refokal/bin
exec env \
    LD_LIBRARY_PATH="/opt/refokal/lib${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}" \
    QT_PLUGIN_PATH="/opt/refokal/plugins" \
    QT_QPA_PLATFORM_PLUGIN_PATH="/opt/refokal/plugins/platforms" \
    QML_IMPORT_PATH="/opt/refokal/qml" \
    QML2_IMPORT_PATH="/opt/refokal/qml" \
    LIBHEIF_PLUGIN_PATH="/opt/refokal/lib/heif-plugins" \
    QT_QUICK_BACKEND=software \
    ./refokal.real "$@"
