From 5f5a2a3ef25cedc78ea6dacc63c869c1639998dc Mon Sep 17 00:00:00 2001
From: Ilya Fedin <fedin-ilja2010@ya.ru>
Date: Sat, 25 Jan 2025 21:48:35 +0400
Subject: [PATCH] Check high contrast theme for auto dark mode on Windows

---
 Telegram/SourceFiles/platform/win/specific_win.cpp | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/Telegram/SourceFiles/platform/win/specific_win.cpp b/Telegram/SourceFiles/platform/win/specific_win.cpp
index 9b8b959e0..488d9a1cb 100644
--- a/Telegram/SourceFiles/platform/win/specific_win.cpp
+++ b/Telegram/SourceFiles/platform/win/specific_win.cpp
@@ -399,6 +399,13 @@ std::optional<bool> IsDarkMode() {
 		return std::nullopt;
 	}
 
+	HIGHCONTRAST hcf = {};
+	hcf.cbSize = static_cast<UINT>(sizeof(HIGHCONTRAST));
+	if (SystemParametersInfo(SPI_GETHIGHCONTRAST, hcf.cbSize, &hcf, FALSE)
+			&& (hcf.dwFlags & HCF_HIGHCONTRASTON)) {
+		return std::nullopt;
+	}
+
 	const auto keyName = L""
 		"Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize";
 	const auto valueName = L"AppsUseLightTheme";