description="Messaging app with a focus on speed and security, it’s super-fast, simple and free."
url="https://telegram.org/"

packager="spiky <spiky@nutyx.org>"
contributors="Fanch,Fabienwang,Tnut"

makedepends=(xorg-libdrm xorg-libice xorg-libsm xorg-fontconfig freetype libxcb
             xorg-libx11 glib dbus libpng expat xorg-libxau xorg-libxdmcp chrpath)

run=(gtk-update-icon-cache shared-mime-info hicolor-icon-theme desktop-file-utils)

alias=(telegram)

name=telegram-desktop
version=4.6.2

source=(https://github.com/telegramdesktop/tdesktop/releases/download/v${version}/tsetup.$version.tar.xz
       	tg.protocol https://github.com/telegramdesktop/tdesktop/raw/master/Telegram/Resources/art/icon16.png
	https://github.com/telegramdesktop/tdesktop/raw/master/Telegram/Resources/art/icon32.png
	https://github.com/telegramdesktop/tdesktop/raw/master/Telegram/Resources/art/icon48.png
	https://github.com/telegramdesktop/tdesktop/raw/master/Telegram/Resources/art/icon64.png
	https://github.com/telegramdesktop/tdesktop/raw/master/Telegram/Resources/art/icon128.png
	https://github.com/telegramdesktop/tdesktop/raw/master/Telegram/Resources/art/icon256.png
	https://github.com/telegramdesktop/tdesktop/raw/master/Telegram/Resources/art/icon512.png
        telegram-desktop.desktop)

build() {

	# Creating needed directories
	install -dm755 "$PKG/usr/bin"
	install -dm755 "$PKG/usr/share/pixmaps/"
	install -dm755 "$PKG/usr/share/applications/"

	# Program
	install -Dm755 Telegram/Telegram "$PKG/usr/bin/telegram-desktop"

	# Remove RPATH informations
	chrpath --delete "$PKG/usr/bin/telegram-desktop"

	# Desktop launcher
	install -Dm644 icon256.png "$PKG/usr/share/pixmaps/telegram.png"
	install -Dm644 $name.desktop "$PKG/usr/share/applications/telegramdesktop.desktop"


	# Icons
	local icon_size icon_dir
	for icon_size in 16 32 48 64 128 256 512; do
		icon_dir="$PKG/usr/share/icons/hicolor/${icon_size}x${icon_size}/apps"
		install -d "$icon_dir"
		install -m644 "$SRC/icon${icon_size}.png" "$icon_dir/telegram.png"
	done
} 
