diff --git a/CHANGELOG.md b/CHANGELOG.md index 561f6340a..bb6e93bd4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ Changes: * Display keys `percent*` and `size*` in JSON config are restructured. `{ "sizeNdigits": 1 }` is now `{ "size": { "ndigits": 1 } }` * With the introduction of `--migrate-config`, the old flag based config file is deprecated, and will be removed in 3.0.0 (next major version) * Support of `--gen-config conf` is deprecated accordingly, and will be removed in 2.3.0 (next minor version) +* A new flag `--packages-winget` is introduced to control whether `winget` packages count should be detected. It was controlled by `--allow-slow-operations` previously. Note it's a very slow operation, please enable it with caution. Features: * Quirks for MIPS platforms (CPU, Linux) diff --git a/doc/json_schema.json b/doc/json_schema.json index c401e5c45..e82280bcf 100644 --- a/doc/json_schema.json +++ b/doc/json_schema.json @@ -708,10 +708,6 @@ "const": "os", "description": "Print operating system name and version" }, - { - "const": "packages", - "description": "List installed package managers and count of installed packages" - }, { "const": "player", "description": "Print music player name" @@ -1282,6 +1278,20 @@ }, "additionalProperties": false }, + { + "title": "Packages", + "properties": { + "type": { + "const": "packages", + "description": "List installed package managers and count of installed packages" + }, + "winget": { + "description": "Set if winget package count should be detected.\nNote this is very slow operation. Please make sure `winget list` works before enable this option\nWindows only", + "type": "boolean", + "default": false + } + } + }, { "title": "Public IP", "properties": { diff --git a/src/data/help.txt b/src/data/help.txt index a495119cb..865490150 100644 --- a/src/data/help.txt +++ b/src/data/help.txt @@ -137,6 +137,7 @@ Module specific options: --disk-use-available : Use f_bavail (lpFreeBytesAvailableToCaller for Windows) instead of f_bfree to calculate used bytes. Default is false --diskio-name-prefix : Show disks with given name prefix only. Default is empty --bluetooth-show-disconnected: : Set if disconnected bluetooth devices should be printed. Default is false + --packages-winget: : Set if winget package count should be detected. Default is false --display-compact-type: : Set if all displays should be printed in one line. Default is none --display-detect-name: : Set if display name should be detected and printed (if supported). Default is false --display-precise-refresh-rate: :Set if decimal refresh rates should not be rounded into integers when printing. Default is true diff --git a/src/detection/packages/packages.c b/src/detection/packages/packages.c index ce7c778c3..2d1268a80 100644 --- a/src/detection/packages/packages.c +++ b/src/detection/packages/packages.c @@ -3,11 +3,11 @@ #include -void ffDetectPackagesImpl(FFPackagesResult* result); +void ffDetectPackagesImpl(FFPackagesResult* result, FFPackagesOptions* options); -const char* ffDetectPackages(FFPackagesResult* result) +const char* ffDetectPackages(FFPackagesResult* result, FFPackagesOptions* options) { - ffDetectPackagesImpl(result); + ffDetectPackagesImpl(result, options); for(uint32_t i = 0; i < offsetof(FFPackagesResult, all) / sizeof(uint32_t); ++i) result->all += ((uint32_t *)result)[i]; diff --git a/src/detection/packages/packages.h b/src/detection/packages/packages.h index 475d39301..1fb5e0d85 100644 --- a/src/detection/packages/packages.h +++ b/src/detection/packages/packages.h @@ -36,6 +36,6 @@ typedef struct FFPackagesResult FFstrbuf pacmanBranch; } FFPackagesResult; -const char* ffDetectPackages(FFPackagesResult* result); +const char* ffDetectPackages(FFPackagesResult* result, FFPackagesOptions* options); #endif diff --git a/src/detection/packages/packages_apple.c b/src/detection/packages/packages_apple.c index 97e858fbe..d49944d84 100644 --- a/src/detection/packages/packages_apple.c +++ b/src/detection/packages/packages_apple.c @@ -68,7 +68,7 @@ static uint32_t getMacPortsPackages() return countMacPortsPackages(FASTFETCH_TARGET_DIR_ROOT"/opt/local"); } -void ffDetectPackagesImpl(FFPackagesResult* result) +void ffDetectPackagesImpl(FFPackagesResult* result, FF_MAYBE_UNUSED FFPackagesOptions* options) { getBrewPackages(result); result->port = getMacPortsPackages(); diff --git a/src/detection/packages/packages_linux.c b/src/detection/packages/packages_linux.c index 332fd3de0..9351b420f 100644 --- a/src/detection/packages/packages_linux.c +++ b/src/detection/packages/packages_linux.c @@ -327,7 +327,7 @@ static void getPackageCountsBedrock(FFstrbuf* baseDir, FFPackagesResult* package ffStrbufSubstrBefore(baseDir, baseDirLength); } -void ffDetectPackagesImpl(FFPackagesResult* result) +void ffDetectPackagesImpl(FFPackagesResult* result, FF_MAYBE_UNUSED FFPackagesOptions* options) { FF_STRBUF_AUTO_DESTROY baseDir = ffStrbufCreateA(512); ffStrbufAppendS(&baseDir, FASTFETCH_TARGET_DIR_ROOT); diff --git a/src/detection/packages/packages_windows.c b/src/detection/packages/packages_windows.c index e5b591361..4bd845e2a 100644 --- a/src/detection/packages/packages_windows.c +++ b/src/detection/packages/packages_windows.c @@ -105,11 +105,11 @@ static void detectWinget(FFPackagesResult* result) result->winget = count; } -void ffDetectPackagesImpl(FFPackagesResult* result) +void ffDetectPackagesImpl(FFPackagesResult* result, FFPackagesOptions* options) { detectScoop(result); detectChoco(result); detectPacman(result); - if (instance.config.general.allowSlowOperations) + if (options->winget) detectWinget(result); } diff --git a/src/modules/packages/option.h b/src/modules/packages/option.h index eb3050b96..afbbccccc 100644 --- a/src/modules/packages/option.h +++ b/src/modules/packages/option.h @@ -8,4 +8,8 @@ typedef struct FFPackagesOptions { FFModuleBaseInfo moduleInfo; FFModuleArgs moduleArgs; + +#ifdef _WIN32 + bool winget; +#endif } FFPackagesOptions; diff --git a/src/modules/packages/packages.c b/src/modules/packages/packages.c index 0e3202f41..915707244 100644 --- a/src/modules/packages/packages.c +++ b/src/modules/packages/packages.c @@ -11,7 +11,7 @@ void ffPrintPackages(FFPackagesOptions* options) FFPackagesResult counts = {}; ffStrbufInit(&counts.pacmanBranch); - const char* error = ffDetectPackages(&counts); + const char* error = ffDetectPackages(&counts, options); if(error) { @@ -109,6 +109,14 @@ bool ffParsePackagesCommandOptions(FFPackagesOptions* options, const char* key, if (ffOptionParseModuleArgs(key, subKey, value, &options->moduleArgs)) return true; + #ifdef _WIN32 + if(ffStrEqualsIgnCase(subKey, "winget")) + { + options->winget = ffOptionParseBoolean(value); + return true; + } + #endif + return false; } @@ -125,6 +133,14 @@ void ffParsePackagesJsonObject(FFPackagesOptions* options, yyjson_val* module) if (ffJsonConfigParseModuleArgs(key, val, &options->moduleArgs)) continue; + #ifdef _WIN32 + if (ffStrEqualsIgnCase(key, "winget")) + { + options->winget = yyjson_get_bool(val); + continue; + } + #endif + ffPrintError(FF_PACKAGES_MODULE_NAME, 0, &options->moduleArgs, "Unknown JSON key %s", key); } } @@ -135,6 +151,11 @@ void ffGeneratePackagesJsonConfig(FFPackagesOptions* options, yyjson_mut_doc* do ffInitPackagesOptions(&defaultOptions); ffJsonConfigGenerateModuleArgsConfig(doc, module, &defaultOptions.moduleArgs, &options->moduleArgs); + + #ifdef _WIN32 + if (options->winget != defaultOptions.winget) + yyjson_mut_obj_add_bool(doc, module, "winget", options->winget); + #endif } void ffGeneratePackagesJsonResult(FF_MAYBE_UNUSED FFPackagesOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) @@ -142,7 +163,7 @@ void ffGeneratePackagesJsonResult(FF_MAYBE_UNUSED FFPackagesOptions* options, yy FFPackagesResult counts = {}; ffStrbufInit(&counts.pacmanBranch); - const char* error = ffDetectPackages(&counts); + const char* error = ffDetectPackages(&counts, options); if(error) { @@ -225,6 +246,10 @@ void ffInitPackagesOptions(FFPackagesOptions* options) ffGeneratePackagesJsonConfig ); ffOptionInitModuleArg(&options->moduleArgs); + + #ifdef _WIN32 + options->winget = false; + #endif } void ffDestroyPackagesOptions(FFPackagesOptions* options)