# Template file for 'stremio-shell'
pkgname=stremio-shell
version=4.4.183
revision=1
_serverjs_ver=4.4.172
_singleapplication_hash=aede311d28d20179216c5419b581087be2a8409f
_libmpv_hash=822a41a1087daf2911fc336fbd9509f962158fef
create_wrksrc=yes
build_style=qmake
hostmakedepends="qt5-host-tools qt5-qmake"
makedepends="mpv-devel qt5-webview-devel qt5-webengine-devel
 qt5-declarative-devel qt5-webchannel-devel qt5-location-devel
 qt5-quickcontrols2-devel qt5-quickcontrols chromaprint-devel"
depends="qt5-quickcontrols qt5-quickcontrols2 virtual?nodejs-runtime
 qt5-webengine"
short_desc="Hub for video content aggregation"
maintainer="mobinmob <mobinmob@disroot.org>"
license="GPL-3.0-or-later"
homepage="https://www.stremio.com"
distfiles="https://github.com/Stremio/stremio-shell/archive/v${version}.tar.gz
 https://github.com/itay-grudev/SingleApplication/archive/${_singleapplication_hash}.tar.gz
 https://raw.githubusercontent.com/mpv-player/mpv/v0.32.0/libmpv/qthelper.hpp
 https://dl.strem.io/four/v${_serverjs_ver}/server.js
 https://dl.strem.io/four/v${_serverjs_ver}/stremio.asar"
checksum="7f27d20ae64a3ef80cc528840030d341a8cd5da3da55a80931bb313a12a494f8
 7b8a10a511b329e910ba428626e707576d312f522292acb7ee29d55db22546cc
 86e1fcba6001829b7e23a856db84d01ebc76e63528f74064d7bc5705015a2684
 08d5510a771c3d07a8b1f9c0e521324551d6055b001c5a56c7a79e3e3e0474ef
 a6cb74bd82323ecaa898323c0b710d4297ebad50dd4f2389d84b8426ef6d943a"
skip_extraction="server.js stremio.asar qthelper.hpp"

post_extract() {
	mv stremio-shell-$version/* .
	rmdir deps/singleapplication
	mv SingleApplication-${_singleapplication_hash} deps/singleapplication
	mkdir deps/libmpv/include
	cp -a $XBPS_CROSS_BASE/usr/include/mpv deps/libmpv/include
	cp "${XBPS_SRCDISTDIR}/${pkgname}-${version}/qthelper.hpp" \
		deps/libmpv/include/mpv/
}

post_install() {
	# Fix the bizarre locations
	vmkdir usr/lib/stremio
	mv "${DESTDIR}/usr/opt/stremio/stremio" "${DESTDIR}/usr/lib/stremio"

	# Move .desktop file to proper location
	vmkdir usr/share/applications
	mv "${DESTDIR}/usr/opt/stremio/smartcode-stremio.desktop" "${DESTDIR}/usr/share/applications"

	# Link executable in PATH
	vmkdir usr/bin
	ln -s /usr/lib/stremio/stremio "${DESTDIR}/usr/bin/stremio"

	# Symlink node in the installation directory
	ln -s /usr/bin/node "${DESTDIR}/usr/lib/stremio/node"

	# Install icon
	vmkdir usr/share/icons
	cp "${wrksrc}/images/stremio_window.png" "${DESTDIR}/usr/share/icons/smartcode-stremio.png"

	# Copy server
	cp "${XBPS_SRCDISTDIR}/${pkgname}-${version}/server.js" "${DESTDIR}/usr/lib/stremio"
	cp "${XBPS_SRCDISTDIR}/${pkgname}-${version}/stremio.asar" "${DESTDIR}/usr/lib/stremio"
}
