#!/bin/sh
set -eu

# Whalebird is an Electron app staged by apply_extra to /app/extra/whalebird.
# Run it through zypak-wrapper (from org.electronjs.Electron2.BaseApp): zypak
# redirects Chromium's SUID sandbox onto the Flatpak sandbox, so the app keeps
# an internal sandbox rather than running with --no-sandbox.
# --ozone-platform-hint=auto lets Chromium use Wayland when available and fall
# back to X11. Flatpak redirects $HOME, so the accounts, settings and the local
# timeline database under ~/.config/Whalebird stay inside the sandbox.
#
# Defensively clear ELECTRON_RUN_AS_NODE: if it leaks in from the launching
# environment (e.g. a terminal inside VS Code/Electron), the binary would start
# as plain Node instead of the GUI app.
unset ELECTRON_RUN_AS_NODE

# apply_extra resolves the launcher's upstream name from the .deb's own .desktop
# file and records it next to the app tree, so an upstream rename cannot break an
# automated pin refresh.
launcher="$(cat /app/extra/launcher 2>/dev/null || true)"
[ -n "$launcher" ] || launcher=whalebird
exec zypak-wrapper "/app/extra/whalebird/$launcher" --ozone-platform-hint=auto "$@"
