Skip to content

Commit

Permalink
fix: do not apply system theme on launch
Browse files Browse the repository at this point in the history
Closes PrismLauncher#490

Regression introduced by PrismLauncher#249

Signed-off-by: Sefa Eyeoglu <contact@scrumplex.net>
  • Loading branch information
Scrumplex authored and pull[bot] committed Apr 8, 2023
1 parent 56c206f commit 48be350
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 17 deletions.
8 changes: 3 additions & 5 deletions launcher/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -830,9 +830,7 @@ Application::Application(int &argc, char **argv) : QApplication(argc, argv)
}
});

{
applyCurrentlySelectedTheme();
}
applyCurrentlySelectedTheme(true);

updateCapabilities();

Expand Down Expand Up @@ -1107,9 +1105,9 @@ QList<ITheme*> Application::getValidApplicationThemes()
return m_themeManager->getValidApplicationThemes();
}

void Application::applyCurrentlySelectedTheme()
void Application::applyCurrentlySelectedTheme(bool initial)
{
m_themeManager->applyCurrentlySelectedTheme();
m_themeManager->applyCurrentlySelectedTheme(initial);
}

void Application::setApplicationTheme(const QString& name)
Expand Down
2 changes: 1 addition & 1 deletion launcher/Application.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ class Application : public QApplication

void setIconTheme(const QString& name);

void applyCurrentlySelectedTheme();
void applyCurrentlySelectedTheme(bool initial = false);

QList<ITheme*> getValidApplicationThemes();

Expand Down
2 changes: 1 addition & 1 deletion launcher/ui/themes/ITheme.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
#include <QDir>
#include "Application.h"

void ITheme::apply()
void ITheme::apply(bool)
{
APPLICATION->setStyleSheet(QString());
QApplication::setStyle(QStyleFactory::create(qtTheme()));
Expand Down
2 changes: 1 addition & 1 deletion launcher/ui/themes/ITheme.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class QStyle;
class ITheme {
public:
virtual ~ITheme() {}
virtual void apply();
virtual void apply(bool initial);
virtual QString id() = 0;
virtual QString name() = 0;
virtual bool hasStyleSheet() = 0;
Expand Down
8 changes: 6 additions & 2 deletions launcher/ui/themes/SystemTheme.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,13 @@ SystemTheme::SystemTheme()
themeDebugLog() << "System theme not found, defaulted to Fusion";
}

void SystemTheme::apply()
void SystemTheme::apply(bool initial)
{
ITheme::apply();
// See https://github.com/MultiMC/Launcher/issues/1790
// or https://github.com/PrismLauncher/PrismLauncher/issues/490
if (initial)
return;
ITheme::apply(initial);
}

QString SystemTheme::id()
Expand Down
2 changes: 1 addition & 1 deletion launcher/ui/themes/SystemTheme.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class SystemTheme : public ITheme {
public:
SystemTheme();
virtual ~SystemTheme() {}
void apply() override;
void apply(bool initial) override;

QString id() override;
QString name() override;
Expand Down
8 changes: 4 additions & 4 deletions launcher/ui/themes/ThemeManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,22 +116,22 @@ void ThemeManager::setIconTheme(const QString& name)
QIcon::setThemeName(name);
}

void ThemeManager::applyCurrentlySelectedTheme()
void ThemeManager::applyCurrentlySelectedTheme(bool initial)
{
setIconTheme(APPLICATION->settings()->get("IconTheme").toString());
themeDebugLog() << "<> Icon theme set.";
setApplicationTheme(APPLICATION->settings()->get("ApplicationTheme").toString());
setApplicationTheme(APPLICATION->settings()->get("ApplicationTheme").toString(), initial);
themeDebugLog() << "<> Application theme set.";
}

void ThemeManager::setApplicationTheme(const QString& name)
void ThemeManager::setApplicationTheme(const QString& name, bool initial)
{
auto systemPalette = qApp->palette();
auto themeIter = m_themes.find(name);
if (themeIter != m_themes.end()) {
auto& theme = themeIter->second;
themeDebugLog() << "applying theme" << theme->name();
theme->apply();
theme->apply(initial);
} else {
themeWarningLog() << "Tried to set invalid theme:" << name;
}
Expand Down
4 changes: 2 additions & 2 deletions launcher/ui/themes/ThemeManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ class ThemeManager {

QList<ITheme*> getValidApplicationThemes();
void setIconTheme(const QString& name);
void applyCurrentlySelectedTheme();
void setApplicationTheme(const QString& name);
void applyCurrentlySelectedTheme(bool initial = false);
void setApplicationTheme(const QString& name, bool initial = false);

/// <summary>
/// Returns the cat based on selected cat and with events (Birthday, XMas, etc.)
Expand Down

0 comments on commit 48be350

Please sign in to comment.