mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-09-13 02:14:37 +02:00
Battery (Linux): remove option --battery-dir
It was added in c5c3cecb93 but there was no comment or issues linked to indicate why it was necessary.
`/sys/class/power_supply` is standardized in <https://www.kernel.org/doc/Documentation/ABI/testing/sysfs-class-power>. I don't I want to support non-standard platform unless proper reason is given
This commit is contained in:
@@ -384,7 +384,6 @@ __fastfetch_completion()
|
||||
"--lib-pulse"
|
||||
"--lib-ddcutil"
|
||||
"--lib-nm"
|
||||
"--battery-dir"
|
||||
)
|
||||
|
||||
local FF_OPTIONS_LOGO=(
|
||||
|
||||
@@ -804,10 +804,6 @@
|
||||
"const": "battery",
|
||||
"description": "Print battery capacity, status, etc"
|
||||
},
|
||||
"dir": {
|
||||
"description": "The directory where the battery folders are. Standard: `/sys/class/power_supply/`. Linux only",
|
||||
"type": "string"
|
||||
},
|
||||
"useSetupApi": {
|
||||
"description": "Set if `SetupAPI` should be used on Windows to detect battery info, which supports multi batteries, but slower. Windows only",
|
||||
"type": "boolean",
|
||||
|
||||
@@ -1026,15 +1026,6 @@
|
||||
"default": "main"
|
||||
}
|
||||
},
|
||||
{
|
||||
"long": "battery-dir",
|
||||
"desc": "The directory where the battery folders are",
|
||||
"remark": "Linux only",
|
||||
"arg": {
|
||||
"type": "path",
|
||||
"default": "/sys/class/power_supply/"
|
||||
}
|
||||
},
|
||||
{
|
||||
"long": "battery-use-setup-api",
|
||||
"desc": "Set if \"SetupAPI\" should be used on Windows to detect battery info",
|
||||
|
||||
@@ -101,14 +101,13 @@ static void parseBattery(FFstrbuf* dir, const char* id, FFBatteryOptions* option
|
||||
const char* ffDetectBattery(FFBatteryOptions* options, FFlist* results)
|
||||
{
|
||||
FF_STRBUF_AUTO_DESTROY baseDir = ffStrbufCreateA(64);
|
||||
ffStrbufAppend(&baseDir, &options->dir);
|
||||
ffStrbufEnsureEndsWithC(&baseDir, '/');
|
||||
ffStrbufAppend(&baseDir, "/sys/class/power_supply/");
|
||||
|
||||
uint32_t baseDirLength = baseDir.length;
|
||||
|
||||
FF_AUTO_CLOSE_DIR DIR* dirp = opendir(baseDir.chars);
|
||||
if(dirp == NULL)
|
||||
return "opendir(batteryDir) == NULL";
|
||||
return "opendir(\"/sys/class/power_supply/\") == NULL";
|
||||
|
||||
struct dirent* entry;
|
||||
while((entry = readdir(dirp)) != NULL)
|
||||
@@ -122,7 +121,7 @@ const char* ffDetectBattery(FFBatteryOptions* options, FFlist* results)
|
||||
}
|
||||
|
||||
if(results->length == 0)
|
||||
return "batteryDir doesn't contain any battery folder";
|
||||
return "\"/sys/class/power_supply/\" doesn't contain any battery folder";
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -115,14 +115,6 @@ bool ffParseBatteryCommandOptions(FFBatteryOptions* options, const char* key, co
|
||||
return true;
|
||||
}
|
||||
|
||||
#ifdef __linux__
|
||||
if (ffStrEqualsIgnCase(subKey, "dir"))
|
||||
{
|
||||
ffOptionParseString(key, value, &options->dir);
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32
|
||||
if (ffStrEqualsIgnCase(subKey, "use-setup-api"))
|
||||
{
|
||||
@@ -147,14 +139,6 @@ void ffParseBatteryJsonObject(FFBatteryOptions* options, yyjson_val* module)
|
||||
if (ffJsonConfigParseModuleArgs(key, val, &options->moduleArgs))
|
||||
continue;
|
||||
|
||||
#ifdef __linux__
|
||||
if (ffStrEqualsIgnCase(key, "dir"))
|
||||
{
|
||||
ffStrbufSetS(&options->dir, yyjson_get_str(val));
|
||||
continue;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32
|
||||
if (ffStrEqualsIgnCase(key, "useSetupApi"))
|
||||
{
|
||||
@@ -180,11 +164,6 @@ void ffGenerateBatteryJsonConfig(FFBatteryOptions* options, yyjson_mut_doc* doc,
|
||||
|
||||
ffJsonConfigGenerateModuleArgsConfig(doc, module, &defaultOptions.moduleArgs, &options->moduleArgs);
|
||||
|
||||
#ifdef __linux__
|
||||
if (!ffStrbufEqual(&defaultOptions.dir, &options->dir))
|
||||
yyjson_mut_obj_add_strbuf(doc, module, "dir", &options->dir);
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32
|
||||
if (defaultOptions.useSetupApi != options->useSetupApi)
|
||||
yyjson_mut_obj_add_bool(doc, module, "useSetupApi", options->useSetupApi);
|
||||
@@ -257,9 +236,7 @@ void ffInitBatteryOptions(FFBatteryOptions* options)
|
||||
ffOptionInitModuleArg(&options->moduleArgs);
|
||||
options->temp = false;
|
||||
|
||||
#ifdef __linux__
|
||||
ffStrbufInitStatic(&options->dir, "/sys/class/power_supply/");
|
||||
#elif defined(_WIN32)
|
||||
#ifdef _WIN32
|
||||
options->useSetupApi = false;
|
||||
#endif
|
||||
}
|
||||
@@ -267,8 +244,4 @@ void ffInitBatteryOptions(FFBatteryOptions* options)
|
||||
void ffDestroyBatteryOptions(FFBatteryOptions* options)
|
||||
{
|
||||
ffOptionDestroyModuleArg(&options->moduleArgs);
|
||||
|
||||
#ifdef __linux__
|
||||
ffStrbufDestroy(&options->dir);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -11,9 +11,7 @@ typedef struct FFBatteryOptions
|
||||
|
||||
bool temp;
|
||||
|
||||
#ifdef __linux__
|
||||
FFstrbuf dir;
|
||||
#elif defined(_WIN32)
|
||||
#ifdef _WIN32
|
||||
bool useSetupApi;
|
||||
#endif
|
||||
} FFBatteryOptions;
|
||||
|
||||
Reference in New Issue
Block a user