From abf6c403d415ffa4c6e5e49ec7da9787a755d478 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Tue, 25 Jun 2024 16:15:35 +0800 Subject: [PATCH] Fastfetch: add JSON config `general.preRun` --- doc/json_schema.json | 5 +++++ src/options/general.c | 15 +++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/doc/json_schema.json b/doc/json_schema.json index 146a1822d..4c5ae9367 100644 --- a/doc/json_schema.json +++ b/doc/json_schema.json @@ -329,6 +329,11 @@ "type": "integer", "description": "Set the timeout (ms) when waiting for child processes, `-1` for no timeout", "default": 1000 + }, + "preRun": { + "type": "string", + "description": "Set the command to be executed before printing logos", + "default": "" } } }, diff --git a/src/options/general.c b/src/options/general.c index 2b87d7929..b2fe71150 100644 --- a/src/options/general.c +++ b/src/options/general.c @@ -1,5 +1,6 @@ #include "fastfetch.h" #include "common/jsonconfig.h" +#include "common/processing.h" #include "options/general.h" #include "util/stringUtils.h" @@ -21,6 +22,20 @@ const char* ffOptionsParseGeneralJsonConfig(FFOptionsGeneral* options, yyjson_va options->multithreading = yyjson_get_bool(val); else if (ffStrEqualsIgnCase(key, "processingTimeout")) options->processingTimeout = (int32_t) yyjson_get_int(val); + else if (ffStrEqualsIgnCase(key, "preRun")) + { + FF_STRBUF_AUTO_DESTROY _ = ffStrbufCreate(); + const char* error = ffProcessAppendStdOut(&_, (char* const[]) { + #ifdef _WIN32 + "cmd.exe", "/C", + #else + "/bin/sh", "-c", + #endif + (char*) yyjson_get_str(val), NULL + }); + if (error) + return "Failed to execute preRun command"; + } #if defined(__linux__) || defined(__FreeBSD__) || defined(__sun) else if (ffStrEqualsIgnCase(key, "escapeBedrock"))