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

EAPI=8

VALA_MIN_API_VERSION="0.56"

inherit gnome2-utils meson vala xdg

DESCRIPTION="A time management utility for GNOME based on the pomodoro technique"
HOMEPAGE="
	https://gnomepomodoro.org/
	https://github.com/focustimerhq/FocusTimer
"
SRC_URI="https://github.com/focustimerhq/FocusTimer/archive/refs/tags/${PV}.tar.gz -> ${P}.tar.gz"
S="${WORKDIR}/FocusTimer-${PV}"

LICENSE="GPL-3"
SLOT="0"
KEYWORDS="~amd64"
IUSE="bash-completion layer-shell"
RESTRICT="mirror"

RDEPEND="
	dev-db/sqlite:3
	>=dev-libs/glib-2.50:2
	>=dev-libs/gom-0.5.0
	>=dev-libs/json-glib-1.6.2
	dev-libs/libpeas:2
	>=gui-libs/gtk-4.18:4
	>=gui-libs/libadwaita-1.7.0:1
	layer-shell? ( >=gui-libs/gtk4-layer-shell-1.0[introspection,vala] )
	media-libs/graphene[introspection]
	>=media-libs/gstreamer-1.0.10:1.0
	x11-libs/pango
"
DEPEND="${RDEPEND}"
BDEPEND="
	$(vala_depend)
	bash-completion? ( app-shells/bash-completion )
	dev-libs/gobject-introspection
	dev-libs/libpeas:2[vala]
	sys-devel/gettext
	virtual/pkgconfig
"

src_prepare() {
	xdg_src_prepare

	# gtk4-layer-shell is detected automagically, make it follow the USE flag
	if use layer-shell; then
		sed -i -e "/gtk4-layer-shell-0/s/required: false/required: true/" meson.build || die
	else
		sed -i -e "s/dependency('gtk4-layer-shell-0'[^)]*)/dependency('', required: false)/" meson.build || die
	fi
}

src_configure() {
	vala_setup
	meson_src_configure
}

pkg_postinst() {
	gnome2_schemas_update
	xdg_pkg_postinst
}

pkg_postrm() {
	gnome2_schemas_update
	xdg_pkg_postrm
}