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:
@@ -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();
|
||||
}
|
||||
|
Reference in New Issue
Block a user