#!/bin/bash

# omarchy:summary=Install Spotify, as its web player where Spotify has no Linux client.
# omarchy:requires-sudo=true

set -e

if omarchy-hw-x86; then
  echo "Installing Spotify..."
  omarchy-pkg-aur-add com.spotify.Client

  echo "Opening Spotify..."
  setsid uwsm-app -- flatpak run --user com.spotify.Client >/dev/null 2>&1 &
else
  # Spotify builds its Linux client for x86_64 only (its repository serves amd64
  # and i386), so ARM gets the web player, which Chromium plays with the Widevine
  # module it fetches itself.
  echo "Installing Spotify as a web app..."
  omarchy-webapp-install "Spotify" "https://open.spotify.com/" "https://cdn.jsdelivr.net/gh/homarr-labs/dashboard-icons/png/spotify.png"

  echo "Opening Spotify..."
  setsid omarchy-launch-webapp "https://open.spotify.com/" >/dev/null 2>&1 &
fi

echo ""
echo "Spotify has been installed."
