From b4d310fd1efa9c489b354eba3bbdcfb15bed5bcf Mon Sep 17 00:00:00 2001 From: Ilya Fedin Date: Sat, 12 Nov 2022 06:32:43 +0400 Subject: [PATCH] Don't subscribe to inhibiton changes when not supported --- .../linux/notifications_manager_linux.cpp | 81 +++++++++---------- 1 file changed, 39 insertions(+), 42 deletions(-) diff --git a/Telegram/SourceFiles/platform/linux/notifications_manager_linux.cpp b/Telegram/SourceFiles/platform/linux/notifications_manager_linux.cpp index 6dce4c719..609929152 100644 --- a/Telegram/SourceFiles/platform/linux/notifications_manager_linux.cpp +++ b/Telegram/SourceFiles/platform/linux/notifications_manager_linux.cpp @@ -258,11 +258,6 @@ void GetCapabilities(Fn callback) { } void GetInhibited(Fn callback) { - if (!CurrentCapabilities.contains(qsl("inhibitions"))) { - crl::on_main([=] { callback(false); }); - return; - } - Noexcept([&] { const auto connection = Gio::DBus::Connection::get_sync( Gio::DBus::BusType::SESSION); @@ -947,50 +942,52 @@ Manager::Private::Private(not_null manager, Type type) .arg(capabilities.join(", "))); } - Noexcept([&] { - _dbusConnection = Gio::DBus::Connection::get_sync( - Gio::DBus::BusType::SESSION); - }); + if (capabilities.contains(qsl("inhibitions"))) { + Noexcept([&] { + _dbusConnection = Gio::DBus::Connection::get_sync( + Gio::DBus::BusType::SESSION); + }); - if (!_dbusConnection) { - return; - } + if (!_dbusConnection) { + return; + } - const auto weak = base::make_weak(this); - GetInhibited(crl::guard(weak, [=](bool result) { - _inhibited = result; - })); + const auto weak = base::make_weak(this); + GetInhibited(crl::guard(weak, [=](bool result) { + _inhibited = result; + })); - _inhibitedSignalId = _dbusConnection->signal_subscribe( - [=]( - const Glib::RefPtr &connection, - const Glib::ustring &sender_name, - const Glib::ustring &object_path, - const Glib::ustring &interface_name, - const Glib::ustring &signal_name, - Glib::VariantContainerBase parameters) { - Noexcept([&] { - const auto interface = GlibVariantCast( - parameters.get_child(0)); + _inhibitedSignalId = _dbusConnection->signal_subscribe( + [=]( + const Glib::RefPtr &connection, + const Glib::ustring &sender_name, + const Glib::ustring &object_path, + const Glib::ustring &interface_name, + const Glib::ustring &signal_name, + Glib::VariantContainerBase parameters) { + Noexcept([&] { + const auto interface = GlibVariantCast( + parameters.get_child(0)); - if (interface != kInterface.data()) { - return; - } + if (interface != kInterface.data()) { + return; + } - const auto inhibited = GlibVariantCast( - GlibVariantCast< - std::map - >(parameters.get_child(1)).at("Inhibited")); + const auto inhibited = GlibVariantCast( + GlibVariantCast< + std::map + >(parameters.get_child(1)).at("Inhibited")); - crl::on_main(weak, [=] { - _inhibited = inhibited; + crl::on_main(weak, [=] { + _inhibited = inhibited; + }); }); - }); - }, - std::string(kService), - std::string(kPropertiesInterface), - "PropertiesChanged", - std::string(kObjectPath)); + }, + std::string(kService), + std::string(kPropertiesInterface), + "PropertiesChanged", + std::string(kObjectPath)); + } } void Manager::Private::showNotification(