From d77df9905f9ccbb32ffaddcc7fddee0c95060296 Mon Sep 17 00:00:00 2001 From: Ilya Fedin Date: Mon, 1 Mar 2021 22:40:09 +0400 Subject: [PATCH] Move NotificationServiceWatcher to glibmm --- .../linux_notification_service_watcher.cpp | 60 ++++++++++++------- .../linux_notification_service_watcher.h | 6 +- 2 files changed, 42 insertions(+), 24 deletions(-) diff --git a/Telegram/SourceFiles/platform/linux/linux_notification_service_watcher.cpp b/Telegram/SourceFiles/platform/linux/linux_notification_service_watcher.cpp index ae7953bc6f..8c5223b560 100644 --- a/Telegram/SourceFiles/platform/linux/linux_notification_service_watcher.cpp +++ b/Telegram/SourceFiles/platform/linux/linux_notification_service_watcher.cpp @@ -10,9 +10,11 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "core/application.h" #include "main/main_domain.h" #include "window/notifications_manager.h" +#include "base/platform/linux/base_linux_glibmm_helper.h" #include "base/platform/linux/base_linux_dbus_utilities.h" -#include +#include +#include namespace Platform { namespace internal { @@ -40,27 +42,43 @@ bool IsNotificationServiceActivatable() { } // namespace -NotificationServiceWatcher::NotificationServiceWatcher() -: _dbusWatcher( - kNotificationService.utf16(), - QDBusConnection::sessionBus(), - QDBusServiceWatcher::WatchForOwnerChange) { - const auto signal = &QDBusServiceWatcher::serviceOwnerChanged; - QObject::connect(&_dbusWatcher, signal, [=]( - const QString &service, - const QString &oldOwner, - const QString &newOwner) { - crl::on_main([=] { - if (!Core::App().domain().started()) { - return; - } else if (IsNotificationServiceActivatable() - && newOwner.isEmpty()) { - return; - } +class NotificationServiceWatcher::Private { +public: + Glib::RefPtr dbusConnection; + uint signalId = 0; +}; - Core::App().notifications().createManager(); - }); - }); +NotificationServiceWatcher::NotificationServiceWatcher() +: _private(std::make_unique()) { + try { + _private->dbusConnection = Gio::DBus::Connection::get_sync( + Gio::DBus::BusType::BUS_TYPE_SESSION); + + _private->signalId = base::Platform::DBus::RegisterServiceWatcher( + _private->dbusConnection, + std::string(kNotificationService), + []( + const Glib::ustring &service, + const Glib::ustring &oldOwner, + const Glib::ustring &newOwner) { + if (!Core::App().domain().started() + || (IsNotificationServiceActivatable() + && newOwner.empty())) { + return; + } + + crl::on_main([] { + Core::App().notifications().createManager(); + }); + }); + } catch (...) { + } +} + +NotificationServiceWatcher::~NotificationServiceWatcher() { + if (_private->dbusConnection && _private->signalId != 0) { + _private->dbusConnection->signal_unsubscribe(_private->signalId); + } } } // namespace internal diff --git a/Telegram/SourceFiles/platform/linux/linux_notification_service_watcher.h b/Telegram/SourceFiles/platform/linux/linux_notification_service_watcher.h index 50295d0892..034b49c7be 100644 --- a/Telegram/SourceFiles/platform/linux/linux_notification_service_watcher.h +++ b/Telegram/SourceFiles/platform/linux/linux_notification_service_watcher.h @@ -7,17 +7,17 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #pragma once -#include - namespace Platform { namespace internal { class NotificationServiceWatcher { public: NotificationServiceWatcher(); + ~NotificationServiceWatcher(); private: - QDBusServiceWatcher _dbusWatcher; + class Private; + const std::unique_ptr _private; }; } // namespace internal