name='vk-messenger'
version='6.0.57'
release=1
summary='VK Messenger client'
summary_ru='Официальный клиент VK Messenger'
group='Networking/Instant messaging'
desc='VK Messenger is the official VK instant messaging client, distributed as an Electron desktop application directly from vk.me.'
desc_ru='VK Messenger — официальный клиент мессенджера VK, распространяемый в виде Electron-приложения напрямую с vk.me.'
homepage='https://vk.me/app'
maintainer='VK Support <support@vk.com>'

architectures=('amd64')

license=('Custom')
nonfree=1
nonfree_msg='VK Messenger является проприетарным приложением VK. Использование мессенджера, учетной записи VK ID и сетевых функций регулируется условиями VK.'
nonfree_url='https://vk.com/terms'

provides=()
replaces=('vk-messenger')
conflicts=()

auto_reqprov_method="dirty"
auto_req=0
auto_prov=0

deps=()
deps_debian=('libc6' 'libglib2.0-0t64 | libglib2.0-0' 'libgtk-3-0t64 | libgtk-3-0' 'libnotify4' 'libnss3' 'libxss1' 'libxtst6' 'xdg-utils' 'libatspi2.0-0' 'libuuid1' 'libsecret-1-0' 'libasound2t64 | libasound2 | pulseaudio' 'libgbm1' 'libdrm2' 'pulseaudio | pulseaudio-utils | pipewire-pulse')
deps_ubuntu=("${deps_debian[@]}")
deps_fedora=('glibc' 'glib2' 'gtk3' 'libnotify' 'nss' 'libXScrnSaver' 'libXtst' 'xdg-utils' 'at-spi2-core' 'libuuid' 'libsecret' 'alsa-lib' 'mesa-libgbm' 'libdrm' 'pulseaudio-utils')
deps_arch=('glibc' 'glib2' 'gtk3' 'libnotify' 'nss' 'libxss' 'libxtst' 'xdg-utils' 'at-spi2-core' 'libutil-linux' 'libsecret' 'alsa-lib' 'libgbm' 'libdrm' 'libpulse')
deps_opensuse=('glibc' 'libglib-2_0-0' 'gtk3' 'libnotify4' 'mozilla-nss' 'libXss1' 'libXtst6' 'xdg-utils' 'at-spi2-core' 'libuuid1' 'libsecret-1-0' 'libasound2' 'libgbm1' 'libdrm2' 'pulseaudio-utils')
deps_altlinux=('glibc' 'glib2' 'libgtk+3' 'libnotify' 'libnss' 'libXScrnSaver' 'libXtst' 'xdg-utils' 'libat-spi2-core' 'libuuid' 'libsecret' 'libalsa' 'libgbm' 'libdrm' 'pulseaudio-utils')

opt_deps=()
opt_deps_debian=('libayatana-appindicator3-1 | libappindicator3-1')
opt_deps_ubuntu=("${opt_deps_debian[@]}")
opt_deps_fedora=('libappindicator-gtk3')
opt_deps_arch=('libappindicator-gtk3')
opt_deps_opensuse=('libappindicator3-1')
opt_deps_altlinux=('libappindicator-gtk3')

build_deps=('binutils')

sources=(
	"https://upload.object2.vk-apps.com/vk-me-desktop-dev-5837a06d-5f28-484a-ac22-045903cb1b1a/latest/vk-messenger.deb?~archive=false&~name=vk-messenger.deb"
	'local:///LICENSE'
)

checksums=(
	'sha256:cb4fa7a8fb3c6af5c432696e4653751393c9c5c655b6bf0e2d944ff7483ec784'
	'sha256:ab672f11775fc2a579a2001bef3c8b75d78159a67e004dd55339befe98f9e232'
)

scripts=(
	['postinstall']='postinstall.sh'
	['postremove']='postremove.sh'
)

package() {
	cd "${srcdir}"

	mkdir -p "${srcdir}/extracted"
	ar x vk-messenger.deb
	tar -xf data.tar.* -C "${srcdir}/extracted"

	# Upstream's own installer uses the literal (Cyrillic, spaced) product name
	# as the /opt directory, not a clean slug — find it rather than hardcode it.
	opt_src="$(find "${srcdir}/extracted/opt" -mindepth 1 -maxdepth 1 -type d | head -1)"
	[[ -n "$opt_src" ]] || { echo "не найден каталог /opt/* внутри vk-messenger.deb" >&2; exit 1; }

	install -dm755 "${pkgdir}/opt/vk-messenger"
	cp -a "${opt_src}/." "${pkgdir}/opt/vk-messenger/"
	chmod 0755 "${pkgdir}/opt/vk-messenger/chrome-sandbox"

	install -dm755 "${pkgdir}/usr/bin"
	ln -sfn /opt/vk-messenger/vk-messenger "${pkgdir}/usr/bin/vk-messenger"

	install -Dm644 "${srcdir}/extracted/usr/share/applications/vk-messenger.desktop" \
		"${pkgdir}/usr/share/applications/vk-messenger.desktop"

	for icon in "${srcdir}"/extracted/usr/share/icons/hicolor/*/apps/vk-messenger.*; do
		size="$(basename "$(dirname "$(dirname "$icon")")")"
		install -Dm644 "$icon" \
			"${pkgdir}/usr/share/icons/hicolor/${size}/apps/$(basename "$icon")"
	done

	install-license "${srcdir}/LICENSE" "vk-messenger/LICENSE.nivora"
	install -Dm644 "${opt_src}/LICENSE.electron.txt" \
		"${pkgdir}/usr/share/licenses/vk-messenger/LICENSE.electron.txt"
	install -Dm644 "${opt_src}/LICENSES.chromium.html" \
		"${pkgdir}/usr/share/licenses/vk-messenger/LICENSES.chromium.html"
}

files() {
	files-find-binary
	files-find-desktop
	files-find-license
	files-find \
		"/opt/vk-messenger/**/*" \
		"/usr/share/icons/hicolor/*/apps/vk-messenger.*"
}
