# Maintainer: Kimiblock Moe
# Contributor: Francesco Masala <mail@francescomasala.me>
# Contributor: lotation <xlapsiu@gmail.com>

pkgname=bottles-bwrap
_pkgname=Bottles
pkgver=64.1
pkgrel=1
epoch=2
pkgdesc='Easily manage wine and proton prefix. Sandboxed by portable.'
arch=(any)
url="https://github.com/bottlesdevs/Bottles"
license=(GPL-3.0-only)
provides+=(bottles)
conflicts+=(bottles)
depends=(
	cabextract
	dconf
	gtk4
	gtksourceview5
	hicolor-icon-theme
	icoextract
	imagemagick
	libadwaita
	libportal-gtk4
	p7zip
	patool
	python
	python-chardet
	python-fvs
	python-gobject
	python-markdown
	python-orjson
	python-pathvalidate
	python-pycurl
	python-requests
	python-steamgriddb
	python-yaml
	python-yara
	webkit2gtk-4.1
	xorg-xdpyinfo
	vkbasalt-cli
	portable
	gamemode
)

optdepends=(
	gvfs
	lib32-gamemode
	lib32-gnutls
	lib32-vkd3d
	lib32-vulkan-icd-loader
	vkd3d
	vulkan-icd-loader
	wine
)
makedepends=(
	blueprint-compiler
	meson
	ninja
	git
	portable-packer
)
source=(
	"Bottles::git+https://github.com/bottlesdevs/Bottles.git#tag=${pkgver}"
	remove-flatpak-checks.patch
	config.toml
	desktop.file
)
sha256sums=('c4193396c10a8903c70953858328e1b54938c81b2fafe523c167e7dc50d41e89'
            '2770f36f98e0a48464a13047a934c92b7eff5a9490a30868b86b90210e97b824'
            'b5e9e7d9b3fe4e47babeed9c96d3bed5bfef4a399f1fe5e6e8395a7d4c30a6f1'
            'ea8e990c57bddaa3079f80d7074a6b7939a96cd0cc37de3003a848408e45313a')

function prepare() {
	patch --forward --directory="${srcdir}/${_pkgname}" --strip=1 --input="${srcdir}/remove-flatpak-checks.patch"
}

build() {
	cd "${srcdir}/${_pkgname}"
	meson setup --prefix='/usr' build
	ninja -C build
}

package() {
	cd "${srcdir}/${_pkgname}"
	DESTDIR="${pkgdir}" ninja -C build install
	install -d "${pkgdir}/usr/lib"
	mv ${pkgdir}/usr/bin/ "${pkgdir}/usr/lib/bottles-bwrap"
	declare -x -g pkgname
	declare -x -g pkgdir
	declare -x -g srcdir
	portable-packer \
		--distro arch \
		--mode post \
		--config-ng "${srcdir}/config.toml" \
		--desktop-file "${srcdir}/desktop.file" \
		--dbus-activation
	ln -srf "${pkgdir}/usr/bin/bottles-bwrap" "${pkgdir}/usr/bin/bottles"
}
