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

EAPI=8

PYTHON_COMPAT=( python3_{11..13} )

inherit python-single-r1 xdg

MY_PN="${PN%-bin}"
MY_P="${MY_PN}_${PV}"

DESCRIPTION="Simple and lightweight app for running Windows games using UMU-Launcher"
HOMEPAGE="https://github.com/Faugus/faugus-launcher"
SRC_URI="https://github.com/Faugus/${MY_PN}/releases/download/${PV}/${MY_P}-1_all.deb"

S="${WORKDIR}"

LICENSE="MIT"
SLOT="0"
KEYWORDS="~amd64"
RESTRICT="mirror"

REQUIRED_USE="${PYTHON_REQUIRED_USE}"

RDEPEND="
	${PYTHON_DEPS}
	$(python_gen_cond_dep '
		dev-python/pygobject[${PYTHON_USEDEP}]
		dev-python/requests[${PYTHON_USEDEP}]
		dev-python/pillow[${PYTHON_USEDEP}]
		dev-python/filelock[${PYTHON_USEDEP}]
		dev-python/psutil[${PYTHON_USEDEP}]
		dev-python/vdf[${PYTHON_USEDEP}]
	')
	media-gfx/imagemagick
	dev-libs/libayatana-appindicator
	gui-libs/gtk:4
	gui-libs/libadwaita:1
"
BDEPEND="app-arch/dpkg"

src_unpack() {
	# Extract data.tar from deb
	cd "${S}" || die
	ar x "${DISTDIR}/${MY_P}-1_all.deb" || die
	# data.tar.zst in this package
	tar --zstd -xf data.tar.zst || die
}

src_install() {
	# Install binaries from /usr/bin/
	dobin usr/bin/faugus-launcher
	dobin usr/bin/faugus-proton-manager
	dobin usr/bin/faugus-run

	# Install Python modules to site-packages
	python_moduleinto faugus
	python_domodule usr/lib/python3/dist-packages/faugus/*.py

	# Install data files
	insinto /usr/share/faugus-launcher
	doins -r usr/share/faugus-launcher/*

	# Install desktop entries
	insinto /usr/share/applications
	doins usr/share/applications/*.desktop

	# Install icons
	insinto /usr/share/icons/hicolor/256x256/apps
	doins usr/share/icons/hicolor/256x256/apps/*.png
	doins usr/share/icons/hicolor/256x256/apps/*.svg

	# Install scalable icons
	if [[ -d usr/share/icons/hicolor/scalable/actions ]]; then
		insinto /usr/share/icons/hicolor/scalable/actions
		doins usr/share/icons/hicolor/scalable/actions/*.svg
	fi

	# Install locale files if present
	if [[ -d usr/share/locale ]]; then
		insinto /usr/share
		doins -r usr/share/locale
	fi
}

pkg_postinst() {
	xdg_pkg_postinst

	elog "========================================="
	elog "Faugus Launcher has been installed!"
	elog "========================================="
	elog ""
	elog "You will need a Proton/Wine runner to play games."
	elog "Install one of the following:"
	elog "  - app-emulation/wine-ge-custom-bin"
	elog "  - app-emulation/wine-cachyos"
	elog "  - games-util/umu-launcher"
	elog ""
	elog "Or install Proton-GE from Steam compatibility tools."
	elog "========================================="
}