diff --git a/include/FramelessHelper/Core/private/sysapiloader_p.h b/include/FramelessHelper/Core/private/sysapiloader_p.h index 3a1b4af..698f751 100644 --- a/include/FramelessHelper/Core/private/sysapiloader_p.h +++ b/include/FramelessHelper/Core/private/sysapiloader_p.h @@ -25,8 +25,6 @@ #pragma once #include "framelesshelpercore_global.h" -#include -#include FRAMELESSHELPER_BEGIN_NAMESPACE @@ -54,10 +52,6 @@ public: { return reinterpret_cast(get(function)); } - -private: - static inline QMutex m_mutex{}; - static inline QHash> m_functionCache = {}; }; FRAMELESSHELPER_END_NAMESPACE diff --git a/src/core/framelessmanager.cpp b/src/core/framelessmanager.cpp index fdc7d50..1515982 100644 --- a/src/core/framelessmanager.cpp +++ b/src/core/framelessmanager.cpp @@ -365,7 +365,9 @@ void FramelessManagerPrivate::initialize() flagSet = true; // Set a global flag so that people can check whether FramelessHelper is being // used without actually accessing the FramelessHelper interface. - qApp->setProperty(kGlobalFlagVarName, FramelessHelper::Core::version().version); + const int ver = FramelessHelper::Core::version().version; + qputenv(kGlobalFlagVarName, QByteArray::number(ver)); + qApp->setProperty(kGlobalFlagVarName, ver); } } diff --git a/src/core/sysapiloader.cpp b/src/core/sysapiloader.cpp index 73993f1..def8b84 100644 --- a/src/core/sysapiloader.cpp +++ b/src/core/sysapiloader.cpp @@ -23,6 +23,8 @@ */ #include "sysapiloader_p.h" +#include +#include #ifdef Q_OS_WINDOWS # include #else @@ -37,6 +39,14 @@ Q_LOGGING_CATEGORY(lcSysApiLoader, "wangwenx190.framelesshelper.core.sysapiloade #define WARNING qCWarning(lcSysApiLoader) #define CRITICAL qCCritical(lcSysApiLoader) +struct SysApiLoaderData +{ + QMutex mutex; + QHash> functionCache = {}; +}; + +Q_GLOBAL_STATIC(SysApiLoaderData, g_loaderData) + Q_GLOBAL_STATIC(SysApiLoader, g_sysApiLoader) SysApiLoader::SysApiLoader(QObject *parent) : QObject(parent) @@ -91,17 +101,17 @@ bool SysApiLoader::isAvailable(const QString &library, const QString &function) if (library.isEmpty() || function.isEmpty()) { return false; } - const QMutexLocker locker(&m_mutex); - if (m_functionCache.contains(function)) { - return m_functionCache.value(function).has_value(); + const QMutexLocker locker(&g_loaderData()->mutex); + if (g_loaderData()->functionCache.contains(function)) { + return g_loaderData()->functionCache.value(function).has_value(); } const QFunctionPointer symbol = SysApiLoader::resolve(library, function); if (symbol) { - m_functionCache.insert(function, symbol); + g_loaderData()->functionCache.insert(function, symbol); DEBUG << "Successfully loaded" << function << "from" << library; return true; } - m_functionCache.insert(function, std::nullopt); + g_loaderData()->functionCache.insert(function, std::nullopt); WARNING << "Failed to load" << function << "from" << library; return false; } @@ -112,9 +122,9 @@ QFunctionPointer SysApiLoader::get(const QString &function) if (function.isEmpty()) { return nullptr; } - const QMutexLocker locker(&m_mutex); - if (m_functionCache.contains(function)) { - return m_functionCache.value(function).value_or(nullptr); + const QMutexLocker locker(&g_loaderData()->mutex); + if (g_loaderData()->functionCache.contains(function)) { + return g_loaderData()->functionCache.value(function).value_or(nullptr); } return nullptr; }