mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-09-13 02:42:09 +02:00
Bluetooth(Linux): Refactor code a bit
This commit is contained in:
@@ -11,19 +11,19 @@ array [ //root
|
|||||||
dict entry( //property
|
dict entry( //property
|
||||||
string "org.bluez.Device1"
|
string "org.bluez.Device1"
|
||||||
array [
|
array [
|
||||||
dict entry(
|
dict entry( //value
|
||||||
string "Address"
|
string "Address"
|
||||||
variant string "03:21:8B:91:16:4D"
|
variant string "03:21:8B:91:16:4D"
|
||||||
)
|
)
|
||||||
dict entry(
|
dict entry( //value
|
||||||
string "Name"
|
string "Name"
|
||||||
variant string "JBL TUNE160BT"
|
variant string "JBL TUNE160BT"
|
||||||
)
|
)
|
||||||
dict entry(
|
dict entry( //value
|
||||||
string "Icon"
|
string "Icon"
|
||||||
variant string "audio-headset"
|
variant string "audio-headset"
|
||||||
)
|
)
|
||||||
dict entry(
|
dict entry( //value
|
||||||
string "Connected"
|
string "Connected"
|
||||||
variant boolean true
|
variant boolean true
|
||||||
)
|
)
|
||||||
@@ -32,7 +32,7 @@ array [ //root
|
|||||||
dict entry( //property
|
dict entry( //property
|
||||||
string "org.bluez.Battery1"
|
string "org.bluez.Battery1"
|
||||||
array [
|
array [
|
||||||
dict entry(
|
dict entry( //value
|
||||||
string "Percentage"
|
string "Percentage"
|
||||||
variant byte 100
|
variant byte 100
|
||||||
)
|
)
|
||||||
@@ -43,6 +43,34 @@ array [ //root
|
|||||||
]
|
]
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
static void detectBluetoothValue(FFDBusData* dbus, DBusMessageIter* iter, FFBluetoothDevice* device)
|
||||||
|
{
|
||||||
|
if(dbus->lib->ffdbus_message_iter_get_arg_type(iter) != DBUS_TYPE_DICT_ENTRY)
|
||||||
|
return;
|
||||||
|
|
||||||
|
DBusMessageIter dictIter;
|
||||||
|
dbus->lib->ffdbus_message_iter_recurse(iter, &dictIter);
|
||||||
|
|
||||||
|
if(dbus->lib->ffdbus_message_iter_get_arg_type(&dictIter) != DBUS_TYPE_STRING)
|
||||||
|
return;
|
||||||
|
|
||||||
|
const char* deviceProperty;
|
||||||
|
dbus->lib->ffdbus_message_iter_get_basic(&dictIter, &deviceProperty);
|
||||||
|
|
||||||
|
dbus->lib->ffdbus_message_iter_next(&dictIter);
|
||||||
|
|
||||||
|
if(strcmp(deviceProperty, "Address") == 0)
|
||||||
|
ffDBusGetValue(dbus, &dictIter, &device->address);
|
||||||
|
else if(strcmp(deviceProperty, "Name") == 0)
|
||||||
|
ffDBusGetValue(dbus, &dictIter, &device->name);
|
||||||
|
else if(strcmp(deviceProperty, "Icon") == 0)
|
||||||
|
ffDBusGetValue(dbus, &dictIter, &device->type);
|
||||||
|
else if(strcmp(deviceProperty, "Percentage") == 0)
|
||||||
|
ffDBusGetByte(dbus, &dictIter, &device->battery);
|
||||||
|
else if(strcmp(deviceProperty, "Connected") == 0)
|
||||||
|
ffDBusGetBool(dbus, &dictIter, &device->connected);
|
||||||
|
}
|
||||||
|
|
||||||
static void detectBluetoothProperty(FFDBusData* dbus, DBusMessageIter* iter, FFBluetoothDevice* device)
|
static void detectBluetoothProperty(FFDBusData* dbus, DBusMessageIter* iter, FFBluetoothDevice* device)
|
||||||
{
|
{
|
||||||
if(dbus->lib->ffdbus_message_iter_get_arg_type(iter) != DBUS_TYPE_DICT_ENTRY)
|
if(dbus->lib->ffdbus_message_iter_get_arg_type(iter) != DBUS_TYPE_DICT_ENTRY)
|
||||||
@@ -70,31 +98,7 @@ static void detectBluetoothProperty(FFDBusData* dbus, DBusMessageIter* iter, FFB
|
|||||||
|
|
||||||
while(true)
|
while(true)
|
||||||
{
|
{
|
||||||
if(dbus->lib->ffdbus_message_iter_get_arg_type(&arrayIter) != DBUS_TYPE_DICT_ENTRY)
|
detectBluetoothValue(dbus, &arrayIter, device);
|
||||||
FF_DBUS_ITER_CONTINUE(dbus, &arrayIter)
|
|
||||||
|
|
||||||
DBusMessageIter deviceIter;
|
|
||||||
dbus->lib->ffdbus_message_iter_recurse(&arrayIter, &deviceIter);
|
|
||||||
|
|
||||||
if(dbus->lib->ffdbus_message_iter_get_arg_type(&deviceIter) != DBUS_TYPE_STRING)
|
|
||||||
FF_DBUS_ITER_CONTINUE(dbus, &arrayIter)
|
|
||||||
|
|
||||||
const char* deviceProperty;
|
|
||||||
dbus->lib->ffdbus_message_iter_get_basic(&deviceIter, &deviceProperty);
|
|
||||||
|
|
||||||
dbus->lib->ffdbus_message_iter_next(&deviceIter);
|
|
||||||
|
|
||||||
if(strcmp(deviceProperty, "Address") == 0)
|
|
||||||
ffDBusGetValue(dbus, &deviceIter, &device->address);
|
|
||||||
else if(strcmp(deviceProperty, "Name") == 0)
|
|
||||||
ffDBusGetValue(dbus, &deviceIter, &device->name);
|
|
||||||
else if(strcmp(deviceProperty, "Icon") == 0)
|
|
||||||
ffDBusGetValue(dbus, &deviceIter, &device->type);
|
|
||||||
else if(strcmp(deviceProperty, "Percentage") == 0)
|
|
||||||
ffDBusGetByte(dbus, &deviceIter, &device->battery);
|
|
||||||
else if(strcmp(deviceProperty, "Connected") == 0)
|
|
||||||
ffDBusGetBool(dbus, &deviceIter, &device->connected);
|
|
||||||
|
|
||||||
FF_DBUS_ITER_CONTINUE(dbus, &arrayIter);
|
FF_DBUS_ITER_CONTINUE(dbus, &arrayIter);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -160,8 +164,6 @@ static void detectBluetoothRoot(FFBluetoothResult* bluetooth, FFDBusData* dbus,
|
|||||||
detectBluetoothObject(bluetooth, dbus, &arrayIter);
|
detectBluetoothObject(bluetooth, dbus, &arrayIter);
|
||||||
FF_DBUS_ITER_CONTINUE(dbus, &arrayIter);
|
FF_DBUS_ITER_CONTINUE(dbus, &arrayIter);
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char* detectBluetooth(const FFinstance* instance, FFBluetoothResult* bluetooth)
|
static const char* detectBluetooth(const FFinstance* instance, FFBluetoothResult* bluetooth)
|
||||||
|
|||||||
Reference in New Issue
Block a user