Fix recursion issue on MacOS.
This commit is contained in:
parent
19059ccaff
commit
92af5107d7
|
@ -593,11 +593,18 @@ auto VTheme::GetResourceName(const QString &root, const QString &iconName) -> QS
|
|||
VTheme::VTheme(QObject *parent)
|
||||
: QObject(parent)
|
||||
{
|
||||
bool isProcessingColorSchemeChange = false;
|
||||
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0)
|
||||
QStyleHints *hints = QGuiApplication::styleHints();
|
||||
connect(hints, &QStyleHints::colorSchemeChanged, this,
|
||||
[this]()
|
||||
auto colorSchemeChangedSlot = [this, &isProcessingColorSchemeChange]()
|
||||
{
|
||||
if (isProcessingColorSchemeChange)
|
||||
{
|
||||
return; // Already processing, avoid recursion
|
||||
}
|
||||
|
||||
isProcessingColorSchemeChange = true;
|
||||
|
||||
VCommonSettings *settings = VAbstractApplication::VApp()->Settings();
|
||||
VThemeMode themeMode = settings->GetThemeMode();
|
||||
if (themeMode == VThemeMode::System && VTheme::NativeDarkThemeAvailable())
|
||||
|
@ -617,23 +624,39 @@ VTheme::VTheme(QObject *parent)
|
|||
}
|
||||
|
||||
ResetThemeSettings();
|
||||
});
|
||||
|
||||
isProcessingColorSchemeChange = false;
|
||||
};
|
||||
|
||||
QStyleHints *hints = QGuiApplication::styleHints();
|
||||
connect(hints, &QStyleHints::colorSchemeChanged, this, colorSchemeChangedSlot);
|
||||
#else
|
||||
if (VTheme::NativeDarkThemeAvailable())
|
||||
{
|
||||
m_darkTheme = IsInDarkTheme();
|
||||
m_themeTimer = new QTimer(this);
|
||||
m_themeTimer->setTimerType(Qt::VeryCoarseTimer);
|
||||
connect(m_themeTimer, &QTimer::timeout, this,
|
||||
[this]()
|
||||
|
||||
auto colorSchemeTimeoutCheck = [this, &isProcessingColorSchemeChange]()
|
||||
{
|
||||
if (isProcessingColorSchemeChange)
|
||||
{
|
||||
return; // Already processing, avoid recursion
|
||||
}
|
||||
|
||||
isProcessingColorSchemeChange = true;
|
||||
|
||||
bool darkTheme = IsInDarkTheme();
|
||||
if (m_darkTheme != darkTheme)
|
||||
{
|
||||
m_darkTheme = darkTheme;
|
||||
ResetThemeSettings();
|
||||
}
|
||||
});
|
||||
|
||||
isProcessingColorSchemeChange = false;
|
||||
};
|
||||
|
||||
connect(m_themeTimer, &QTimer::timeout, this, colorSchemeTimeoutCheck);
|
||||
m_themeTimer->start(V_SECONDS(5));
|
||||
}
|
||||
#endif // QT_VERSION >= QT_VERSION_CHECK(6, 5, 0)
|
||||
|
|
Loading…
Reference in New Issue
Block a user