#!/usr/bin/env bash
#
# Ormi desktop launcher — env-scrubbing wrapper.
#
# Why this exists:
#   The `ormi-desktop` binary is linked against system glibc. If it inherits
#   a PATH / LD_* / GTK_* / GSETTINGS_* environment from a Snap-packaged
#   parent process (e.g. a developer's VSCode-Snap terminal, or a user's
#   Snap-packaged browser calling xdg-open to dispatch an `ormi://` deep
#   link), the Snap's private libc-pthread is loaded first and the binary
#   aborts with "undefined symbol: __libc_pthread_init (GLIBC_PRIVATE)".
#
#   We run `env -i` to completely reset the child environment, then re-
#   hydrate only the variables the Tauri app needs for a desktop session.
#
# Installed at /usr/bin/ormi-launcher; the .desktop file points its Exec=
# line here instead of at the raw binary so both normal GNOME launches AND
# xdg-open deep-link dispatches always get a clean env.

exec env -i \
  HOME="$HOME" \
  USER="$USER" \
  DISPLAY="${DISPLAY:-:0}" \
  XAUTHORITY="${XAUTHORITY:-$HOME/.Xauthority}" \
  WAYLAND_DISPLAY="${WAYLAND_DISPLAY:-}" \
  LANG="${LANG:-en_US.UTF-8}" \
  PATH="/usr/local/bin:/usr/bin:/bin" \
  XDG_RUNTIME_DIR="${XDG_RUNTIME_DIR:-/run/user/$(id -u)}" \
  XDG_DATA_DIRS="/usr/local/share:/usr/share" \
  XDG_CONFIG_DIRS="/etc/xdg" \
  XDG_SESSION_TYPE="${XDG_SESSION_TYPE:-}" \
  DBUS_SESSION_BUS_ADDRESS="${DBUS_SESSION_BUS_ADDRESS:-unix:path=/run/user/$(id -u)/bus}" \
  /usr/bin/ormi-desktop "$@"
