diff --git a/src/dbus/properties.cpp b/src/dbus/properties.cpp index 1a40ca23..6156b2a3 100644 --- a/src/dbus/properties.cpp +++ b/src/dbus/properties.cpp @@ -268,14 +268,15 @@ void DBusPropertyGroup::updateAllViaGetAll() { qCWarning(logDbusProperties).noquote() << "Error updating properties of" << this->toString() << "via GetAll"; qCWarning(logDbusProperties) << reply.error(); + emit this->getAllFailed(reply.error()); } else { qCDebug(logDbusProperties).noquote() << "Received GetAll property set for" << this->toString(); this->updatePropertySet(reply.value(), true); + emit this->getAllFinished(); } delete call; - emit this->getAllFinished(); }; QObject::connect(call, &QDBusPendingCallWatcher::finished, this, responseCallback); diff --git a/src/dbus/properties.hpp b/src/dbus/properties.hpp index e24d23fb..65f51afc 100644 --- a/src/dbus/properties.hpp +++ b/src/dbus/properties.hpp @@ -135,6 +135,7 @@ public: signals: void getAllFinished(); + void getAllFailed(QDBusError error); private slots: void onPropertiesChanged( diff --git a/src/services/status_notifier/item.cpp b/src/services/status_notifier/item.cpp index 7f990a9f..f6e16a24 100644 --- a/src/services/status_notifier/item.cpp +++ b/src/services/status_notifier/item.cpp @@ -26,6 +26,7 @@ #include "dbus_item.h" #include "dbus_item_types.hpp" #include "host.hpp" +#include "watcher.hpp" using namespace qs::dbus; using namespace qs::dbus::dbusmenu; @@ -76,6 +77,7 @@ StatusNotifierItem::StatusNotifierItem(const QString& address, QObject* parent) QObject::connect(&this->overlayIconPixmaps, &AbstractDBusProperty::changed, this, &StatusNotifierItem::updateIcon); QObject::connect(&this->properties, &DBusPropertyGroup::getAllFinished, this, &StatusNotifierItem::onGetAllFinished); + QObject::connect(&this->properties, &DBusPropertyGroup::getAllFailed, this, &StatusNotifierItem::onGetAllFailed); QObject::connect(&this->menuPath, &AbstractDBusProperty::changed, this, &StatusNotifierItem::onMenuPathChanged); // clang-format on @@ -246,6 +248,19 @@ void StatusNotifierItem::onGetAllFinished() { emit this->ready(); } +void StatusNotifierItem::onGetAllFailed() { + // Not changing the item to ready, as it is almost definitely broken. + if (!this->mReady) { + qWarning(logStatusNotifierItem) << "Failed to load tray item" << this->properties.toString(); + + if (!StatusNotifierWatcher::instance()->isRegistered()) { + qWarning(logStatusNotifierItem) + << "Another StatusNotifier host seems to be running. Please disable it and check that " + "the problem persists before reporting an issue."; + } + } +} + TrayImageHandle::TrayImageHandle(StatusNotifierItem* item) : QsImageHandle(QQmlImageProviderBase::Pixmap, item) , item(item) {} @@ -257,6 +272,7 @@ TrayImageHandle::requestPixmap(const QString& /*unused*/, QSize* size, const QSi auto pixmap = this->item->createPixmap(targetSize); if (pixmap.isNull()) { + qCWarning(logStatusNotifierItem) << "Unable to create pixmap for tray icon" << this->item; pixmap = IconImageProvider::missingPixmap(targetSize); } diff --git a/src/services/status_notifier/item.hpp b/src/services/status_notifier/item.hpp index efe31591..2a22e2ec 100644 --- a/src/services/status_notifier/item.hpp +++ b/src/services/status_notifier/item.hpp @@ -75,6 +75,7 @@ signals: private slots: void updateIcon(); void onGetAllFinished(); + void onGetAllFailed(); void onMenuPathChanged(); private: diff --git a/src/services/status_notifier/watcher.cpp b/src/services/status_notifier/watcher.cpp index a6fd2179..4917077c 100644 --- a/src/services/status_notifier/watcher.cpp +++ b/src/services/status_notifier/watcher.cpp @@ -47,12 +47,15 @@ StatusNotifierWatcher::StatusNotifierWatcher(QObject* parent): QObject(parent) { this->tryRegister(); } +bool StatusNotifierWatcher::isRegistered() const { return this->registered; } + void StatusNotifierWatcher::tryRegister() { // NOLINT auto bus = QDBusConnection::sessionBus(); auto success = bus.registerService("org.kde.StatusNotifierWatcher"); if (success) { qCDebug(logStatusNotifierWatcher) << "Registered watcher at org.kde.StatusNotifierWatcher"; + this->registered = true; } else { qCDebug(logStatusNotifierWatcher) << "Could not register watcher at org.kde.StatusNotifierWatcher, presumably because one is " @@ -68,7 +71,6 @@ void StatusNotifierWatcher::onServiceUnregistered(const QString& service) { << "Active StatusNotifierWatcher unregistered, attempting registration"; this->tryRegister(); return; - ; } else { QString qualifiedItem; this->items.removeIf([&](const QString& item) { diff --git a/src/services/status_notifier/watcher.hpp b/src/services/status_notifier/watcher.hpp index 5fd41e5a..4a042257 100644 --- a/src/services/status_notifier/watcher.hpp +++ b/src/services/status_notifier/watcher.hpp @@ -29,6 +29,7 @@ public: [[nodiscard]] qint32 protocolVersion() const { return 0; } // NOLINT [[nodiscard]] bool isHostRegistered() const; [[nodiscard]] QList registeredItems() const; + [[nodiscard]] bool isRegistered() const; // NOLINTBEGIN void RegisterStatusNotifierHost(const QString& host); @@ -54,6 +55,7 @@ private: QDBusServiceWatcher serviceWatcher; QList hosts; QList items; + bool registered = false; }; } // namespace qs::service::sni