Bluetooth (Linux): improve performance when showDisconnected == false

If no connected devices found, no dbus calls will be emitted

Fix #1450
This commit is contained in:
Carter Li
2024-12-20 11:07:09 +08:00
parent 4bef801337
commit 4f807f26a9
6 changed files with 28 additions and 8 deletions
+21 -1
View File
@@ -3,6 +3,7 @@
#ifdef FF_HAVE_DBUS
#include "common/dbus.h"
#include "common/io/io.h"
/* Example dbus reply, striped to only the relevant parts:
array [ //root
@@ -192,11 +193,30 @@ static const char* detectBluetooth(FFlist* devices)
return NULL;
}
static bool hasConnectedDevices(void)
{
FF_AUTO_CLOSE_DIR DIR* dirp = opendir("/sys/class/bluetooth");
if(dirp == NULL)
return false;
struct dirent* entry;
while ((entry = readdir(dirp)) != NULL)
{
if (strchr(entry->d_name, ':') != NULL) // ignore connected devices
return true;
}
return false;
}
#endif
const char* ffDetectBluetooth(FF_MAYBE_UNUSED FFlist* devices /* FFBluetoothResult */)
const char* ffDetectBluetooth(FFBluetoothOptions* options, FF_MAYBE_UNUSED FFlist* devices /* FFBluetoothResult */)
{
#ifdef FF_HAVE_DBUS
if (!options->showDisconnected && !hasConnectedDevices())
return NULL;
return detectBluetooth(devices);
#else
return "Fastfetch was compiled without DBus support";