Support D-Bus activation
This commit is contained in:
parent
0421e41c47
commit
2dfe858327
4 changed files with 55 additions and 0 deletions
|
@ -1730,5 +1730,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/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 "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.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.metainfo.xml" DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/metainfo")
|
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/org.telegram.desktop.metainfo.xml" DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/metainfo")
|
||||||
endif()
|
endif()
|
||||||
|
|
|
@ -322,6 +322,55 @@ bool GenerateDesktopFile(
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool GenerateServiceFile(bool silent = false) {
|
||||||
|
const auto executable = ExecutablePathForShortcuts();
|
||||||
|
if (executable.isEmpty()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto targetPath = QStandardPaths::writableLocation(
|
||||||
|
QStandardPaths::GenericDataLocation) + u"/dbus-1/services/"_q;
|
||||||
|
|
||||||
|
const auto targetFile = targetPath
|
||||||
|
+ QGuiApplication::desktopFileName().chopped(8)
|
||||||
|
+ u".service"_q;
|
||||||
|
|
||||||
|
DEBUG_LOG(("App Info: placing .service file to %1").arg(targetPath));
|
||||||
|
if (!QDir(targetPath).exists()) QDir().mkpath(targetPath);
|
||||||
|
|
||||||
|
const auto target = Glib::KeyFile::create();
|
||||||
|
constexpr auto group = "D-BUS Service";
|
||||||
|
|
||||||
|
target->set_string(
|
||||||
|
group,
|
||||||
|
"Name",
|
||||||
|
QGuiApplication::desktopFileName().chopped(8).toStdString());
|
||||||
|
|
||||||
|
target->set_string(
|
||||||
|
group,
|
||||||
|
"Exec",
|
||||||
|
KShell::joinArgs({ executable }).replace(
|
||||||
|
'\\',
|
||||||
|
qstr("\\\\")).toStdString());
|
||||||
|
|
||||||
|
try {
|
||||||
|
target->save_to_file(targetFile.toStdString());
|
||||||
|
} catch (const std::exception &e) {
|
||||||
|
if (!silent) {
|
||||||
|
LOG(("App Error: %1").arg(QString::fromStdString(e.what())));
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
QProcess::execute(u"systemctl"_q, {
|
||||||
|
u"--user"_q,
|
||||||
|
u"reload"_q,
|
||||||
|
u"dbus"_q,
|
||||||
|
});
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
void InstallLauncher() {
|
void InstallLauncher() {
|
||||||
static const auto DisabledByEnv = !qEnvironmentVariableIsEmpty(
|
static const auto DisabledByEnv = !qEnvironmentVariableIsEmpty(
|
||||||
"DESKTOPINTEGRATION");
|
"DESKTOPINTEGRATION");
|
||||||
|
@ -335,6 +384,7 @@ void InstallLauncher() {
|
||||||
QStandardPaths::ApplicationsLocation) + '/';
|
QStandardPaths::ApplicationsLocation) + '/';
|
||||||
|
|
||||||
GenerateDesktopFile(applicationsPath);
|
GenerateDesktopFile(applicationsPath);
|
||||||
|
GenerateServiceFile();
|
||||||
|
|
||||||
const auto icons = QStandardPaths::writableLocation(
|
const auto icons = QStandardPaths::writableLocation(
|
||||||
QStandardPaths::GenericDataLocation) + u"/icons/"_q;
|
QStandardPaths::GenericDataLocation) + u"/icons/"_q;
|
||||||
|
|
|
@ -11,6 +11,7 @@ Categories=Chat;Network;InstantMessaging;Qt;
|
||||||
MimeType=x-scheme-handler/tg;
|
MimeType=x-scheme-handler/tg;
|
||||||
Keywords=tg;chat;im;messaging;messenger;sms;tdesktop;
|
Keywords=tg;chat;im;messaging;messenger;sms;tdesktop;
|
||||||
Actions=quit;
|
Actions=quit;
|
||||||
|
DBusActivatable=true
|
||||||
SingleMainWindow=true
|
SingleMainWindow=true
|
||||||
X-GNOME-UsesNotifications=true
|
X-GNOME-UsesNotifications=true
|
||||||
X-GNOME-SingleWindow=true
|
X-GNOME-SingleWindow=true
|
||||||
|
|
3
lib/xdg/org.telegram.desktop.service
Normal file
3
lib/xdg/org.telegram.desktop.service
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
[D-BUS Service]
|
||||||
|
Name=org.telegram.desktop
|
||||||
|
Exec=telegram-desktop
|
Loading…
Reference in a new issue