SNI: Use our object path for ItemPropertyChanged

ItemPropertyChanged is called multiple times per actual icon change.
senderName is the same, objectPath is the same, but our registered name
for the callback differs.
We can't use the provided name for item searching, since that *can*
differ from the one we registered with (Looking at you, Discord. Discord
registers with org.kde.StatusNotifierItem-*, but calls back with :*.*)
Since then the object path will sometimes be wrong for the name, we just
use the one from the icon we originally registered with. This causes
multiple icons to reload though

Potential fix for https://github.com/scorpion-26/gBar/issues/26
This commit is contained in:
scorpion-26 2023-07-26 13:28:50 +02:00
parent fe7b02b10c
commit 39cf17c30f

View file

@ -279,16 +279,20 @@ namespace SNI
} }
} }
static void ItemPropertyChanged(GDBusConnection*, const char*, const char* object, const char*, const char*, GVariant*, void* name) static void ItemPropertyChanged(GDBusConnection*, const char* senderName, const char* object, const char*, const char*, GVariant*, void* name)
{ {
std::string nameStr = (const char*)name; std::string nameStr = (const char*)name;
LOG("SNI: Reloading " << (const char*)name << " " << object); LOG("SNI: Reloading " << (const char*)name << " " << object << " (Sender: " << senderName << ")");
// We don't care about *what* changed, just remove and reload // We don't care about *what* changed, just remove and reload
auto it = std::find_if(items.begin(), items.end(), auto it = std::find_if(items.begin(), items.end(),
[&](const Item& item) [&](const Item& item)
{ {
return item.name == nameStr; return item.name == nameStr;
}); });
// We can't trust the object path given to us, since ItemPropertyChanged is called multiple times with the same name, but with different
// object paths.
std::string itemObjectPath = it->object;
LOG("SNI: Actual object path: " << itemObjectPath)
if (it != items.end()) if (it != items.end())
{ {
items.erase(it); items.erase(it);
@ -297,7 +301,7 @@ namespace SNI
{ {
LOG("SNI: Coudn't remove item " << nameStr << " when reloading"); LOG("SNI: Coudn't remove item " << nameStr << " when reloading");
} }
clientsToQuery[nameStr] = {nameStr, std::string(object)}; clientsToQuery[nameStr] = {nameStr, itemObjectPath};
} }
static TimerResult UpdateWidgets(Box&) static TimerResult UpdateWidgets(Box&)