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

EAPI=8

CRATES="
	addr2line@0.24.2
	adler2@2.0.0
	aho-corasick@1.1.3
	aligned-vec@0.5.0
	alloc-no-stdlib@2.0.4
	alloc-stdlib@0.2.2
	android-tzdata@0.1.1
	android_system_properties@0.1.5
	anstream@0.6.17
	anstyle-parse@0.2.6
	anstyle-query@1.1.2
	anstyle-wincon@3.0.6
	anstyle@1.0.9
	anyhow@1.0.91
	arbitrary@1.3.2
	arboard@3.4.1
	arg_enum_proc_macro@0.3.4
	arrayvec@0.7.6
	ascii@1.1.0
	async-broadcast@0.7.1
	async-channel@2.3.1
	async-executor@1.13.1
	async-fs@2.1.2
	async-io@2.3.4
	async-lock@3.4.0
	async-process@2.3.0
	async-recursion@1.1.1
	async-signal@0.2.10
	async-task@4.7.1
	async-trait@0.1.83
	atk-sys@0.18.0
	atk@0.18.0
	atomic-waker@1.1.2
	autocfg@1.4.0
	av1-grain@0.2.3
	avif-serialize@0.8.2
	backtrace@0.3.74
	base64@0.21.7
	base64@0.22.1
	bit_field@0.10.2
	bitflags@1.3.2
	bitflags@2.6.0
	bitstream-io@2.5.3
	block-buffer@0.10.4
	block2@0.5.1
	block@0.1.6
	blocking@1.6.1
	brotli-decompressor@4.0.1
	brotli@7.0.0
	built@0.7.5
	bumpalo@3.16.0
	bytemuck@1.19.0
	byteorder-lite@0.1.0
	byteorder@1.5.0
	bytes@1.8.0
	cairo-rs@0.18.5
	cairo-sys-rs@0.18.2
	camino@1.1.9
	cargo-platform@0.1.8
	cargo_metadata@0.18.1
	cargo_toml@0.17.2
	cc@1.1.31
	cesu8@1.1.0
	cfb@0.7.3
	cfg-expr@0.15.8
	cfg-if@1.0.0
	cfg_aliases@0.2.1
	chrono@0.4.38
	chunked_transfer@1.5.0
	clap@4.5.20
	clap_builder@4.5.20
	clap_lex@0.7.2
	clipboard-win@5.4.0
	cocoa-foundation@0.2.0
	cocoa@0.26.0
	color_quant@1.1.0
	colorchoice@1.0.3
	combine@4.6.7
	concurrent-queue@2.5.0
	convert_case@0.4.0
	core-foundation-sys@0.8.7
	core-foundation@0.10.0
	core-foundation@0.9.4
	core-graphics-types@0.1.3
	core-graphics-types@0.2.0
	core-graphics@0.23.2
	core-graphics@0.24.0
	cpufeatures@0.2.14
	crc32fast@1.4.2
	crossbeam-channel@0.5.13
	crossbeam-deque@0.8.5
	crossbeam-epoch@0.9.18
	crossbeam-utils@0.8.20
	crunchy@0.2.2
	crypto-common@0.1.6
	cssparser-macros@0.6.1
	cssparser@0.27.2
	ctor@0.2.8
	darling@0.20.10
	darling_core@0.20.10
	darling_macro@0.20.10
	deranged@0.3.11
	derivative@2.2.0
	derive_more@0.99.18
	digest@0.10.7
	dirs-sys@0.4.1
	dirs@5.0.1
	dispatch@0.2.0
	dlopen2@0.7.0
	dlopen2_derive@0.4.0
	dpi@0.1.1
	dtoa-short@0.3.5
	dtoa@1.0.9
	dunce@1.0.5
	dyn-clone@1.0.17
	either@1.13.0
	embed-resource@2.5.0
	embed_plist@1.2.2
	encoding_rs@0.8.35
	endi@1.1.0
	enumflags2@0.7.10
	enumflags2_derive@0.7.10
	equivalent@1.0.1
	erased-serde@0.4.5
	errno@0.3.9
	error-code@3.3.1
	event-listener-strategy@0.5.2
	event-listener@5.3.1
	exr@1.73.0
	fastrand@2.1.1
	fdeflate@0.3.6
	field-offset@0.3.6
	flate2@1.0.34
	fluent-uri@0.1.4
	fnv@1.0.7
	foreign-types-macros@0.2.3
	foreign-types-shared@0.3.1
	foreign-types@0.5.0
	form_urlencoded@1.2.1
	futf@0.1.5
	futures-channel@0.3.31
	futures-core@0.3.31
	futures-executor@0.3.31
	futures-io@0.3.31
	futures-lite@2.4.0
	futures-macro@0.3.31
	futures-sink@0.3.31
	futures-task@0.3.31
	futures-util@0.3.31
	fxhash@0.2.1
	gdk-pixbuf-sys@0.18.0
	gdk-pixbuf@0.18.5
	gdk-sys@0.18.0
	gdk@0.18.0
	gdkwayland-sys@0.18.0
	gdkx11-sys@0.18.0
	gdkx11@0.18.0
	generic-array@0.14.7
	gethostname@0.4.3
	getrandom@0.1.16
	getrandom@0.2.15
	gif@0.13.1
	gimli@0.31.1
	gio-sys@0.18.1
	gio@0.18.4
	glib-macros@0.18.5
	glib-sys@0.18.1
	glib@0.18.5
	glob@0.3.1
	gobject-sys@0.18.0
	gtk-sys@0.18.0
	gtk3-macros@0.18.0
	gtk@0.18.1
	half@2.4.1
	hashbrown@0.12.3
	hashbrown@0.15.0
	heck@0.4.1
	heck@0.5.0
	hermit-abi@0.3.9
	hermit-abi@0.4.0
	hex@0.4.3
	html5ever@0.26.0
	http-body-util@0.1.2
	http-body@1.0.1
	http@1.1.0
	httparse@1.9.5
	httpdate@1.0.3
	hyper-util@0.1.10
	hyper@1.5.0
	iana-time-zone-haiku@0.1.2
	iana-time-zone@0.1.61
	ico@0.3.0
	ident_case@1.0.1
	idna@0.5.0
	image-webp@0.2.0
	image@0.25.4
	imgref@1.11.0
	indexmap@1.9.3
	indexmap@2.6.0
	infer@0.16.0
	instant@0.1.13
	interpolate_name@0.2.4
	ipnet@2.10.1
	is-docker@0.2.0
	is-wsl@0.4.0
	is_terminal_polyfill@1.70.1
	itertools@0.12.1
	itoa@0.4.8
	itoa@1.0.11
	javascriptcore-rs-sys@1.1.1
	javascriptcore-rs@1.1.2
	jni-sys@0.3.0
	jni@0.21.1
	jobserver@0.1.32
	jpeg-decoder@0.3.1
	js-sys@0.3.72
	json-patch@2.0.0
	json-patch@3.0.1
	jsonptr@0.4.7
	jsonptr@0.6.3
	keyboard-types@0.7.0
	kuchikiki@0.8.2
	lazy_static@1.5.0
	lebe@0.5.2
	libappindicator-sys@0.9.0
	libappindicator@0.9.0
	libc@0.2.161
	libfuzzer-sys@0.4.7
	libloading@0.7.4
	libredox@0.1.3
	linux-raw-sys@0.4.14
	lock_api@0.4.12
	log@0.4.22
	loop9@0.1.5
	mac@0.1.1
	malloc_buf@0.0.6
	markup5ever@0.11.0
	matches@0.1.10
	maybe-rayon@0.1.1
	memchr@2.7.4
	memoffset@0.9.1
	mime@0.3.17
	minimal-lexical@0.2.1
	miniz_oxide@0.8.0
	mio@1.0.2
	muda@0.15.2
	ndk-context@0.1.1
	ndk-sys@0.6.0+11769913
	ndk@0.9.0
	new_debug_unreachable@1.0.6
	nix@0.27.1
	nodrop@0.1.14
	nom@7.1.3
	noop_proc_macro@0.3.0
	num-bigint@0.4.6
	num-conv@0.1.0
	num-derive@0.4.2
	num-integer@0.1.46
	num-rational@0.4.2
	num-traits@0.2.19
	num_enum@0.7.3
	num_enum_derive@0.7.3
	objc-sys@0.3.5
	objc2-app-kit@0.2.2
	objc2-cloud-kit@0.2.2
	objc2-contacts@0.2.2
	objc2-core-data@0.2.2
	objc2-core-image@0.2.2
	objc2-core-location@0.2.2
	objc2-encode@4.0.3
	objc2-foundation@0.2.2
	objc2-link-presentation@0.2.2
	objc2-metal@0.2.2
	objc2-quartz-core@0.2.2
	objc2-symbols@0.2.2
	objc2-ui-kit@0.2.2
	objc2-uniform-type-identifiers@0.2.2
	objc2-user-notifications@0.2.2
	objc2-web-kit@0.2.2
	objc2@0.5.2
	objc@0.2.7
	object@0.36.5
	once_cell@1.20.2
	open@5.3.0
	option-ext@0.2.0
	ordered-stream@0.2.0
	os_pipe@1.2.1
	pango-sys@0.18.0
	pango@0.18.3
	parking@2.2.1
	parking_lot@0.12.3
	parking_lot_core@0.9.10
	paste@1.0.15
	pathdiff@0.2.2
	percent-encoding@2.3.1
	phf@0.10.1
	phf@0.11.2
	phf@0.8.0
	phf_codegen@0.10.0
	phf_codegen@0.8.0
	phf_generator@0.10.0
	phf_generator@0.11.2
	phf_generator@0.8.0
	phf_macros@0.11.2
	phf_macros@0.8.0
	phf_shared@0.10.0
	phf_shared@0.11.2
	phf_shared@0.8.0
	pin-project-lite@0.2.15
	pin-utils@0.1.0
	piper@0.2.4
	pkg-config@0.3.31
	plist@1.7.0
	png@0.17.14
	polling@3.7.3
	powerfmt@0.2.0
	ppv-lite86@0.2.20
	precomputed-hash@0.1.1
	proc-macro-crate@1.3.1
	proc-macro-crate@2.0.2
	proc-macro-error-attr@1.0.4
	proc-macro-error@1.0.4
	proc-macro-hack@0.5.20+deprecated
	proc-macro2@1.0.89
	profiling-procmacros@1.0.16
	profiling@1.0.16
	qoi@0.4.1
	quick-error@2.0.1
	quick-xml@0.32.0
	quote@1.0.37
	rand@0.7.3
	rand@0.8.5
	rand_chacha@0.2.2
	rand_chacha@0.3.1
	rand_core@0.5.1
	rand_core@0.6.4
	rand_hc@0.2.0
	rand_pcg@0.2.1
	rav1e@0.7.1
	ravif@0.11.11
	raw-window-handle@0.6.2
	rayon-core@1.12.1
	rayon@1.10.0
	redox_syscall@0.5.7
	redox_users@0.4.6
	regex-automata@0.4.8
	regex-syntax@0.8.5
	regex@1.11.1
	reqwest@0.12.9
	rgb@0.8.50
	rustc-demangle@0.1.24
	rustc_version@0.4.1
	rustix@0.38.38
	ryu@1.0.18
	same-file@1.0.6
	schemars@0.8.21
	schemars_derive@0.8.21
	scopeguard@1.2.0
	selectors@0.22.0
	semver@1.0.23
	serde-untagged@0.1.6
	serde@1.0.214
	serde_derive@1.0.214
	serde_derive_internals@0.29.1
	serde_json@1.0.132
	serde_repr@0.1.19
	serde_spanned@0.6.8
	serde_urlencoded@0.7.1
	serde_with@3.11.0
	serde_with_macros@3.11.0
	serialize-to-javascript-impl@0.1.1
	serialize-to-javascript@0.1.1
	servo_arc@0.1.1
	sha1@0.10.6
	sha2@0.10.8
	shared_child@1.0.1
	shlex@1.3.0
	signal-hook-registry@1.4.2
	simd-adler32@0.3.7
	simd_helpers@0.1.0
	siphasher@0.3.11
	slab@0.4.9
	smallvec@1.13.2
	socket2@0.5.7
	softbuffer@0.4.6
	soup3-sys@0.5.0
	soup3@0.5.0
	stable_deref_trait@1.2.0
	static_assertions@1.1.0
	string_cache@0.8.7
	string_cache_codegen@0.5.2
	strsim@0.11.1
	swift-rs@1.0.7
	syn@1.0.109
	syn@2.0.85
	sync_wrapper@1.0.1
	system-deps@6.2.2
	tao-macros@0.1.3
	tao@0.30.5
	target-lexicon@0.12.16
	tauri-build@2.0.2
	tauri-codegen@2.0.2
	tauri-macros@2.0.2
	tauri-plugin-cli@2.0.1
	tauri-plugin-clipboard-manager@2.0.1
	tauri-plugin-localhost@2.0.1
	tauri-plugin-shell@2.0.2
	tauri-plugin-store@2.1.0
	tauri-plugin-window-state@2.0.1
	tauri-plugin@2.0.2
	tauri-runtime-wry@2.1.2
	tauri-runtime@2.1.1
	tauri-utils@2.0.2
	tauri-winres@0.1.1
	tauri@2.0.6
	tempfile@3.13.0
	tendril@0.4.3
	thin-slice@0.1.1
	thiserror-impl@1.0.65
	thiserror@1.0.65
	tiff@0.9.1
	time-core@0.1.2
	time-macros@0.2.18
	time@0.3.36
	tiny_http@0.12.0
	tinyvec@1.8.0
	tinyvec_macros@0.1.1
	tokio-macros@2.4.0
	tokio-util@0.7.12
	tokio@1.41.0
	toml@0.7.8
	toml@0.8.2
	toml_datetime@0.6.3
	toml_edit@0.19.15
	toml_edit@0.20.2
	tower-service@0.3.3
	tracing-attributes@0.1.27
	tracing-core@0.1.32
	tracing@0.1.40
	tray-icon@0.19.1
	try-lock@0.2.5
	typeid@1.0.2
	typenum@1.17.0
	uds_windows@1.1.0
	unic-char-property@0.9.0
	unic-char-range@0.9.0
	unic-common@0.9.0
	unic-ucd-ident@0.9.0
	unic-ucd-version@0.9.0
	unicode-bidi@0.3.17
	unicode-ident@1.0.13
	unicode-normalization@0.1.24
	unicode-segmentation@1.12.0
	url@2.5.2
	urlpattern@0.3.0
	utf-8@0.7.6
	utf8parse@0.2.2
	uuid@1.11.0
	v_frame@0.3.8
	version-compare@0.2.0
	version_check@0.9.5
	vswhom-sys@0.1.2
	vswhom@0.1.0
	walkdir@2.5.0
	want@0.3.1
	wasi@0.11.0+wasi-snapshot-preview1
	wasi@0.9.0+wasi-snapshot-preview1
	wasm-bindgen-backend@0.2.95
	wasm-bindgen-futures@0.4.45
	wasm-bindgen-macro-support@0.2.95
	wasm-bindgen-macro@0.2.95
	wasm-bindgen-shared@0.2.95
	wasm-bindgen@0.2.95
	wasm-streams@0.4.2
	web-sys@0.3.72
	webkit2gtk-sys@2.0.1
	webkit2gtk@2.0.1
	webview2-com-macros@0.8.0
	webview2-com-sys@0.33.0
	webview2-com@0.33.0
	weezl@0.1.8
	winapi-i686-pc-windows-gnu@0.4.0
	winapi-util@0.1.9
	winapi-x86_64-pc-windows-gnu@0.4.0
	winapi@0.3.9
	window-vibrancy@0.5.2
	windows-core@0.52.0
	windows-core@0.58.0
	windows-implement@0.58.0
	windows-interface@0.58.0
	windows-registry@0.2.0
	windows-result@0.2.0
	windows-strings@0.1.0
	windows-sys@0.45.0
	windows-sys@0.48.0
	windows-sys@0.52.0
	windows-sys@0.59.0
	windows-targets@0.42.2
	windows-targets@0.48.5
	windows-targets@0.52.6
	windows-version@0.1.1
	windows@0.58.0
	windows_aarch64_gnullvm@0.42.2
	windows_aarch64_gnullvm@0.48.5
	windows_aarch64_gnullvm@0.52.6
	windows_aarch64_msvc@0.42.2
	windows_aarch64_msvc@0.48.5
	windows_aarch64_msvc@0.52.6
	windows_i686_gnu@0.42.2
	windows_i686_gnu@0.48.5
	windows_i686_gnu@0.52.6
	windows_i686_gnullvm@0.52.6
	windows_i686_msvc@0.42.2
	windows_i686_msvc@0.48.5
	windows_i686_msvc@0.52.6
	windows_x86_64_gnu@0.42.2
	windows_x86_64_gnu@0.48.5
	windows_x86_64_gnu@0.52.6
	windows_x86_64_gnullvm@0.42.2
	windows_x86_64_gnullvm@0.48.5
	windows_x86_64_gnullvm@0.52.6
	windows_x86_64_msvc@0.42.2
	windows_x86_64_msvc@0.48.5
	windows_x86_64_msvc@0.52.6
	winnow@0.5.40
	winreg@0.52.0
	wry@0.46.3
	x11-dl@2.21.0
	x11@2.21.0
	x11rb-protocol@0.13.1
	x11rb@0.13.1
	xdg-home@1.3.0
	zbus@4.0.1
	zbus_macros@4.0.1
	zbus_names@3.0.0
	zerocopy-derive@0.7.35
	zerocopy@0.7.35
	zune-core@0.4.12
	zune-inflate@0.2.54
	zune-jpeg@0.4.13
	zvariant@4.0.0
	zvariant_derive@4.0.0
	zvariant_utils@1.1.0
"

inherit cargo desktop optfeature unpacker xdg

DESCRIPTION="Monitor and control your cooling and other devices"
HOMEPAGE="https://gitlab.com/coolercontrol/coolercontrol"
SRC_URI="
	https://gitlab.com/coolercontrol/coolercontrol/-/archive/${PV}/${P}.tar.bz2
	https://gitlab.com/coolercontrol/coolercontrol/-/releases/${PV}/downloads/packages/coolercontrol-ui.tzst
		-> ${P}-ui.tar.zst
	${CARGO_CRATE_URIS}
"
S="${WORKDIR}/coolercontrol-${PV}/coolercontrol-ui/src-tauri"

LICENSE="GPL-3+ CC0-1.0"
# Dependent crate licenses
LICENSE+="
	Apache-2.0 Apache-2.0-with-LLVM-exceptions BSD-2 BSD Boost-1.0 ISC
	MIT MPL-2.0 Unicode-DFS-2016
"
SLOT="0"
KEYWORDS="~amd64"

DEPEND="
	dev-libs/glib:2
	net-libs/libsoup:3.0
	net-libs/webkit-gtk:4.1
	x11-libs/cairo
	x11-libs/gdk-pixbuf:2
	x11-libs/gtk+:3
"
RDEPEND="
	${DEPEND}
	dev-libs/libayatana-appindicator
	sys-apps/coolercontrold
	virtual/pkgconfig
"
BDEPEND="
	net-libs/nodejs[npm]
"

QA_FLAGS_IGNORED=".*"

src_unpack() {
	# Yes, there will be a double unpack
	cargo_src_unpack
	unpacker ${P}-ui.tar.zst
}

src_prepare() {
	pushd ../.. >/dev/null || die
	default
	popd >/dev/null || die

	# Disable stripping
	sed -i -e '/^strip =/d' Cargo.toml || die

	mv "${WORKDIR}"/node_modules "${S}"/.. || die
}

src_configure() {
	local myfeatures=(
		# https://gitlab.com/coolercontrol/coolercontrol/-/blob/1.4.0/coolercontrol-ui/src-tauri/Cargo.toml?ref_type=tags#L41
		custom-protocol
	)
	cargo_src_configure
}

src_compile() {
	pushd .. >/dev/null || die
	npm run build-only || die
	popd >/dev/null || die

	cargo_src_compile
}

src_test() {
	cargo_src_test

	pushd .. >/dev/null || die
	npm run test:unit || die
	popd >/dev/null || die
}

src_install() {
	cargo_src_install

	einstalldocs

	domenu ../../packaging/metadata/org.coolercontrol.CoolerControl.desktop
	doicon ../../packaging/metadata/org.coolercontrol.CoolerControl.png
	doicon ../../packaging/metadata/org.coolercontrol.CoolerControl.svg
	insinto /usr/share/metainfo
	doins ../../packaging/metadata/org.coolercontrol.CoolerControl.metainfo.xml
}

pkg_postinst() {
	xdg_pkg_postinst

	optfeature "interact with AIO liquid coolers and other devices" sys-apps/coolercontrol-liqctld
}