mirror of
https://github.com/scorpion-26/gBar.git
synced 2024-11-22 03:02:49 +00:00
SNI: Remove items on bus name vanish
This commit is contained in:
parent
d4ffac395b
commit
a02bce9b91
1 changed files with 26 additions and 5 deletions
31
src/SNI.cpp
31
src/SNI.cpp
|
@ -198,6 +198,24 @@ namespace SNI
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void DBusNameVanished(GDBusConnection*, const char* name, void*)
|
||||||
|
{
|
||||||
|
auto it = std::find_if(items.begin(), items.end(),
|
||||||
|
[&](const Item& item)
|
||||||
|
{
|
||||||
|
return item.name == name;
|
||||||
|
});
|
||||||
|
if (it != items.end())
|
||||||
|
{
|
||||||
|
items.erase(it);
|
||||||
|
InvalidateWidget();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
LOG("SNI: Cannot remove unregistered bus name " << name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Methods
|
// Methods
|
||||||
static void RegisterItem(sniWatcher*, GDBusMethodInvocation* invocation, const char* service)
|
static void RegisterItem(sniWatcher*, GDBusMethodInvocation* invocation, const char* service)
|
||||||
{
|
{
|
||||||
|
@ -215,18 +233,21 @@ namespace SNI
|
||||||
name = service;
|
name = service;
|
||||||
object = "/StatusNotifierItem";
|
object = "/StatusNotifierItem";
|
||||||
}
|
}
|
||||||
auto it = std::find_if(items.begin(), items.end(), [&](const Item& item)
|
auto it = std::find_if(items.begin(), items.end(),
|
||||||
{
|
[&](const Item& item)
|
||||||
return item.name == name && item.object == object;
|
{
|
||||||
});
|
return item.name == name && item.object == object;
|
||||||
|
});
|
||||||
if (it != items.end())
|
if (it != items.end())
|
||||||
{
|
{
|
||||||
LOG("Rejecting " << name << " " << object);
|
LOG("Rejecting " << name << " " << object);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// TODO: Add mechanism to remove items
|
|
||||||
LOG("SNI: Registered Item " << name << " " << object);
|
LOG("SNI: Registered Item " << name << " " << object);
|
||||||
Item item = CreateItem(std::move(name), std::move(object));
|
Item item = CreateItem(std::move(name), std::move(object));
|
||||||
|
// Add handler for removing
|
||||||
|
g_bus_watch_name_on_connection(dbusConnection, item.name.c_str(), G_BUS_NAME_WATCHER_FLAGS_NONE, nullptr, DBusNameVanished, nullptr, nullptr);
|
||||||
|
|
||||||
items.push_back(std::move(item));
|
items.push_back(std::move(item));
|
||||||
InvalidateWidget();
|
InvalidateWidget();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue