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

EAPI=8

inherit desktop xdg

DESCRIPTION="Open Source Tools and Models for Makers, Builders, and Creatives"
HOMEPAGE="https://getartcraft.com/"
SRC_URI="
    amd64? ( https://github.com/storytold/craft-launcher/releases/download/v${PV}/${PN}-${PV}-linux-x86_64.tar.gz -> ${P}-x86_64.tar.gz )
    arm64? ( https://github.com/storytold/craft-launcher/releases/download/v${PV}/${PN}-${PV}-linux-aarch64.tar.gz -> ${P}-aarch64.tar.gz )
"

LICENSE="MIT"
SLOT="0"
KEYWORDS="amd64 arm64"

src_unpack() {
	default

	if use amd64; then
		S="${WORKDIR}/${PN}-${PV}-linux-x86_64"
	elif use arm64; then
		S="${WORKDIR}/${PN}-${PV}-linux-aarch64"
	fi
}

src_install() {
	if use amd64; then
		cd "${WORKDIR}/${PN}-${PV}-linux-x86_64" || die
	elif use arm64; then
		cd "${WORKDIR}/${PN}-${PV}-linux-aarch64" || die
	fi

	insinto /opt/artcraft-launcher
	doins -r bin

	fperms +x /opt/artcraft-launcher/bin/artcraft-launcher
	dosym /opt/artcraft-launcher/bin/artcraft-launcher /usr/bin/artcraft-launcher

	if [[ -d "share/icons/hicolor" ]]; then
		insinto /usr/share
		doins -r share/icons
	fi

	make_desktop_entry "artcraft-launcher" "ArtCraft Launcher" "ai.storyteller.artcraft-launcher" "Graphics;Utility;"
}

pkg_postinst() {
	xdg_desktop_database_update
	xdg_icon_cache_update
}

pkg_postrm() {
	xdg_desktop_database_update
	xdg_icon_cache_update
}