#!/bin/sh
# Flathub remote + the full Spotify GUI client (docs/project-plan.md Phase 16).
#
# Spotify ships no apt package for bookworm, so this comes from Flathub — the same
# distribution channel already used for hosts/thin-client's Steam Link. No release
# version is pinned, same "don't hardcode a URL that will just rot" reasoning as that
# hook and as 0500-spotify-connect.hook.chroot's headless-receiver install.
set -eu

flatpak remote-add --if-not-exists flathub https://dl.flathub.org/repo/flathub.flatpakrepo

# VERIFY BEFORE THE FIRST REAL BUILD: confirm this application ID against the live
# Flathub listing (`flatpak search Spotify`). Believed correct (it's Spotify's own
# published app on Flathub) but not checked from this environment.
SPOTIFY_APP_ID="com.spotify.Client"

if flatpak install -y --noninteractive flathub "$SPOTIFY_APP_ID"; then
  echo "0300-flatpak-spotify: installed ${SPOTIFY_APP_ID}."
else
  echo "0300-flatpak-spotify: WARNING — could not install ${SPOTIFY_APP_ID} during the"
  echo "  build (no network in the chroot, or the app ID is wrong). Run this on the"
  echo "  booted image instead:  flatpak install -y flathub ${SPOTIFY_APP_ID}"
  echo "  The Spotify workspace will show a blank window until this is done."
fi
