#!/bin/sh
#
# Copyright (c) 2012 Spotify AB

# This script registers menus and icons
# It should be run from the folder containing the spotify executable

# Add icons to the system icons
XDG_ICON_RESOURCE="`which xdg-icon-resource 2> /dev/null`"
if [ ! -x "$XDG_ICON_RESOURCE" ]; then
  echo "Error: Could not find xdg-icon-resource" >&2
  exit 1
fi
for icon in "Icons/spotify-linux-"*.png; do
  size="${icon##*/spotify-linux-}"
  "$XDG_ICON_RESOURCE" install --size "${size%.png}" "$icon" "spotify-client"
done

# Add an entry to the system menu
XDG_DESKTOP_MENU="`which xdg-desktop-menu 2> /dev/null`"
UPDATE_MENUS="`which update-menus 2> /dev/null`"
if [ ! -x "$XDG_DESKTOP_MENU" ]; then
  echo "Error: Could not find xdg-desktop-menu" >&2
  exit 1
fi
# It seems the desktop file has to match the mpris name.
# I don't want to change that, so we use --novendor here
"$XDG_DESKTOP_MENU" install --novendor "spotify.desktop"

if [ -x "$UPDATE_MENUS" ]; then
  "$UPDATE_MENUS"
fi
