# Copyright 2024 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2

# Autogenerated by pycargoebuild 0.14.0

EAPI=8

CRATES="
"

declare -A GIT_CRATES=(
	[dark-light]='https://github.com/frewsxcv/rust-dark-light;b8edef9072f7d38ae879129cde03bb1f40750c4c;dark-light-%commit%'
)

PLOCALES="en_US it_IT zh_CN"
PLOCALE_BACKUP="en_US"
RUST_MIN_VER="1.78"
inherit cargo desktop gnome2-utils plocale xdg

DESCRIPTION="Simple On Screen lyrics Display for linux/unix"
HOMEPAGE="
	https://waylyrics.github.io/waylyrics/waylyrics
	https://github.com/waylyrics/waylyrics
"

if [[ "${PV}" == *9999* ]]; then
	inherit git-r3
	EGIT_REPO_URI="https://github.com/waylyrics/waylyrics.git"
else
	SRC_URI="
		https://github.com/waylyrics/waylyrics/archive/refs/tags/v${PV}.tar.gz -> ${P}.tar.gz
		https://github.com/liuyujielol/gentoo-go-deps/releases/download/${P}/${P}-crates.tar.xz
		${CARGO_CRATE_URIS}
	"
	KEYWORDS="~amd64 ~loong"
fi

LICENSE="MIT CC-BY-4.0"
# Dependent crate licenses
LICENSE+="
	Apache-2.0 Apache-2.0-with-LLVM-exceptions BSD GPL-3+ ISC MIT
	MPL-2.0 Unicode-3.0 Unlicense
"
SLOT="0"

DEPEND="
	dev-libs/glib:2
	app-i18n/opencc
	dev-libs/openssl:=
	gnome-base/dconf
	gui-libs/gtk:4
	sys-apps/dbus
	sys-devel/gettext
	x11-libs/cairo
"
RDEPEND="
	${DEPEND}
	sys-apps/xdg-desktop-portal
"

src_compile() {
	export WAYLYRICS_THEME_PRESETS_DIR="/usr/share/${PN}/themes"
	cargo_src_compile --all-targets --all-features
}

src_install() {
	cargo_src_install

	doicon -s scalable "${S}/res/icons/hicolor/scalable/apps/io.github.waylyrics.Waylyrics.svg"
	domenu "${S}/metainfo/io.github.waylyrics.Waylyrics.desktop"

	insinto "/usr/share/glib-2.0/schemas"
	doins "${S}/metainfo/io.github.waylyrics.Waylyrics.gschema.xml"

	insinto "/usr/share/metainfo"
	doins "${S}/metainfo/io.github.waylyrics.Waylyrics.metainfo.xml"

	insinto "/usr/share/${PN}"
	doins -r themes

	cd "${S}/locales" || die
	install_locale() {
		if [[ -f ${1}/LC_MESSAGES/waylyrics.po ]]; then
			local file=${1}/LC_MESSAGES/waylyrics.po
			msgfmt "${file}" -o "${file%.po}.mo" || die
			insinto /usr/share/locale/${1}/LC_MESSAGES
			doins "${file%.po}.mo"
		fi
	}
	plocale_for_each_locale install_locale
}

pkg_postinst() {
	gnome2_schemas_update
	xdg_pkg_postinst
}

pkg_postrm() {
	gnome2_schemas_update
	xdg_pkg_postrm
}