#!/bin/sh
set -eu

# AB Download Manager is a jpackage app-image (Compose Desktop + a bundled JRE),
# staged by apply_extra to /app/extra/ABDownloadManager. The native launcher
# locates its JRE and jars relative to itself, and Skia/AWT pull X11, OpenGL,
# fontconfig and libstdc++ from the runtime. The app keeps its config and
# download database in ~/.abdm (from the user.home JVM property), granted in
# finish-args.

# The bundled tray backend (libLinuxTray.so) claims the StatusNotifier bus name
# "org.kde.StatusNotifierItem-<getpid()>-1" and gives up if that name is taken.
# Inside the sandbox the app is always PID 2 in its own PID namespace, so every
# Flatpak app with a tray races for the same name and whichever starts first
# wins. Report a fixed, distinctive PID instead, and grant exactly that one bus
# name in finish-args.
export ABDM_FAKE_PID="${ABDM_FAKE_PID:-424242}"
export LD_PRELOAD="/app/lib/abdm/libfakepid.so${LD_PRELOAD:+:$LD_PRELOAD}"

exec /app/extra/ABDownloadManager/bin/ABDownloadManager "$@"
