SNI: Remove callback for erased items

Should fix DBusNameVanished spam as found in https://github.com/scorpion-26/gBar/issues/29
This commit is contained in:
scorpion-26 2023-07-28 18:56:51 +02:00
parent ef8652f046
commit a7862a4242

View file

@ -39,6 +39,8 @@ namespace SNI
std::string menuObjectPath; std::string menuObjectPath;
EventBox* gtkEvent; EventBox* gtkEvent;
int watcherID;
}; };
std::vector<Item> items; std::vector<Item> items;
@ -272,13 +274,20 @@ namespace SNI
if (it != items.end()) if (it != items.end())
{ {
LOG("SNI: " << name << " vanished!"); LOG("SNI: " << name << " vanished!");
g_bus_unwatch_name(it->watcherID);
items.erase(it); items.erase(it);
InvalidateWidget(); InvalidateWidget();
return;
} }
else
auto toRegisterIt = clientsToQuery.find(name);
if (toRegisterIt != clientsToQuery.end())
{ {
LOG("SNI: Cannot remove unregistered bus name " << name); clientsToQuery.erase(toRegisterIt);
} }
LOG("SNI: Cannot remove unregistered bus name " << name);
return;
} }
static void ItemPropertyChanged(GDBusConnection*, const char* senderName, 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)
@ -304,6 +313,7 @@ namespace SNI
LOG("SNI: Actual object path: " << itemObjectPath) LOG("SNI: Actual object path: " << itemObjectPath)
if (it != items.end()) if (it != items.end())
{ {
g_bus_unwatch_name(it->watcherID);
items.erase(it); items.erase(it);
} }
else else
@ -325,8 +335,8 @@ namespace SNI
LOG("SNI: Creating Item " << client.name << " " << client.object); LOG("SNI: Creating Item " << client.name << " " << client.object);
Item item = CreateItem(std::move(client.name), std::move(client.object)); Item item = CreateItem(std::move(client.name), std::move(client.object));
// Add handler for removing // Add handler for removing
g_bus_watch_name_on_connection(dbusConnection, item.name.c_str(), G_BUS_NAME_WATCHER_FLAGS_NONE, nullptr, DBusNameVanished, nullptr, item.watcherID = g_bus_watch_name_on_connection(dbusConnection, item.name.c_str(), G_BUS_NAME_WATCHER_FLAGS_NONE, nullptr,
nullptr); DBusNameVanished, nullptr, nullptr);
// Add handler for icon change // Add handler for icon change
char* staticBuf = new char[item.name.size() + 1]{0x0}; char* staticBuf = new char[item.name.size() + 1]{0x0};