Skip to content

Commit

Permalink
Merge #265 [stable-3.13] nmc/0000-DarkMode_Disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
memurats committed Jul 17, 2024
2 parents 6958e90 + 999b017 commit 048587c
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 19 deletions.
27 changes: 27 additions & 0 deletions src/gui/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,33 @@ int main(int argc, char **argv)

OCC::Application app(argc, argv);

//NMC custoization, enforce our palette to avoid dark mode colors
QPalette palette = app.palette();

palette.setColor(QPalette::WindowText, QColor(0, 0, 0));
palette.setColor(QPalette::Button, QColor(236, 236, 236));
palette.setColor(QPalette::Light, QColor(255, 255, 255));
palette.setColor(QPalette::Midlight, QColor(245, 245, 245));
palette.setColor(QPalette::Dark, QColor(191, 191, 191));
palette.setColor(QPalette::Mid, QColor(168, 168, 168));
palette.setColor(QPalette::Text, QColor(0, 0, 0));
palette.setColor(QPalette::BrightText, QColor(255, 255, 255));
palette.setColor(QPalette::ButtonText, QColor(0, 0, 0));
palette.setColor(QPalette::Base, QColor(255, 255, 255));
palette.setColor(QPalette::Window, QColor(236, 236, 236));
palette.setColor(QPalette::Shadow, QColor(0, 0, 0));
palette.setColor(QPalette::Highlight, QColor(179, 215, 255));
palette.setColor(QPalette::HighlightedText, QColor(0, 0, 0));
palette.setColor(QPalette::Link, QColor(0, 104, 218));
palette.setColor(QPalette::LinkVisited, QColor(255, 0, 255));
palette.setColor(QPalette::AlternateBase, QColor(245, 245, 245));
palette.setColor(QPalette::NoRole, QColor(0, 0, 0));
palette.setColor(QPalette::ToolTipBase, QColor(255, 255, 255));
palette.setColor(QPalette::ToolTipText, QColor(0, 0, 0));
palette.setColor(QPalette::PlaceholderText, QColor(0, 0, 0));

app.setPalette(palette);

#ifdef Q_OS_WIN
// The Windows style still has pixelated elements with Qt 5.6,
// it's recommended to use the Fusion style in this case, even
Expand Down
31 changes: 16 additions & 15 deletions src/libsync/theme.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,6 @@ QString Theme::aboutInfo() const
//: Example text: "<p>Nextcloud Desktop Client</p>" (%1 is the application name)
auto devString = QString(tr("<p>%1 Desktop Client</p><p>Version %1. For more information please click <a href='%2'>here</a>.</p>") + QStringLiteral(" (%3)"))
.arg(APPLICATION_NAME, QString::fromLatin1(MIRALL_STRINGIFY(MIRALL_VERSION)), helpUrl(), osName);


devString += tr("<p><small>Using virtual files plugin: %1</small></p>").arg(Vfs::modeToString(bestAvailableVfsMode()));
devString += QStringLiteral("<br>%1").arg(QSysInfo::productType() % QLatin1Char('-') % QSysInfo::kernelVersion());
Expand Down Expand Up @@ -818,7 +817,8 @@ double Theme::getColorDarkness(const QColor &color)

bool Theme::isDarkColor(const QColor &color)
{
return getColorDarkness(color) > 0.5;
Q_UNUSED(color)
return false; //getColorDarkness(color) > 0.5;
}

QColor Theme::getBackgroundAwareLinkColor(const QColor &backgroundColor)
Expand Down Expand Up @@ -942,19 +942,20 @@ QPalette Theme::systemPalette()

bool Theme::darkMode()
{
connectToPaletteSignal();
// Windows: Check registry for dark mode
#if defined(Q_OS_WIN)
const auto darkModeSubkey = QStringLiteral("Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize");
if (Utility::registryKeyExists(HKEY_CURRENT_USER, darkModeSubkey) &&
!Utility::registryGetKeyValue(HKEY_CURRENT_USER, darkModeSubkey, QStringLiteral("AppsUseLightTheme")).toBool()) {
return true;
}

return false;
#else
return Theme::isDarkColor(QGuiApplication::palette().window().color());
#endif
// connectToPaletteSignal();
// // Windows: Check registry for dark mode
// #if defined(Q_OS_WIN)
// const auto darkModeSubkey = QStringLiteral("Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize");
// if (Utility::registryKeyExists(HKEY_CURRENT_USER, darkModeSubkey) &&
// !Utility::registryGetKeyValue(HKEY_CURRENT_USER, darkModeSubkey, QStringLiteral("AppsUseLightTheme")).toBool()) {
// return true;
// }

// return false;
// #else
// return Theme::isDarkColor(QGuiApplication::palette().window().color());
// #endif
return false;
}

void Theme::setOverrideServerUrl(const QString &overrideServerUrl)
Expand Down
12 changes: 8 additions & 4 deletions test/testtheme.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ private slots:

const auto iconPath = OCC::Theme::hidpiFileName(iconName + ".png", backgroundColor, &paintDevice);

QCOMPARE(iconPath, ":/client/theme/white/" + iconName + ".png");
Q_UNUSED(iconPath)
//QCOMPARE(iconPath, ":/client/theme/white/" + iconName + ".png");
}

void testHidpiFileName_lightBackground_returnPathToBlackIcon()
Expand All @@ -61,7 +62,8 @@ private slots:

const auto iconPath = OCC::Theme::hidpiFileName(iconName + ".png", backgroundColor, &paintDevice);

QCOMPARE(iconPath, ":/client/theme/white/" + iconName + "@2x.png");
Q_UNUSED(iconPath)
//QCOMPARE(iconPath, ":/client/theme/white/" + iconName + "@2x.png");
}

void testIsDarkColor_nextcloudBlue_returnTrue()
Expand All @@ -70,7 +72,8 @@ private slots:

const auto result = OCC::Theme::isDarkColor(color);

QCOMPARE(result, true);
Q_UNUSED(result)
//QCOMPARE(result, true);
}

void testIsDarkColor_lightColor_returnFalse()
Expand All @@ -88,7 +91,8 @@ private slots:

const auto result = OCC::Theme::isDarkColor(color);

QCOMPARE(result, true);
Q_UNUSED(result)
//QCOMPARE(result, true);
}

void testIsHidpi_hidpi_returnTrue()
Expand Down

0 comments on commit 048587c

Please sign in to comment.