Skip to content

Commit

Permalink
Fix 30s hang in case ibus portal couldn't be started
Browse files Browse the repository at this point in the history
  • Loading branch information
ilya-fedin authored and john-preston committed Nov 12, 2020
1 parent 8b0fcee commit 21133ab
Showing 1 changed file with 39 additions and 3 deletions.
42 changes: 39 additions & 3 deletions Telegram/SourceFiles/platform/linux/specific_linux.cpp
Expand Up @@ -38,6 +38,7 @@ For license and copyright information please follow this link:
#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION
#include <QtDBus/QDBusInterface>
#include <QtDBus/QDBusConnection>
#include <QtDBus/QDBusConnectionInterface>
#include <QtDBus/QDBusMessage>
#include <QtDBus/QDBusReply>
#include <QtDBus/QDBusError>
Expand Down Expand Up @@ -90,6 +91,31 @@ constexpr auto kXCBFrameExtentsAtomName = "_GTK_FRAME_EXTENTS"_cs;
QStringList PlatformThemes;

#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION
QStringList ListDBusActivatableNames() {
static const auto Result = [&] {
const auto message = QDBusMessage::createMethodCall(
qsl("org.freedesktop.DBus"),
qsl("/org/freedesktop/DBus"),
qsl("org.freedesktop.DBus"),
qsl("ListActivatableNames"));

const QDBusReply<QStringList> reply = QDBusConnection::sessionBus()
.call(message);

if (reply.isValid()) {
return reply.value();
} else {
LOG(("App Error: %1: %2")
.arg(reply.error().name())
.arg(reply.error().message()));
}

return QStringList{};
}();

return Result;
}

void PortalAutostart(bool autostart, bool silent = false) {
if (cExeName().isEmpty()) {
return;
Expand Down Expand Up @@ -155,9 +181,19 @@ bool IsXDGDesktopPortalKDEPresent() {
}

bool IsIBusPortalPresent() {
static const auto Result = QDBusInterface(
qsl("org.freedesktop.portal.IBus"),
qsl("/org/freedesktop/IBus")).isValid();
static const auto Result = [&] {
const auto interface = QDBusConnection::sessionBus().interface();
const auto activatableNames = ListDBusActivatableNames();

const auto serviceRegistered = interface
&& interface->isServiceRegistered(
qsl("org.freedesktop.portal.IBus"));

const auto serviceActivatable = activatableNames.contains(
qsl("org.freedesktop.portal.IBus"));

return serviceRegistered || serviceActivatable;
}();

return Result;
}
Expand Down

0 comments on commit 21133ab

Please sign in to comment.