#!/bin/sh
set -eu

# YoutubeDownloader is a self-contained .NET / Avalonia apphost staged by
# apply_extra to /app/extra/ytd. The launcher locates its bundled CoreCLR, the
# managed assemblies and SkiaSharp relative to itself; X11, libGL, fontconfig,
# libstdc++ and ICU come from org.freedesktop.Platform. The bundled ffmpeg sits
# in the same dir, which the app probes automatically.
#
# By default the app writes Settings.dat next to its own binary — which is the
# read-only extra-data dir, so it crashes on startup. Upstream lets us redirect
# it: point YOUTUBEDOWNLOADER_SETTINGS_PATH at the writable per-app config dir
# (a trailing slash makes the app append Settings.dat). Flatpak persists
# XDG_CONFIG_HOME across updates, so settings survive.
config_dir="${XDG_CONFIG_HOME:-$HOME/.config}"
mkdir -p "$config_dir"
export YOUTUBEDOWNLOADER_SETTINGS_PATH="$config_dir/"
# The in-app auto-updater would download into the read-only /app dir and is
# redundant — FlatPark tracks new upstream releases via extra-data.
export YOUTUBEDOWNLOADER_ALLOW_AUTO_UPDATE=false

exec /app/extra/ytd/YoutubeDownloader "$@"
