Move theme detection into Application

* Add function to Application to quickly determine if in light or dark theme
* Add kpxcApp symbol
* Explicitly define main function for GUI tests to improve performance and use custom Application.
This commit is contained in:
Jonathan White 2020-03-08 22:45:51 -04:00
parent a8c02fdc3c
commit 1d7ef5d4eb
7 changed files with 77 additions and 30 deletions

View file

@ -18,8 +18,14 @@
*/
#include "Application.h"
#include "MainWindow.h"
#include "autotype/AutoType.h"
#include "core/Config.h"
#include "core/Global.h"
#include "gui/MainWindow.h"
#include "gui/osutils/OSUtils.h"
#include "gui/styles/dark/DarkStyle.h"
#include "gui/styles/light/LightStyle.h"
#include <QFileInfo>
#include <QFileOpenEvent>
@ -28,9 +34,6 @@
#include <QStandardPaths>
#include <QtNetwork/QLocalSocket>
#include "autotype/AutoType.h"
#include "core/Global.h"
#if defined(Q_OS_WIN) || (defined(Q_OS_UNIX) && !defined(Q_OS_MACOS))
#include "core/OSEventFilter.h"
#endif
@ -65,6 +68,26 @@ Application::Application(int& argc, char** argv)
registerUnixSignals();
#endif
QString appTheme = config()->get("GUI/ApplicationTheme").toString();
if (appTheme == "auto") {
if (osUtils->isDarkMode()) {
setStyle(new DarkStyle);
m_darkTheme = true;
} else {
setStyle(new LightStyle);
}
} else if (appTheme == "light") {
setStyle(new LightStyle);
} else if (appTheme == "dark") {
setStyle(new DarkStyle);
m_darkTheme = true;
} else {
// Classic mode, only check for dark theme when not on Windows
#ifndef Q_OS_WIN
m_darkTheme = osUtils->isDarkMode();
#endif
}
QString userName = qgetenv("USER");
if (userName.isEmpty()) {
userName = qgetenv("USERNAME");
@ -281,3 +304,8 @@ bool Application::sendFileNamesToRunningInstance(const QStringList& fileNames)
const bool disconnected = client.waitForDisconnected(WaitTimeoutMSec);
return writeOk && disconnected;
}
bool Application::isDarkTheme() const
{
return m_darkTheme;
}