From 88a165d6761c4289c40ea8363d42822826589041 Mon Sep 17 00:00:00 2001
From: Avimitin <dev@avimit.in>
Date: Mon, 24 Jul 2023 16:53:09 +0800
Subject: [PATCH] Use absolute executable path for dbus service

After the v4.8.7 release, I cannot launch telegram desktop because of the
recent dbus support introduced in
https://github.com/telegramdesktop/tdesktop/commit/2dfe85832717ccfd9268a5b767f03eb4e8665b8f.
And it was fixed after I changed the value of the Exec field to absolute
path to the telegram-desktop executable.

In dbus specification they don't mention that they will find
executable from PATH variable, so this is a UB.
After this commit, cmake will use the full install path to generate the correct service file
and fix the above issue.

Signed-off-by: Avimitin <dev@avimit.in>
---
 Telegram/CMakeLists.txt              | 3 ++-
 lib/xdg/org.telegram.desktop.service | 2 +-
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/Telegram/CMakeLists.txt b/Telegram/CMakeLists.txt
index 329e16226..8fb9e62d1 100644
--- a/Telegram/CMakeLists.txt
+++ b/Telegram/CMakeLists.txt
@@ -1758,6 +1758,7 @@ endif()
 
 if (LINUX AND DESKTOP_APP_USE_PACKAGED)
     include(GNUInstallDirs)
+    configure_file("../lib/xdg/org.telegram.desktop.service" "${CMAKE_CURRENT_BINARY_DIR}/org.telegram.desktop.service" @ONLY)
     configure_file("../lib/xdg/org.telegram.desktop.metainfo.xml" "${CMAKE_CURRENT_BINARY_DIR}/org.telegram.desktop.metainfo.xml" @ONLY)
     generate_appdata_changelog(Telegram "${CMAKE_SOURCE_DIR}/changelog.txt" "${CMAKE_CURRENT_BINARY_DIR}/org.telegram.desktop.metainfo.xml")
     install(TARGETS Telegram RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" BUNDLE DESTINATION "${CMAKE_INSTALL_BINDIR}")
@@ -1769,6 +1770,6 @@ if (LINUX AND DESKTOP_APP_USE_PACKAGED)
     install(FILES "Resources/art/icon256.png" DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/icons/hicolor/256x256/apps" RENAME "telegram.png")
     install(FILES "Resources/art/icon512.png" DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/icons/hicolor/512x512/apps" RENAME "telegram.png")
     install(FILES "../lib/xdg/org.telegram.desktop.desktop" DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/applications")
-    install(FILES "../lib/xdg/org.telegram.desktop.service" DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/dbus-1/services")
+    install(FILES "${CMAKE_CURRENT_BINARY_DIR}/org.telegram.desktop.service" DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/dbus-1/services")
     install(FILES "${CMAKE_CURRENT_BINARY_DIR}/org.telegram.desktop.metainfo.xml" DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/metainfo")
 endif()
diff --git a/lib/xdg/org.telegram.desktop.service b/lib/xdg/org.telegram.desktop.service
index 0f9caabbc..525cac208 100644
--- a/lib/xdg/org.telegram.desktop.service
+++ b/lib/xdg/org.telegram.desktop.service
@@ -1,3 +1,3 @@
 [D-BUS Service]
 Name=org.telegram.desktop
-Exec=telegram-desktop
+Exec=@CMAKE_INSTALL_FULL_BINDIR@/telegram-desktop