Global: make FFinstance instance a global variable

As discussed in https://github.com/fastfetch-cli/fastfetch/discussions/473
This commit is contained in:
李通洲
2023-06-24 10:59:53 +08:00
parent 48b01c9665
commit d0f093c567
255 changed files with 2020 additions and 2064 deletions
+1 -1
View File
@@ -26,6 +26,6 @@ typedef struct FFTerminalShellResult
FFstrbuf userShellVersion;
} FFTerminalShellResult;
const FFTerminalShellResult* ffDetectTerminalShell(const FFinstance* instance);
const FFTerminalShellResult* ffDetectTerminalShell();
#endif
@@ -262,9 +262,9 @@ static void getTerminalFromEnv(FFTerminalShellResult* result)
}
}
static void getUserShellFromEnv(const FFinstance* instance, FFTerminalShellResult* result)
static void getUserShellFromEnv(FFTerminalShellResult* result)
{
ffStrbufSet(&result->userShellExe, &instance->state.platform.userShell);
ffStrbufSet(&result->userShellExe, &instance.state.platform.userShell);
if(result->userShellExe.length == 0)
return;
@@ -309,10 +309,8 @@ static void getShellVersion(FFstrbuf* exe, const char* exeName, FFstrbuf* versio
bool fftsGetTerminalVersion(FFstrbuf* processName, FFstrbuf* exe, FFstrbuf* version);
const FFTerminalShellResult* ffDetectTerminalShell(const FFinstance* instance)
const FFTerminalShellResult* ffDetectTerminalShell()
{
FF_UNUSED(instance);
static FFThreadMutex mutex = FF_THREAD_MUTEX_INITIALIZER;
static FFTerminalShellResult result;
static bool init = false;
@@ -350,7 +348,7 @@ const FFTerminalShellResult* ffDetectTerminalShell(const FFinstance* instance)
getTerminalShell(&result, getppid());
getTerminalFromEnv(&result);
getUserShellFromEnv(instance, &result);
getUserShellFromEnv(&result);
ffStrbufClear(&result.shellVersion);
getShellVersion(&result.shellExe, result.shellExeName, &result.shellVersion);
@@ -119,7 +119,7 @@ static bool getTerminalInfoByEnumeratingChildProcesses(FFTerminalShellResult* re
bool fftsGetShellVersion(FFstrbuf* exe, const char* exeName, FFstrbuf* version);
static uint32_t getShellInfo(const FFinstance* instance, FFTerminalShellResult* result, uint32_t pid)
static uint32_t getShellInfo(FFTerminalShellResult* result, uint32_t pid)
{
uint32_t ppid;
@@ -148,7 +148,7 @@ static uint32_t getShellInfo(const FFinstance* instance, FFTerminalShellResult*
ffStrbufClear(&result->shellPrettyName);
ffStrbufClear(&result->shellExe);
result->shellExeName = NULL;
return getShellInfo(instance, result, ppid);
return getShellInfo(result, ppid);
}
ffStrbufClear(&result->shellVersion);
@@ -199,7 +199,7 @@ static uint32_t getShellInfo(const FFinstance* instance, FFTerminalShellResult*
return ppid;
}
static uint32_t getTerminalInfo(const FFinstance* instance, FFTerminalShellResult* result, uint32_t pid)
static uint32_t getTerminalInfo(FFTerminalShellResult* result, uint32_t pid)
{
uint32_t ppid;
@@ -225,7 +225,7 @@ static uint32_t getTerminalInfo(const FFinstance* instance, FFTerminalShellResul
ffStrbufClear(&result->terminalPrettyName);
ffStrbufClear(&result->terminalExe);
result->terminalExeName = "";
return getTerminalInfo(instance, result, ppid);
return getTerminalInfo(result, ppid);
}
if(ffStrbufIgnCaseEqualS(&result->terminalPrettyName, "sihost") ||
@@ -306,10 +306,8 @@ static void getTerminalFromEnv(FFTerminalShellResult* result)
bool fftsGetTerminalVersion(FFstrbuf* processName, FFstrbuf* exe, FFstrbuf* version);
const FFTerminalShellResult* ffDetectTerminalShell(const FFinstance* instance)
const FFTerminalShellResult* ffDetectTerminalShell(void)
{
FF_UNUSED(instance);
static FFThreadMutex mutex = FF_THREAD_MUTEX_INITIALIZER;
static FFTerminalShellResult result;
static bool init = false;
@@ -342,9 +340,9 @@ const FFTerminalShellResult* ffDetectTerminalShell(const FFinstance* instance)
if(!getProcessInfo(0, &ppid, NULL, NULL, NULL))
goto exit;
ppid = getShellInfo(instance, &result, ppid);
ppid = getShellInfo(&result, ppid);
if(ppid)
getTerminalInfo(instance, &result, ppid);
getTerminalInfo(&result, ppid);
if(result.terminalProcessName.length == 0)
getTerminalFromEnv(&result);