# Contributor: Jakub Jirutka <jakub@jirutka.cz>
# Maintainer: Jakub Jirutka <jakub@jirutka.cz>
pkgname=ncspot
pkgver=1.1.0
pkgrel=0
pkgdesc="Cross-platform ncurses Spotify client inspired by ncmpc and the likes"
url="https://github.com/hrkfdn/ncspot"
# riscv64: takes eternity to build
# s390x: fails to build nix crate
# ppc64le: fails to build notify-rust crate
# loongarch64: fails to build notify-rust crate
arch="all !riscv64 !s390x !ppc64le !loongarch64"
license="BSD-2-Clause"
makedepends="
	cargo
	cargo-auditable
	libxcb-dev
	ncurses-dev
	openssl-dev>3
	pulseaudio-dev
	python3
	"
_rspotify_ver=0.12.0
_notify_rust_ver=4.10.0
source="https://github.com/hrkfdn/ncspot/archive/v$pkgver/ncspot-$pkgver.tar.gz
	https://github.com/ramsayleung/rspotify/archive/v$_rspotify_ver/rspotify-$_rspotify_ver.tar.gz
	https://github.com/hoodie/notify-rust/archive/v$_notify_rust_ver/notify-rust-$_notify_rust_ver.tar.gz
	no-rustls.patch
	rspotify-fix-ureq-native-tls.patch
	notify-rust-zbus-v4.patch
	cargo.lock.patch
	"
options="!check"  # there's only one unit test (in v0.8.1)

# Build with ncurses_backend instead of termion_backend, enable cover and share_selection.
_cargo_opts="
	--frozen
	--no-default-features
	--features share_clipboard,pulseaudio_backend,mpris,notify,cover,share_selection,ncurses_backend
	"

prepare() {
	mkdir -p vendor
	mv "$srcdir"/rspotify-$_rspotify_ver vendor/rspotify
	mv "$srcdir"/notify-rust-$_notify_rust_ver vendor/notify-rust

	default_prepare

	# Build with patched notify-rust and rspotify (see *.patch files).
	# TODO: Remove notify-rust after https://github.com/hoodie/notify-rust/pull/202
	#  is merged and released.
	# TODO: Remove rspotify after https://github.com/ramsayleung/rspotify/pull/471
	#  is released and ncspot moved to this version.
	cat >> Cargo.toml <<-EOF

		[patch.crates-io]
		notify-rust = { path = "vendor/notify-rust" }
		rspotify = { path = "vendor/rspotify" }
	EOF

	cargo fetch --target="$CTARGET" --locked
}

build() {
	cargo auditable build $_cargo_opts --release
}

check() {
	cargo test $_cargo_opts
}

package() {
	install -D -m755 target/release/$pkgname -t "$pkgdir"/usr/bin/
}

sha512sums="
e07e119e682649428aeabebd2ae882b0111a83e0f1bc3c47843f38351a9d833c7cbace48f777bca3edbebe58b9dd55e8135becbdc4693560a307667fd0f2b2e9  ncspot-1.1.0.tar.gz
83d8a2ffc67f9a8986bac01e330a24ef764bc65f8bc8d2b5a96c46082a5d5bcc7f7659e259cb6bd30a32e4abaadb889be1953f97491cf1e34865cc734b0a55bf  rspotify-0.12.0.tar.gz
dbff70bee81513af930dd2147037e28ac06affe2ffbae4528c343d42aac27d683a205dc1c7e1ae1b10812148e96ed179e257c32feead833de3800056a1db95bf  notify-rust-4.10.0.tar.gz
0142b6d01fa500454130040095730a28fa51f697e5c0d2aa4046e29a18ba9c7161256683609c3233a28d0bdd2aff84e1297fc81376099624f7401ef45cee3c0f  no-rustls.patch
4610754ce0d760854ebefc0a6bf99afe5c4294c05119dd5f94b7294fda0b98b193ff596df4ae255d86ff6e77922ab4a53394f92c28d48a3f59e4a8bfe1381f01  rspotify-fix-ureq-native-tls.patch
e8b33f6a0c3614cf6741f81868bb87f02e2338fc4a2e726f9b1bfe5e2b21e12907933e16615a2d668ce42f0d95a299cb99086506488f49b91dfa884ef5d4c227  notify-rust-zbus-v4.patch
02a9a85e57f80cf11e86f813cd71ded28e1de0bcaa424de76d01faa7ed142699ed6465ff6b1109bd4e01bb1070b234e193a597db5fe38706454002f3a4438976  cargo.lock.patch
"
