mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-11-04 04:04:17 +01:00
Modules: return bool to indicate whether the detection is succeeded
This commit is contained in:
@@ -56,7 +56,7 @@ static void printDevice(FFBluetoothOptions* options, const FFBluetoothResult* de
|
||||
}
|
||||
}
|
||||
|
||||
void ffPrintBluetooth(FFBluetoothOptions* options)
|
||||
bool ffPrintBluetooth(FFBluetoothOptions* options)
|
||||
{
|
||||
FF_LIST_AUTO_DESTROY devices = ffListCreate(sizeof (FFBluetoothResult));
|
||||
const char* error = ffDetectBluetooth(options, &devices);
|
||||
@@ -64,29 +64,28 @@ void ffPrintBluetooth(FFBluetoothOptions* options)
|
||||
if(error)
|
||||
{
|
||||
ffPrintError(FF_BLUETOOTH_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "%s", error);
|
||||
return false;
|
||||
}
|
||||
else
|
||||
|
||||
FF_LIST_AUTO_DESTROY filtered = ffListCreate(sizeof(FFBluetoothResult*));
|
||||
|
||||
FF_LIST_FOR_EACH(FFBluetoothResult, device, devices)
|
||||
{
|
||||
FF_LIST_AUTO_DESTROY filtered = ffListCreate(sizeof(FFBluetoothResult*));
|
||||
if(!device->connected && !options->showDisconnected)
|
||||
continue;
|
||||
|
||||
FF_LIST_FOR_EACH(FFBluetoothResult, device, devices)
|
||||
{
|
||||
if(!device->connected && !options->showDisconnected)
|
||||
continue;
|
||||
*(FFBluetoothResult**)ffListAdd(&filtered) = device;
|
||||
}
|
||||
|
||||
*(FFBluetoothResult**)ffListAdd(&filtered) = device;
|
||||
}
|
||||
if(filtered.length == 0)
|
||||
{
|
||||
ffPrintError(FF_BLUETOOTH_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "No bluetooth devices found");
|
||||
}
|
||||
|
||||
if(filtered.length == 0)
|
||||
{
|
||||
ffPrintError(FF_BLUETOOTH_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "No bluetooth devices found");
|
||||
}
|
||||
|
||||
for(uint32_t i = 0; i < filtered.length; i++)
|
||||
{
|
||||
uint8_t index = (uint8_t) (filtered.length == 1 ? 0 : i + 1);
|
||||
printDevice(options, *FF_LIST_GET(FFBluetoothResult*, filtered, i), index);
|
||||
}
|
||||
for(uint32_t i = 0; i < filtered.length; i++)
|
||||
{
|
||||
uint8_t index = (uint8_t) (filtered.length == 1 ? 0 : i + 1);
|
||||
printDevice(options, *FF_LIST_GET(FFBluetoothResult*, filtered, i), index);
|
||||
}
|
||||
|
||||
FF_LIST_FOR_EACH(FFBluetoothResult, device, devices)
|
||||
@@ -95,6 +94,7 @@ void ffPrintBluetooth(FFBluetoothOptions* options)
|
||||
ffStrbufDestroy(&device->type);
|
||||
ffStrbufDestroy(&device->address);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void ffParseBluetoothJsonObject(FFBluetoothOptions* options, yyjson_val* module)
|
||||
@@ -128,7 +128,7 @@ void ffGenerateBluetoothJsonConfig(FFBluetoothOptions* options, yyjson_mut_doc*
|
||||
ffPercentGenerateJsonConfig(doc, module, options->percent);
|
||||
}
|
||||
|
||||
void ffGenerateBluetoothJsonResult(FFBluetoothOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)
|
||||
bool ffGenerateBluetoothJsonResult(FFBluetoothOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)
|
||||
{
|
||||
FF_LIST_AUTO_DESTROY results = ffListCreate(sizeof(FFBluetoothResult));
|
||||
|
||||
@@ -136,7 +136,7 @@ void ffGenerateBluetoothJsonResult(FFBluetoothOptions* options, yyjson_mut_doc*
|
||||
if (error)
|
||||
{
|
||||
yyjson_mut_obj_add_str(doc, module, "error", error);
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
yyjson_mut_val* arr = yyjson_mut_obj_add_arr(doc, module, "result");
|
||||
@@ -157,6 +157,7 @@ void ffGenerateBluetoothJsonResult(FFBluetoothOptions* options, yyjson_mut_doc*
|
||||
ffStrbufDestroy(&device->type);
|
||||
ffStrbufDestroy(&device->address);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void ffInitBluetoothOptions(FFBluetoothOptions* options)
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
#define FF_BLUETOOTH_MODULE_NAME "Bluetooth"
|
||||
|
||||
void ffPrintBluetooth(FFBluetoothOptions* options);
|
||||
bool ffPrintBluetooth(FFBluetoothOptions* options);
|
||||
void ffInitBluetoothOptions(FFBluetoothOptions* options);
|
||||
void ffDestroyBluetoothOptions(FFBluetoothOptions* options);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user