#!/bin/sh
set -eu

# MotrixNext is a Tauri v2 (WebKitGTK) app staged by apply_extra to
# /app/extra/motrix-next. The GUI binary links only against libraries in
# org.gnome.Platform (webkit2gtk-4.1, gtk-3, libsoup-3, cairo, dbus) and dlopens
# libayatana-appindicator3 for its tray icon; that stack is built by the manifest
# into /app/lib, already on the runtime's search path. Its engine sidecar sits
# next to it in bin/, and Tauri resolves the resource tree it reads (aria2.conf,
# the peer blocklist, the GeoIP database, the ED2K bootstrap caches) as
# <exe_dir>/../lib/MotrixNext, which apply_extra staged as a sibling.
#
# Flatpak redirects the XDG base dirs, so the task database, the settings and the
# engine's session state stay inside the sandbox.

# No LD_PRELOAD getpid shim here, unlike io.enpass.Enpass and
# com.abdownloadmanager.AbDownloadManager. Those pin the reported PID so their
# tray backend stops competing for the one org.kde.StatusNotifierItem-2-1 name
# every sandboxed app would otherwise ask for; this app's tray registers under
# its unique D-Bus connection name instead, so it never asks for that name and
# has nothing to contend over. The shim is also actively harmful here — faking
# getpid() for the whole process tree stops the app from coming up at all.

# apply_extra recorded the launcher name from the .deb's own desktop entry, so a
# rename upstream cannot leave this wrapper pointing at a binary that is gone.
launcher="$(cat /app/extra/motrix-next/.launcher)"

exec "/app/extra/motrix-next/bin/$launcher" "$@"
