From fae0bccc9cc5eaf912ca63f4b0e1aea9ee30bde5 Mon Sep 17 00:00:00 2001 From: John Preston Date: Tue, 17 Jul 2018 15:44:58 +0300 Subject: [PATCH] Don't use registry quiet hours entry any more. In the latest Windows 10 those settings aren't stored in registry. --- .../win/notifications_manager_win.cpp | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/Telegram/SourceFiles/platform/win/notifications_manager_win.cpp b/Telegram/SourceFiles/platform/win/notifications_manager_win.cpp index ed6bec3759..236046e621 100644 --- a/Telegram/SourceFiles/platform/win/notifications_manager_win.cpp +++ b/Telegram/SourceFiles/platform/win/notifications_manager_win.cpp @@ -589,9 +589,27 @@ namespace { bool QuietHoursEnabled = false; DWORD QuietHoursValue = 0; +bool useQuietHoursRegistryEntry() { + // Taken from QSysInfo. + OSVERSIONINFO result = { sizeof(OSVERSIONINFO), 0, 0, 0, 0,{ '\0' } }; + if (const auto library = GetModuleHandle(L"ntdll.dll")) { + using RtlGetVersionFunction = NTSTATUS(NTAPI*)(LPOSVERSIONINFO); + const auto RtlGetVersion = reinterpret_cast( + GetProcAddress(library, "RtlGetVersion")); + if (RtlGetVersion) { + RtlGetVersion(&result); + } + } + // At build 17134 (Redstone 4) the "Quiet hours" was replaced + // by "Focus assist" and it looks like it doesn't use registry. + return (result.dwMajorVersion == 10 + && result.dwMinorVersion == 0 + && result.dwBuildNumber < 17134); +} + // Thanks https://stackoverflow.com/questions/35600128/get-windows-quiet-hours-from-win32-or-c-sharp-api void queryQuietHours() { - if (QSysInfo::windowsVersion() < QSysInfo::WV_WINDOWS10) { + if (!useQuietHoursRegistryEntry()) { // There are quiet hours in Windows starting from Windows 8.1 // But there were several reports about the notifications being shut // down according to the registry while no quiet hours were enabled.