2
0
mirror of https://github.com/telegramdesktop/tdesktop synced 2025-08-31 22:46:10 +00:00

Minimize dbus requests

This commit is contained in:
Ilya Fedin
2020-03-10 12:36:06 +04:00
committed by John Preston
parent afc902a5cb
commit ba5d9eda2d
2 changed files with 63 additions and 12 deletions

View File

@@ -359,6 +359,12 @@ std::optional<crl::time> LastUserInputTime() {
// TODO: a fallback pure-X11 implementation, this one covers only major DEs on X11 and Wayland
// an example: https://stackoverflow.com/q/9049087
#ifndef TDESKTOP_DISABLE_DBUS_INTEGRATION
static auto NotSupported = false;
if (NotSupported) {
return std::nullopt;
}
static const auto message = QDBusMessage::createMethodCall(
qsl("org.freedesktop.ScreenSaver"),
qsl("/org/freedesktop/ScreenSaver"),
@@ -368,10 +374,20 @@ std::optional<crl::time> LastUserInputTime() {
const QDBusReply<uint> reply = QDBusConnection::sessionBus().call(
message);
constexpr auto notSupportedErrors = {
QDBusError::ServiceUnknown,
QDBusError::NotSupported,
};
if (reply.isValid()) {
return (crl::now() - static_cast<crl::time>(reply.value()));
} else if (reply.error().type() != QDBusError::ServiceUnknown
&& reply.error().type() != QDBusError::NotSupported) {
} else if (ranges::contains(notSupportedErrors, reply.error().type())) {
NotSupported = true;
} else {
if (reply.error().type() == QDBusError::AccessDenied) {
NotSupported = true;
}
LOG(("Unable to get last user input time: %1: %2")
.arg(reply.error().name())
.arg(reply.error().message()));