Skip to content

Commit 2dfe858

Browse files
ilya-fedinjohn-preston
authored andcommitted
Support D-Bus activation
1 parent 0421e41 commit 2dfe858

File tree

4 files changed

+55
-0
lines changed

4 files changed

+55
-0
lines changed

Telegram/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1730,5 +1730,6 @@ if (LINUX AND DESKTOP_APP_USE_PACKAGED)
17301730
install(FILES "Resources/art/icon256.png" DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/icons/hicolor/256x256/apps" RENAME "telegram.png")
17311731
install(FILES "Resources/art/icon512.png" DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/icons/hicolor/512x512/apps" RENAME "telegram.png")
17321732
install(FILES "../lib/xdg/org.telegram.desktop.desktop" DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/applications")
1733+
install(FILES "../lib/xdg/org.telegram.desktop.service" DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/dbus-1/services")
17331734
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/org.telegram.desktop.metainfo.xml" DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/metainfo")
17341735
endif()

Telegram/SourceFiles/platform/linux/specific_linux.cpp

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,55 @@ bool GenerateDesktopFile(
322322
return true;
323323
}
324324

325+
bool GenerateServiceFile(bool silent = false) {
326+
const auto executable = ExecutablePathForShortcuts();
327+
if (executable.isEmpty()) {
328+
return false;
329+
}
330+
331+
const auto targetPath = QStandardPaths::writableLocation(
332+
QStandardPaths::GenericDataLocation) + u"/dbus-1/services/"_q;
333+
334+
const auto targetFile = targetPath
335+
+ QGuiApplication::desktopFileName().chopped(8)
336+
+ u".service"_q;
337+
338+
DEBUG_LOG(("App Info: placing .service file to %1").arg(targetPath));
339+
if (!QDir(targetPath).exists()) QDir().mkpath(targetPath);
340+
341+
const auto target = Glib::KeyFile::create();
342+
constexpr auto group = "D-BUS Service";
343+
344+
target->set_string(
345+
group,
346+
"Name",
347+
QGuiApplication::desktopFileName().chopped(8).toStdString());
348+
349+
target->set_string(
350+
group,
351+
"Exec",
352+
KShell::joinArgs({ executable }).replace(
353+
'\\',
354+
qstr("\\\\")).toStdString());
355+
356+
try {
357+
target->save_to_file(targetFile.toStdString());
358+
} catch (const std::exception &e) {
359+
if (!silent) {
360+
LOG(("App Error: %1").arg(QString::fromStdString(e.what())));
361+
}
362+
return false;
363+
}
364+
365+
QProcess::execute(u"systemctl"_q, {
366+
u"--user"_q,
367+
u"reload"_q,
368+
u"dbus"_q,
369+
});
370+
371+
return true;
372+
}
373+
325374
void InstallLauncher() {
326375
static const auto DisabledByEnv = !qEnvironmentVariableIsEmpty(
327376
"DESKTOPINTEGRATION");
@@ -335,6 +384,7 @@ void InstallLauncher() {
335384
QStandardPaths::ApplicationsLocation) + '/';
336385

337386
GenerateDesktopFile(applicationsPath);
387+
GenerateServiceFile();
338388

339389
const auto icons = QStandardPaths::writableLocation(
340390
QStandardPaths::GenericDataLocation) + u"/icons/"_q;

lib/xdg/org.telegram.desktop.desktop

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Categories=Chat;Network;InstantMessaging;Qt;
1111
MimeType=x-scheme-handler/tg;
1212
Keywords=tg;chat;im;messaging;messenger;sms;tdesktop;
1313
Actions=quit;
14+
DBusActivatable=true
1415
SingleMainWindow=true
1516
X-GNOME-UsesNotifications=true
1617
X-GNOME-SingleWindow=true

lib/xdg/org.telegram.desktop.service

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[D-BUS Service]
2+
Name=org.telegram.desktop
3+
Exec=telegram-desktop

0 commit comments

Comments
 (0)