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

EAPI=8

inherit desktop wrapper xdg

DESCRIPTION="High-Fidelity Web Archiving"
HOMEPAGE="https://archiveweb.page/"
SRC_URI="
	https://github.com/webrecorder/archiveweb.page/releases/download/v${PV}/ArchiveWeb.page-${PV}.AppImage
"

# or-later unknown
LICENSE="AGPL-3"
# from LICENSE files inside the appimages
# only electron included
LICENSE+=" MIT"
# TODO: Alliance for Open Media Patent License 1.0
# TODO: Almost Native Graphics Layer Engine
# TODO: SunPro, sun microsystems
# then i stopped cause too many
#
# taken from chromium-151.0.7922.169-r1.ebuild
# https://gitweb.gentoo.org/proj/chromium-tools.git/tree/get-chromium-licences.py @ 145.0.7632.76
LICENSE+=" Apache-2.0 Apache-2.0-with-LLVM-exceptions BSD BSD-2 Base64 Boost-1.0 CC-BY-3.0 CC-BY-4.0 Clear-BSD FFT2D FTL"
LICENSE+=" IJG ISC LGPL-2 LGPL-2.1 MIT MPL-1.1 MPL-2.0 Ms-PL PSF-2 SGI-B-2.0 SSLeay SunSoft Unicode-3.0"
LICENSE+=" Unicode-DFS-2015 Unlicense UoI-NCSA ZLIB libtiff openssl"

SLOT="0"
KEYWORDS="-* ~amd64"
RESTRICT="binchecks"

#DEPEND=""
# there's a yesno function in the AppRun but i'm not sure if it's ever used?
RDEPEND="
	|| (
		gnome-extra/zenity
		kde-apps/kdialog
		x11-misc/xdialog
	)
"
#BDEPEND=""

# random variables for ebuild
OPTDEST="opt/${P}/"

src_unpack() {
	filename="ArchiveWeb.page-${PV}.AppImage"
	cp "$DISTDIR"/"$filename" "${WORKDIR}" || die "copy failed"
	chmod +x "$filename" || die "couldn't make appimagte executable"
	./"$filename" --appimage-extract || die "couldn't extract appimage"
	mv "$WORKDIR/squashfs-root/" "${S}" || die
}

src_compile() {
	sed -i "s~^Exec=~Exec=/${OPTDEST}~g" ArchiveWeb.page.desktop || die
	# duplicate files
	rm ArchiveWeb.page.png || die
}

src_install() {
	domenu "${S}/ArchiveWeb.page.desktop"
	# wrapper, since AppRun self-detects its own path to derive some stuff,
	# so don't cp/dobin that
	make_wrapper "ArchiveWeb.page" "/opt/${P}/AppRun"

	insinto /opt/
	doins -r "${S}"

	fperms 0755 "opt/${P}/AppRun" || die
	fperms 0755 "opt/${P}/ArchiveWeb.page" || die

	doicon -s 512 ./usr/share/icons/hicolor/512x512/apps/ArchiveWeb.page.png
}