mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-09-13 02:42:09 +02:00
Battery (Windows): add flag --battery-use-setup-api
This commit is contained in:
@@ -10,6 +10,7 @@ Changes:
|
||||
* The global flag `--allow-slow-operations` is splitted into some explicit flags in differnet modules
|
||||
* `--packages-winget`: control whether `winget` packages count should be detected. Note it's a very slow operation, please enable it with caution.
|
||||
* `--chassis-use-wmi`: control whether `WMI` query should be used to detect chassis type, which detects more information, but slower. This flag only affects `--chassis-format` and `--format json`.
|
||||
* `--battery-use-setup-api`: control whether `SetupAPI` should be used on Windows to detect battery info, which supports multi batteries, but slower.
|
||||
|
||||
Features:
|
||||
* Quirks for MIPS platforms (CPU, Linux)
|
||||
|
||||
@@ -800,6 +800,11 @@
|
||||
"title": "The directory where the battery folders are. Standard: `/sys/class/power_supply/`. Linux only",
|
||||
"type": "string"
|
||||
},
|
||||
"useSetupApi": {
|
||||
"title": "Set if `SetupAPI` should be used on Windows to detect battery info, which supports multi batteries, but slower. Windows only",
|
||||
"type": "boolean",
|
||||
"default": false
|
||||
},
|
||||
"temp": {
|
||||
"title": "Detect and display Battery temperature if supported",
|
||||
"type": "boolean",
|
||||
|
||||
+2
-1
@@ -144,7 +144,8 @@ Module specific options:
|
||||
--display-precise-refresh-rate: <?value>:Set if decimal refresh rates should not be rounded into integers when printing. Default is true
|
||||
--brightness-ddcci-sleep: <num> Set the sleep times (in ms) when sending DDC/CI requests. See <https://www.ddcutil.com/performance_options/#option-sleep-multiplier> for detail. Default is 10
|
||||
--sound-type: <value>: Set what type of sound devices should be printed. Should be either main, active or all. Default is main
|
||||
--battery-dir <folder>: The directory where the battery folders are. Standard: /sys/class/power_supply/
|
||||
--battery-dir <folder>: The directory where the battery folders are. Standard: `/sys/class/power_supply/`. Linux only
|
||||
--battery-use-setup-api <?value>: Set if `SetupAPI` should be used on Windows to detect battery info, which supports multi batteries, but slower. Windows only
|
||||
--cpu-temp <?value>: Detect and display CPU temperature if supported. Default is false
|
||||
--cpu-freq-ndigits <num>: Set the number of digits to keep after the decimal point when printing CPU frequency. Default is 2
|
||||
--cpuusage-separate <?value>: Display CPU usage per CPU logical core, instead of an average result. Default is false
|
||||
|
||||
@@ -32,7 +32,7 @@ static inline void wrapSetupDiDestroyDeviceInfoList(HDEVINFO* hdev)
|
||||
|
||||
const char* ffDetectBattery(FFBatteryOptions* options, FFlist* results)
|
||||
{
|
||||
if(instance.config.general.allowSlowOperations)
|
||||
if(options->useSetupApi)
|
||||
{
|
||||
//https://learn.microsoft.com/en-us/windows/win32/power/enumerating-battery-devices
|
||||
HDEVINFO hdev __attribute__((__cleanup__(wrapSetupDiDestroyDeviceInfoList))) =
|
||||
|
||||
@@ -122,6 +122,14 @@ bool ffParseBatteryCommandOptions(FFBatteryOptions* options, const char* key, co
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32
|
||||
if (ffStrEqualsIgnCase(subKey, "use-setup-api"))
|
||||
{
|
||||
options->useSetupApi = ffOptionParseBoolean(value);
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -146,6 +154,14 @@ void ffParseBatteryJsonObject(FFBatteryOptions* options, yyjson_val* module)
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32
|
||||
if (ffStrEqualsIgnCase(key, "useSetupApi"))
|
||||
{
|
||||
options->useSetupApi = yyjson_get_bool(val);
|
||||
continue;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (ffStrEqualsIgnCase(key, "temp"))
|
||||
{
|
||||
options->temp = yyjson_get_bool(val);
|
||||
@@ -168,6 +184,11 @@ void ffGenerateBatteryJsonConfig(FFBatteryOptions* options, yyjson_mut_doc* doc,
|
||||
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);
|
||||
#endif
|
||||
|
||||
if (options->temp != defaultOptions.temp)
|
||||
yyjson_mut_obj_add_bool(doc, module, "temp", options->temp);
|
||||
}
|
||||
@@ -233,6 +254,8 @@ void ffInitBatteryOptions(FFBatteryOptions* options)
|
||||
|
||||
#ifdef __linux__
|
||||
ffStrbufInit(&options->dir);
|
||||
#elif defined(_WIN32)
|
||||
options->useSetupApi = false;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -13,5 +13,7 @@ typedef struct FFBatteryOptions
|
||||
|
||||
#ifdef __linux__
|
||||
FFstrbuf dir;
|
||||
#elif defined(_WIN32)
|
||||
bool useSetupApi;
|
||||
#endif
|
||||
} FFBatteryOptions;
|
||||
|
||||
Reference in New Issue
Block a user