# Copyright 2022-2023 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2

EAPI=8

PYTHON_COMPAT=( python3_{10..13} )

inherit python-single-r1

MY_PN=textern

DESCRIPTION="Host app for the Textern Firefox add-on"
HOMEPAGE="https://github.com/jlebon/textern"
SRC_URI="https://github.com/jlebon/${MY_PN}/archive/refs/tags/v${PV}.tar.gz -> ${MY_PN}-${PV}.tar.gz"

S="${WORKDIR}"/${MY_PN}-${PV}

LICENSE="GPL-3+"
SLOT="0"
KEYWORDS="~amd64"
REQUIRED_USE="${PYTHON_REQUIRED_USE}"

RDEPEND="
	${PYTHON_DEPS}
	$(python_gen_cond_dep '
		dev-python/inotify-simple[${PYTHON_USEDEP}]
	')
"

src_prepare() {
	default

	python_fix_shebang "native/textern.py"

	sed -e "s|@@NATIVE_PATH@@|${EPREFIX}/usr/libexec/textern.py|" \
		native/textern.json.in > native/textern.json || die
}

src_compile() {
	:
}

src_install() {
	exeinto /usr/libexec
	doexe native/textern.py

	insinto /usr/lib/mozilla/native-messaging-hosts
	doins native/textern.json

	insinto /usr/$(get_libdir)/mozilla/native-messaging-hosts
	doins native/textern.json
}