# Template file for 'Signal-Desktop'
pkgname=Signal-Desktop
version=8.11.0
revision=1
# *-musl could potentially work based on the Alpine port:
# https://git.alpinelinux.org/aports/tree/testing/signal-desktop
archs="x86_64 aarch64"
hostmakedepends="pnpm electron-tasje python3"
depends="cairo gtk+3 libvips pango desktop-file-utils hicolor-icon-theme"
checkdepends="glib nss libgbm alsa-lib ${depends}"
short_desc="Signal Private Messenger for Linux"
maintainer="dkwo <npiazza@disroot.org>"
license="AGPL-3.0-only"
homepage="https://github.com/signalapp/Signal-Desktop"
distfiles="https://github.com/signalapp/Signal-Desktop/archive/v${version}.tar.gz"
checksum=eea21fb713d4c3063b8e3b8b3725bc69d9802c5dfe70fb82fb9b9a930962b6f5
nostrip_files="signal-desktop"
nocross="gyp -> aarch64-linux-gnu-gcc: error: unrecognized command-line option '-m64'"

post_patch() {
	case ${XBPS_TARGET_MACHINE} in
		aarch64*)
			vsed -i 's/xxxtarget/arm64/' package.json
			;;
		x86_64*)
			vsed -i 's/xxxtarget/x64/' package.json
			;;
	esac
}

do_build() {
	# Install dependencies
	pnpm install

	# Build
	pnpm run generate
	pnpm run build
	SIGNAL_ENV=production tasje pack
}

do_check() {
	# fixme: it complains about sandbox/missing files
	# pnpm run test
	:
}

do_install() {
	vmkdir usr/lib/signal-desktop
	vcopy release/linux*-unpacked/* usr/lib/signal-desktop

	vmkdir usr/bin
	ln -s /usr/lib/signal-desktop/signal-desktop ${DESTDIR}/usr/bin/

	vinstall tasje_out/signal.desktop 644 usr/share/applications

	for size in 16 24 32 48 64 128 256 512 1024; do
		vinstall tasje_out/icons/${size}x${size}.png 644 usr/share/icons/hicolor/${size}x${size}/apps signal-desktop.png
	done

	vlicense LICENSE
}
