From 8a52836afc832c076b72fa375b4404243f6370d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Thu, 29 Sep 2022 17:14:50 +0800 Subject: [PATCH] Init: don't pay for unused module Networking can be very slow --- src/common/init.c | 4 ---- src/fastfetch.c | 13 +++++++++++++ src/flashfetch.c | 4 ++++ 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/common/init.c b/src/common/init.c index 3f26cc3cc..0c4674755 100644 --- a/src/common/init.c +++ b/src/common/init.c @@ -363,10 +363,6 @@ static void exitSignalHandler(int signal) void ffStart(FFinstance* instance) { - ffPrepareCPUUsage(); - ffPreparePublicIp(instance); - ffPrepareWeather(instance); - if(instance->config.multithreading) startDetectionThreads(instance); diff --git a/src/fastfetch.c b/src/fastfetch.c index 8acb7419c..a42c0d802 100644 --- a/src/fastfetch.c +++ b/src/fastfetch.c @@ -1485,6 +1485,19 @@ int main(int argc, const char** argv) if(data.structure.length == 0) ffStrbufAppendS(&data.structure, FASTFETCH_DATATEXT_STRUCTURE); + #define FF_CONTAINS_MODULE_NAME(moduleName)\ + ffStrbufContainIgnCaseS(&data.structure, ":" #moduleName ":") ||\ + ffStrbufStartsWithIgnCaseS(&data.structure, #moduleName ":") ||\ + ffStrbufEndsWithIgnCaseS(&data.structure, ":" #moduleName) + + if(FF_CONTAINS_MODULE_NAME(CPUUsage)) + ffPrepareCPUUsage(); + if(FF_CONTAINS_MODULE_NAME(PublicIp)) + ffPreparePublicIp(&instance); + if(FF_CONTAINS_MODULE_NAME(Weather)) + ffPrepareWeather(&instance); + #undef FF_CONTAINS_MODULE_NAME + ffStart(&instance); //Parse the structure and call the modules diff --git a/src/flashfetch.c b/src/flashfetch.c index 159847956..e20b2aa1b 100644 --- a/src/flashfetch.c +++ b/src/flashfetch.c @@ -10,6 +10,10 @@ int main(int argc, char** argv) //Modify instance.config here + // ffPrepareCPUUsage(); + // ffPreparePublicIp(&instance); + // ffPrepareWeather(&instance); + //Does things like starting detection threads, disabling line wrap, etc ffStart(&instance);