forked from quickshell/quickshell
		
	service/tray: report misbehaving tray hosts
I've debugged broken tray items that just end up being a bad host far too many times.
This commit is contained in:
		
							parent
							
								
									0445eee33a
								
							
						
					
					
						commit
						36d1dbeb69
					
				
					 6 changed files with 25 additions and 2 deletions
				
			
		| 
						 | 
					@ -268,14 +268,15 @@ void DBusPropertyGroup::updateAllViaGetAll() {
 | 
				
			||||||
			qCWarning(logDbusProperties).noquote()
 | 
								qCWarning(logDbusProperties).noquote()
 | 
				
			||||||
			    << "Error updating properties of" << this->toString() << "via GetAll";
 | 
								    << "Error updating properties of" << this->toString() << "via GetAll";
 | 
				
			||||||
			qCWarning(logDbusProperties) << reply.error();
 | 
								qCWarning(logDbusProperties) << reply.error();
 | 
				
			||||||
 | 
								emit this->getAllFailed(reply.error());
 | 
				
			||||||
		} else {
 | 
							} else {
 | 
				
			||||||
			qCDebug(logDbusProperties).noquote()
 | 
								qCDebug(logDbusProperties).noquote()
 | 
				
			||||||
			    << "Received GetAll property set for" << this->toString();
 | 
								    << "Received GetAll property set for" << this->toString();
 | 
				
			||||||
			this->updatePropertySet(reply.value(), true);
 | 
								this->updatePropertySet(reply.value(), true);
 | 
				
			||||||
 | 
								emit this->getAllFinished();
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		delete call;
 | 
							delete call;
 | 
				
			||||||
		emit this->getAllFinished();
 | 
					 | 
				
			||||||
	};
 | 
						};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	QObject::connect(call, &QDBusPendingCallWatcher::finished, this, responseCallback);
 | 
						QObject::connect(call, &QDBusPendingCallWatcher::finished, this, responseCallback);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -135,6 +135,7 @@ public:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
signals:
 | 
					signals:
 | 
				
			||||||
	void getAllFinished();
 | 
						void getAllFinished();
 | 
				
			||||||
 | 
						void getAllFailed(QDBusError error);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
private slots:
 | 
					private slots:
 | 
				
			||||||
	void onPropertiesChanged(
 | 
						void onPropertiesChanged(
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -26,6 +26,7 @@
 | 
				
			||||||
#include "dbus_item.h"
 | 
					#include "dbus_item.h"
 | 
				
			||||||
#include "dbus_item_types.hpp"
 | 
					#include "dbus_item_types.hpp"
 | 
				
			||||||
#include "host.hpp"
 | 
					#include "host.hpp"
 | 
				
			||||||
 | 
					#include "watcher.hpp"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
using namespace qs::dbus;
 | 
					using namespace qs::dbus;
 | 
				
			||||||
using namespace qs::dbus::dbusmenu;
 | 
					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->overlayIconPixmaps, &AbstractDBusProperty::changed, this, &StatusNotifierItem::updateIcon);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	QObject::connect(&this->properties, &DBusPropertyGroup::getAllFinished, this, &StatusNotifierItem::onGetAllFinished);
 | 
						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);
 | 
						QObject::connect(&this->menuPath, &AbstractDBusProperty::changed, this, &StatusNotifierItem::onMenuPathChanged);
 | 
				
			||||||
	// clang-format on
 | 
						// clang-format on
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -246,6 +248,19 @@ void StatusNotifierItem::onGetAllFinished() {
 | 
				
			||||||
	emit this->ready();
 | 
						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)
 | 
					TrayImageHandle::TrayImageHandle(StatusNotifierItem* item)
 | 
				
			||||||
    : QsImageHandle(QQmlImageProviderBase::Pixmap, item)
 | 
					    : QsImageHandle(QQmlImageProviderBase::Pixmap, item)
 | 
				
			||||||
    , item(item) {}
 | 
					    , item(item) {}
 | 
				
			||||||
| 
						 | 
					@ -257,6 +272,7 @@ TrayImageHandle::requestPixmap(const QString& /*unused*/, QSize* size, const QSi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	auto pixmap = this->item->createPixmap(targetSize);
 | 
						auto pixmap = this->item->createPixmap(targetSize);
 | 
				
			||||||
	if (pixmap.isNull()) {
 | 
						if (pixmap.isNull()) {
 | 
				
			||||||
 | 
							qCWarning(logStatusNotifierItem) << "Unable to create pixmap for tray icon" << this->item;
 | 
				
			||||||
		pixmap = IconImageProvider::missingPixmap(targetSize);
 | 
							pixmap = IconImageProvider::missingPixmap(targetSize);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -75,6 +75,7 @@ signals:
 | 
				
			||||||
private slots:
 | 
					private slots:
 | 
				
			||||||
	void updateIcon();
 | 
						void updateIcon();
 | 
				
			||||||
	void onGetAllFinished();
 | 
						void onGetAllFinished();
 | 
				
			||||||
 | 
						void onGetAllFailed();
 | 
				
			||||||
	void onMenuPathChanged();
 | 
						void onMenuPathChanged();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
private:
 | 
					private:
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -47,12 +47,15 @@ StatusNotifierWatcher::StatusNotifierWatcher(QObject* parent): QObject(parent) {
 | 
				
			||||||
	this->tryRegister();
 | 
						this->tryRegister();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					bool StatusNotifierWatcher::isRegistered() const { return this->registered; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void StatusNotifierWatcher::tryRegister() { // NOLINT
 | 
					void StatusNotifierWatcher::tryRegister() { // NOLINT
 | 
				
			||||||
	auto bus = QDBusConnection::sessionBus();
 | 
						auto bus = QDBusConnection::sessionBus();
 | 
				
			||||||
	auto success = bus.registerService("org.kde.StatusNotifierWatcher");
 | 
						auto success = bus.registerService("org.kde.StatusNotifierWatcher");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (success) {
 | 
						if (success) {
 | 
				
			||||||
		qCDebug(logStatusNotifierWatcher) << "Registered watcher at org.kde.StatusNotifierWatcher";
 | 
							qCDebug(logStatusNotifierWatcher) << "Registered watcher at org.kde.StatusNotifierWatcher";
 | 
				
			||||||
 | 
							this->registered = true;
 | 
				
			||||||
	} else {
 | 
						} else {
 | 
				
			||||||
		qCDebug(logStatusNotifierWatcher)
 | 
							qCDebug(logStatusNotifierWatcher)
 | 
				
			||||||
		    << "Could not register watcher at org.kde.StatusNotifierWatcher, presumably because one is "
 | 
							    << "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";
 | 
							    << "Active StatusNotifierWatcher unregistered, attempting registration";
 | 
				
			||||||
		this->tryRegister();
 | 
							this->tryRegister();
 | 
				
			||||||
		return;
 | 
							return;
 | 
				
			||||||
		;
 | 
					 | 
				
			||||||
	} else {
 | 
						} else {
 | 
				
			||||||
		QString qualifiedItem;
 | 
							QString qualifiedItem;
 | 
				
			||||||
		this->items.removeIf([&](const QString& item) {
 | 
							this->items.removeIf([&](const QString& item) {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -29,6 +29,7 @@ public:
 | 
				
			||||||
	[[nodiscard]] qint32 protocolVersion() const { return 0; } // NOLINT
 | 
						[[nodiscard]] qint32 protocolVersion() const { return 0; } // NOLINT
 | 
				
			||||||
	[[nodiscard]] bool isHostRegistered() const;
 | 
						[[nodiscard]] bool isHostRegistered() const;
 | 
				
			||||||
	[[nodiscard]] QList<QString> registeredItems() const;
 | 
						[[nodiscard]] QList<QString> registeredItems() const;
 | 
				
			||||||
 | 
						[[nodiscard]] bool isRegistered() const;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// NOLINTBEGIN
 | 
						// NOLINTBEGIN
 | 
				
			||||||
	void RegisterStatusNotifierHost(const QString& host);
 | 
						void RegisterStatusNotifierHost(const QString& host);
 | 
				
			||||||
| 
						 | 
					@ -54,6 +55,7 @@ private:
 | 
				
			||||||
	QDBusServiceWatcher serviceWatcher;
 | 
						QDBusServiceWatcher serviceWatcher;
 | 
				
			||||||
	QList<QString> hosts;
 | 
						QList<QString> hosts;
 | 
				
			||||||
	QList<QString> items;
 | 
						QList<QString> items;
 | 
				
			||||||
 | 
						bool registered = false;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
} // namespace qs::service::sni
 | 
					} // namespace qs::service::sni
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue