# Copyright 1999-2026 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2

EAPI=8

inherit go-module

MY_PN="cli"

DESCRIPTION="Commandline tool to customize Spotify client"
HOMEPAGE="https://spicetify.app/"
SRC_URI="
	https://github.com/spicetify/cli/archive/v${PV}.tar.gz -> ${P}.tar.gz
"
if [[ ${PKGBUMPING} != ${PVR} ]]; then
	SRC_URI+=" https://gitlab.com/api/v4/projects/32909921/packages/generic/${PN}/${PV}/${P}-deps.tar.xz"
	SRC_URI+=" https://gitlab.com/api/v4/projects/32909921/packages/generic/${PN}/${PV}/${P}-js.tar.xz"
fi
S="${WORKDIR}/${MY_PN}-${PV}"

LICENSE="Apache-2.0 BSD LGPL-2.1 MIT"
SLOT="0"
KEYWORDS="~amd64"

RDEPEND="
	sys-process/procps
	x11-apps/xrdb
	x11-misc/xdg-utils
"
BDEPEND+=" >=dev-lang/go-1.25.0"

INSTALLDIR="/opt/${PN}"

src_compile() {
	ego build -ldflags "-X main.version=${PV}"
}

src_test() {
	ego test
}

src_install() {
	insinto "${INSTALLDIR}"
	doins -r {CustomApps,Extensions,Themes,jsHelper,cli}
	newbin - spicetify <<-EOF
	#!/usr/bin/env sh
	exec /opt/spicetify-cli/cli \$@
	EOF
	fperms +x "${INSTALLDIR}/cli"
}

pkg_postinst() {
	elog "Spicetify requires a Spotify install that it can modify."
	elog "To give read and write permissions to everyone on the system to run the following commands as root."
	elog "# chmod a+wr /opt/spotify/spotify-client"
	elog "# chmod a+wr /opt/spotify/spotify-client/Apps -R"
	elog ""
	elog "WARNING: Do not run spicetify as root please"
	elog ""
	elog "Otherwise you can install spotify to a user modifiable location like as a flatpak:"
	elog " https://spicetify.app/docs/advanced-usage/installation#spotify-installed-from-flatpak"
	elog ""
	elog "To install themes see:"
	elog " https://spicetify.app/docs/advanced-usage/themes"

	if $(has_version -r ">=media-sound/spotify-1.2.25"); then
		elog ""
		elog "The New Releases custom app no longer works with Spotify 1.2.25 and higher. As an alternative,"
		elog "please use What's New which was created by Spotify and can be enabled via Experimental Features"
		elog "if it isn't already enabled."
	fi
}