Move NotificationServiceWatcher to glibmm

This commit is contained in:
Ilya Fedin 2021-03-01 22:40:09 +04:00 committed by John Preston
parent 82f92cffd3
commit d77df9905f
2 changed files with 42 additions and 24 deletions

View file

@ -10,9 +10,11 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "core/application.h" #include "core/application.h"
#include "main/main_domain.h" #include "main/main_domain.h"
#include "window/notifications_manager.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 "base/platform/linux/base_linux_dbus_utilities.h"
#include <QtDBus/QDBusConnection> #include <glibmm.h>
#include <giomm.h>
namespace Platform { namespace Platform {
namespace internal { namespace internal {
@ -40,27 +42,43 @@ bool IsNotificationServiceActivatable() {
} // namespace } // namespace
class NotificationServiceWatcher::Private {
public:
Glib::RefPtr<Gio::DBus::Connection> dbusConnection;
uint signalId = 0;
};
NotificationServiceWatcher::NotificationServiceWatcher() NotificationServiceWatcher::NotificationServiceWatcher()
: _dbusWatcher( : _private(std::make_unique<Private>()) {
kNotificationService.utf16(), try {
QDBusConnection::sessionBus(), _private->dbusConnection = Gio::DBus::Connection::get_sync(
QDBusServiceWatcher::WatchForOwnerChange) { Gio::DBus::BusType::BUS_TYPE_SESSION);
const auto signal = &QDBusServiceWatcher::serviceOwnerChanged;
QObject::connect(&_dbusWatcher, signal, [=]( _private->signalId = base::Platform::DBus::RegisterServiceWatcher(
const QString &service, _private->dbusConnection,
const QString &oldOwner, std::string(kNotificationService),
const QString &newOwner) { [](
crl::on_main([=] { const Glib::ustring &service,
if (!Core::App().domain().started()) { const Glib::ustring &oldOwner,
return; const Glib::ustring &newOwner) {
} else if (IsNotificationServiceActivatable() if (!Core::App().domain().started()
&& newOwner.isEmpty()) { || (IsNotificationServiceActivatable()
&& newOwner.empty())) {
return; return;
} }
crl::on_main([] {
Core::App().notifications().createManager(); Core::App().notifications().createManager();
}); });
}); });
} catch (...) {
}
}
NotificationServiceWatcher::~NotificationServiceWatcher() {
if (_private->dbusConnection && _private->signalId != 0) {
_private->dbusConnection->signal_unsubscribe(_private->signalId);
}
} }
} // namespace internal } // namespace internal

View file

@ -7,17 +7,17 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/ */
#pragma once #pragma once
#include <QtDBus/QDBusServiceWatcher>
namespace Platform { namespace Platform {
namespace internal { namespace internal {
class NotificationServiceWatcher { class NotificationServiceWatcher {
public: public:
NotificationServiceWatcher(); NotificationServiceWatcher();
~NotificationServiceWatcher();
private: private:
QDBusServiceWatcher _dbusWatcher; class Private;
const std::unique_ptr<Private> _private;
}; };
} // namespace internal } // namespace internal