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

# Auto-Generated by cargo-ebuild 0.5.4

EAPI=8

CRATES="
	adler-1.0.2
	aho-corasick-0.7.19
	ansi_term-0.11.0
	ansi_term-0.12.1
	anyhow-1.0.38
	arrayref-0.3.6
	arrayvec-0.5.2
	atty-0.2.14
	autocfg-1.0.1
	base64-0.13.0
	bitflags-0.9.1
	bitflags-1.2.1
	blake2b_simd-0.5.11
	block-0.1.6
	block-buffer-0.9.0
	bstr-0.2.15
	bumpalo-3.7.0
	byteorder-1.4.3
	bytes-1.1.0
	bzip2-0.4.3
	bzip2-sys-0.1.11+1.0.8
	calloop-0.9.3
	caps-0.5.2
	cc-1.0.73
	cfg-if-0.1.10
	cfg-if-1.0.0
	chrono-0.4.19
	clap-2.33.3
	colored-2.0.0
	console-0.14.1
	const-sha1-0.2.0
	const_format-0.2.14
	const_format_proc_macros-0.2.14
	constant_time_eq-0.1.5
	core-foundation-0.9.1
	core-foundation-sys-0.8.2
	cpufeatures-0.2.1
	crc32fast-1.2.1
	crossbeam-0.8.1
	crossbeam-channel-0.5.0
	crossbeam-deque-0.8.1
	crossbeam-epoch-0.9.8
	crossbeam-queue-0.3.5
	crossbeam-utils-0.8.8
	cstr_core-0.2.5
	ctor-0.1.20
	cty-0.2.2
	dbus-0.9.1
	dialoguer-0.8.0
	diff-0.1.12
	difference-2.0.0
	digest-0.9.0
	dirs-1.0.5
	dirs-3.0.1
	dirs-sys-0.3.5
	dlib-0.5.0
	downcast-0.10.0
	downcast-rs-1.2.0
	dtoa-0.4.7
	dunce-1.0.1
	either-1.6.1
	encode_unicode-0.3.6
	encoding_rs-0.8.28
	enum-as-inner-0.3.3
	errno-0.2.7
	errno-dragonfly-0.1.1
	filetime-0.2.14
	flate2-1.0.20
	float-cmp-0.8.0
	fnv-1.0.7
	foreign-types-0.3.2
	foreign-types-shared-0.1.1
	form_urlencoded-1.0.1
	fragile-1.0.0
	fs2-0.4.3
	fs_extra-1.2.0
	fsevent-0.4.0
	fsevent-sys-2.0.1
	fuchsia-cprng-0.1.1
	fuchsia-zircon-0.3.3
	fuchsia-zircon-sys-0.3.3
	futf-0.1.4
	futures-channel-0.3.17
	futures-core-0.3.17
	futures-io-0.3.17
	futures-macro-0.3.17
	futures-sink-0.3.17
	futures-task-0.3.17
	futures-util-0.3.17
	gcc-0.3.55
	generic-array-0.14.4
	getrandom-0.1.16
	getrandom-0.2.2
	glob-0.3.0
	h2-0.3.4
	hashbrown-0.11.2
	heck-0.3.2
	hermit-abi-0.1.18
	hex-0.4.3
	html2text-0.2.1
	html5ever-0.25.1
	http-0.2.4
	http-body-0.4.3
	httparse-1.5.1
	httpdate-1.0.1
	hyper-0.14.12
	hyper-rustls-0.22.1
	hyper-tls-0.5.0
	idna-0.2.3
	include_dir-0.6.0
	include_dir_impl-0.6.0
	indexmap-1.7.0
	indoc-1.0.3
	inotify-0.7.1
	inotify-sys-0.1.5
	iovec-0.1.4
	ipnet-2.3.1
	itertools-0.10.0
	itoa-0.4.7
	js-sys-0.3.53
	kernel32-sys-0.2.2
	lazy_static-1.4.0
	lazycell-1.3.0
	libc-0.2.126
	libdbus-sys-0.2.1
	libloading-0.7.0
	linked-hash-map-0.5.4
	log-0.4.14
	log-panics-2.0.0
	mac-0.1.1
	mac-notification-sys-0.3.0
	malloc_buf-0.0.6
	maplit-1.0.2
	markdown-0.3.0
	markup5ever-0.10.1
	markup5ever_rcdom-0.1.0
	matches-0.1.9
	memchr-2.5.0
	memmap2-0.3.1
	memoffset-0.6.5
	mime-0.3.16
	miniz_oxide-0.4.4
	mio-0.6.23
	mio-0.7.13
	mio-extras-2.0.6
	miow-0.2.2
	miow-0.3.7
	mockall-0.9.1
	mockall_derive-0.9.1
	named_pipe-0.4.1
	native-tls-0.2.8
	natord-1.0.9
	net2-0.2.37
	new_debug_unreachable-1.0.4
	nix-0.22.3
	nix-0.24.2
	nom-6.1.2
	normalize-line-endings-0.3.0
	notify-4.0.17
	notify-rust-4.2.2
	ntapi-0.3.6
	num-integer-0.1.44
	num-traits-0.2.14
	num_cpus-1.13.0
	objc-0.2.7
	objc-foundation-0.1.1
	objc_id-0.1.1
	once_cell-1.8.0
	opaque-debug-0.3.0
	opener-0.5.0
	openssl-0.10.36
	openssl-probe-0.1.4
	openssl-sys-0.9.66
	ordered-float-2.1.1
	output_vt100-0.1.2
	path-slash-0.1.4
	percent-encoding-2.1.0
	phf-0.8.0
	phf_codegen-0.8.0
	phf_generator-0.8.0
	phf_shared-0.8.0
	pin-project-lite-0.2.7
	pin-utils-0.1.0
	pipeline-0.5.0
	pkg-config-0.3.19
	ppv-lite86-0.2.10
	precomputed-hash-0.1.1
	predicates-1.0.8
	predicates-core-1.0.2
	predicates-tree-1.0.2
	pretty_assertions-0.7.2
	proc-macro-hack-0.5.19
	proc-macro-nested-0.1.7
	proc-macro2-1.0.24
	pure-rust-locales-0.5.6
	quote-0.3.15
	quote-1.0.9
	rand-0.4.6
	rand-0.7.3
	rand-0.8.3
	rand_chacha-0.2.2
	rand_chacha-0.3.0
	rand_core-0.3.1
	rand_core-0.4.2
	rand_core-0.5.1
	rand_core-0.6.2
	rand_hc-0.2.0
	rand_hc-0.3.0
	rand_pcg-0.2.1
	rayon-1.5.3
	rayon-core-1.9.3
	rdrand-0.4.0
	redox_syscall-0.1.57
	redox_syscall-0.2.5
	redox_users-0.3.5
	regex-1.5.5
	regex-automata-0.1.10
	regex-syntax-0.6.27
	remove_dir_all-0.5.3
	reqwest-0.11.4
	ring-0.16.20
	rust-argon2-0.8.3
	rustls-0.19.1
	ryu-1.0.5
	same-file-1.0.6
	schannel-0.1.19
	scoped-tls-1.0.0
	scopeguard-1.1.0
	sct-0.6.1
	security-framework-2.3.1
	security-framework-sys-2.3.0
	serde-1.0.123
	serde_derive-1.0.123
	serde_json-1.0.62
	serde_urlencoded-0.7.0
	serde_yaml-0.8.17
	sha2-0.9.6
	simplelog-0.9.0
	siphasher-0.3.6
	slab-0.4.3
	smallvec-1.6.1
	smithay-client-toolkit-0.15.4
	socket2-0.4.1
	spin-0.5.2
	squote-0.1.2
	string_cache-0.8.1
	string_cache_codegen-0.5.1
	strsim-0.8.0
	strum-0.8.0
	strum-0.20.0
	strum_macros-0.8.0
	strum_macros-0.20.1
	syn-0.11.11
	syn-1.0.67
	synom-0.11.3
	sys-locale-0.1.0
	sysinfo-0.24.5
	tempdir-0.3.7
	tempfile-3.2.0
	tendril-0.4.2
	termcolor-1.1.2
	terminal_size-0.1.17
	test-case-1.1.0
	textwrap-0.11.0
	thiserror-1.0.23
	thiserror-impl-1.0.23
	time-0.1.44
	tinyvec-1.3.1
	tinyvec_macros-0.1.0
	tokio-1.10.1
	tokio-native-tls-0.3.0
	tokio-rustls-0.22.0
	tokio-util-0.6.7
	toml-0.5.8
	tower-service-0.3.1
	tracing-0.1.26
	tracing-core-0.1.19
	treeline-0.1.0
	try-lock-0.2.3
	typenum-1.14.0
	unicase-2.6.0
	unicode-bidi-0.3.6
	unicode-normalization-0.1.19
	unicode-segmentation-1.7.1
	unicode-width-0.1.8
	unicode-xid-0.0.4
	unicode-xid-0.2.1
	unindent-0.1.7
	untrusted-0.7.1
	url-2.2.2
	utf-8-0.7.6
	vcpkg-0.2.15
	vec_map-0.8.2
	version_check-0.9.2
	wait-timeout-0.2.0
	walkdir-2.3.1
	want-0.3.0
	wasi-0.9.0+wasi-snapshot-preview1
	wasi-0.10.0+wasi-snapshot-preview1
	wasm-bindgen-0.2.76
	wasm-bindgen-backend-0.2.76
	wasm-bindgen-futures-0.4.26
	wasm-bindgen-macro-0.2.76
	wasm-bindgen-macro-support-0.2.76
	wasm-bindgen-shared-0.2.76
	wayland-client-0.29.5
	wayland-commons-0.29.5
	wayland-cursor-0.29.5
	wayland-protocols-0.29.5
	wayland-scanner-0.29.5
	wayland-sys-0.29.5
	web-sys-0.3.53
	webpki-0.21.4
	webpki-roots-0.21.1
	widestring-0.4.3
	winapi-0.2.8
	winapi-0.3.9
	winapi-build-0.1.1
	winapi-i686-pc-windows-gnu-0.4.0
	winapi-util-0.1.5
	winapi-x86_64-pc-windows-gnu-0.4.0
	windows-0.3.1
	windows_gen-0.3.1
	windows_gen_macros-0.3.1
	windows_macros-0.3.1
	windows_winmd-0.3.1
	windows_winmd_macros-0.3.1
	winreg-0.7.0
	winreg-0.9.0
	winres-0.1.11
	winrt-0.4.0
	winrt-notification-0.2.2
	winrt-notification-0.3.1
	ws2_32-sys-0.2.1
	xcursor-0.3.3
	xml-rs-0.6.1
	xml-rs-0.8.3
	xml5ever-0.16.1
	yaml-rust-0.4.5
	zeroize-1.3.0
	zip-0.5.13
"

# Needed because espanso-migrate depends on the git version of yaml-rust
declare -A GIT_CRATES=(
	[yaml-rust]="https://github.com/federico-terzi/yaml-rust;454221bebabc93307bbf7aa7f556407dd3027363"
)

inherit cargo desktop fcaps linux-info systemd xdg-utils

DESCRIPTION="Cross-platform Text Expander written in Rust"
HOMEPAGE="https://espanso.org"
SRC_URI="
	https://github.com/espanso/${PN}/archive/refs/tags/v${PV}.tar.gz -> ${P}.tar.gz
	$(cargo_crate_uris)
"

# License set may be more restrictive as OR is not respected
# use cargo-license for a more accurate license picture
LICENSE="0BSD Apache-2.0 Apache-2.0-with-LLVM-exceptions BSD BSD-2 Boost-1.0 CC0-1.0 GPL-3 ISC MIT MPL-2.0 Unlicense ZLIB"
SLOT="0"
KEYWORDS="~amd64"
IUSE="wayland"

DEPEND="
	acct-group/input
	dev-libs/openssl
	x11-libs/wxGTK
	wayland? (
		x11-libs/libxkbcommon[wayland]
	)
	!wayland? (
		x11-libs/libX11
		x11-libs/libXtst
		x11-libs/libxkbcommon[X]
	)
"
RDEPEND="${DEPEND}"

QA_FLAGS_IGNORED="usr/bin/${PN}"

pkg_setup() {
	CONFIG_CHECK="~INPUT_UINPUT"
	ERROR_INPUT_UINPUT="Espanso with Wayland needs the UINPUT"
	ERROR_INPUT_UINPUT+=" input device driver to detect user inputs. Without it,"
	ERROR_INPUT_UINPUT+=" Espanso will not work as intended"

	# Now do the actual checks setup above, but only when using wayland
	use wayland && linux-info_pkg_setup
}

src_configure() {
	local myfeatures=(
		modulo
		native-tls
		$(usev wayland)
	)
	cargo_src_configure --verbose --no-default-features
}

src_compile() {
	cargo_src_compile -p "${PN}"
}

src_install() {
	cargo_src_install --path "${PN}"

	newicon -s 128 "espanso/src/res/linux/icon.png" "${PN}.png"
	domenu "espanso/src/res/linux/${PN}.desktop"

	# install the systemd-service (user level)
	sed -i "s|{{{espanso_path}}}|/usr/bin/espanso|g" "espanso/src/res/linux/systemd.service" || die
	systemd_newuserunit "espanso/src/res/linux/systemd.service" "${PN}.service"
}

pkg_postinst() {
	# See https://espanso.org/docs/install/linux/#adding-the-required-capabilities
	use wayland && fcaps cap_dac_override "usr/bin/${PN}"

	xdg_icon_cache_update
	xdg_desktop_database_update
}

pkg_postrm() {
	xdg_icon_cache_update
	xdg_desktop_database_update
}