#!/bin/bash

## Copyright (C) 2012 - 2025 ENCRYPTED SUPPORT LLC <adrelanos@whonix.org>
## See the file COPYING for copying conditions.

if [ "$sandbox_app_launcher_debug" = "true" ]; then
  set -x
fi

## TODO: update
xsession_d_file_list_executable=(
  "/etc/X11/Xsession.d/20torbrowser"
  "/etc/X11/Xsession.d/20uwt"
  "/etc/X11/Xsession.d/20whonix"
  "/etc/X11/Xsession.d/20whonix-welcome-page"
  "/etc/X11/Xsession.d/20software_rendering_in_vms"
  "/etc/X11/Xsession.d/40open_link_confirmation"
  "/etc/X11/Xsession.d/40open_link_confirmation_kde"
  "/etc/X11/Xsession.d/50anon-apps-config"
  "/etc/X11/Xsession.d/50default_editor"
  "/etc/X11/Xsession.d/50tb_default_browser"
  "/etc/X11/Xsession.d/50torbrowser_default_browser"
  "/etc/X11/Xsession.d/50security-misc"
)

xsession_d_file_list_existing=(
  "/etc/X11/Xsession.d/20qt-gnome-desktop-session-id"
  "/etc/X11/Xsession.d/20qt-x11-no-mitshm"
  "/etc/X11/Xsession.d/25xdg-qubes-settings"
)

for file_name in "${xsession_d_file_list_executable[@]}" ; do
  if [ -x "$file_name" ]; then
    source "$file_name"
  fi
done

for file_name in "${xsession_d_file_list_existing[@]}" ; do
  if [ -e "$file_name" ]; then
    source "$file_name"
  fi
done

dbus-launch >/dev/null

"${app_path}" "${@}"
