2
0
mirror of https://github.com/telegramdesktop/tdesktop synced 2025-08-31 14:38:15 +00:00

Implement system-based dark mode for Windows and Linux

This commit is contained in:
Ilya Fedin
2020-07-14 20:36:55 +04:00
committed by John Preston
parent fc3a9d98c0
commit 47a237c924
12 changed files with 185 additions and 20 deletions

View File

@@ -20,6 +20,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "storage/localstorage.h"
#include "core/crash_reports.h"
#include <QtCore/QOperatingSystemVersion>
#include <QtWidgets/QApplication>
#include <QtWidgets/QDesktopWidget>
#include <QtGui/QDesktopServices>
@@ -382,6 +383,30 @@ std::optional<crl::time> LastUserInputTime() {
return LastTrackedWhen;
}
std::optional<bool> IsDarkMode() {
if (QOperatingSystemVersion::current()
< QOperatingSystemVersion(QOperatingSystemVersion::Windows, 10, 0, 17763)) {
return std::nullopt;
}
LPCWSTR lpKeyName = L"Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize";
LPCWSTR lpValueName = L"AppsUseLightTheme";
HKEY key;
auto result = RegOpenKeyEx(HKEY_CURRENT_USER, lpKeyName, 0, KEY_READ, &key);
if (result != ERROR_SUCCESS) {
return std::nullopt;
}
DWORD value = 0, type = 0, size = sizeof(value);
result = RegQueryValueEx(key, lpValueName, 0, &type, (LPBYTE)&value, &size);
RegCloseKey(key);
if (result != ERROR_SUCCESS) {
return std::nullopt;
}
return value == 0;
}
bool AutostartSupported() {
return !IsWindowsStoreBuild();
}