format code

This commit is contained in:
dranik
2026-05-29 22:57:54 +03:00
parent 446e7b6a8e
commit 7eecc3667f
+32 -31
View File
@@ -12,43 +12,42 @@
#include "logger.h" #include "logger.h"
namespace namespace {
Logger logger("WindowsUtils");
constexpr const wchar_t kThemeWatcherClassName[] = L"AmneziaVpnThemeWatcher";
struct ThemeObserverState
{ {
Logger logger("WindowsUtils"); std::function<void()> callback;
HWND hwnd = nullptr;
};
constexpr const wchar_t kThemeWatcherClassName[] = L"AmneziaVpnThemeWatcher"; ThemeObserverState g_themeObserver;
struct ThemeObserverState bool registryUsesDarkTheme(const QSettings &settings, const QString &lightThemeKey)
{ {
std::function<void()> callback; if (settings.contains(lightThemeKey)) {
HWND hwnd = nullptr; return settings.value(lightThemeKey).toInt() != 1;
};
ThemeObserverState g_themeObserver;
bool registryUsesDarkTheme(const QSettings &settings, const QString &lightThemeKey)
{
if (settings.contains(lightThemeKey)) {
return settings.value(lightThemeKey).toInt() != 1;
}
return false;
} }
return false;
}
LRESULT CALLBACK themeWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) LRESULT CALLBACK themeWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{ {
Q_UNUSED(wParam); Q_UNUSED(wParam);
if (msg == WM_SETTINGCHANGE && lParam != 0) { if (msg == WM_SETTINGCHANGE && lParam != 0) {
const wchar_t *section = reinterpret_cast<const wchar_t *>(lParam); const wchar_t *section = reinterpret_cast<const wchar_t *>(lParam);
if (wcscmp(section, L"ImmersiveColorSet") == 0 || wcscmp(section, L"WindowsThemeElement") == 0) { if (wcscmp(section, L"ImmersiveColorSet") == 0 || wcscmp(section, L"WindowsThemeElement") == 0) {
if (g_themeObserver.callback) { if (g_themeObserver.callback) {
g_themeObserver.callback(); g_themeObserver.callback();
}
} }
} }
return DefWindowProcW(hwnd, msg, wParam, lParam);
} }
return DefWindowProcW(hwnd, msg, wParam, lParam);
}
} // namespace } // namespace
constexpr const int WINDOWS_11_BUILD = constexpr const int WINDOWS_11_BUILD =
@@ -56,9 +55,11 @@ constexpr const int WINDOWS_11_BUILD =
QString WindowsUtils::getErrorMessage(quint32 code) { QString WindowsUtils::getErrorMessage(quint32 code) {
LPSTR messageBuffer = nullptr; LPSTR messageBuffer = nullptr;
size_t size = size_t size = FormatMessageA(
FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |
nullptr, code, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPSTR)&messageBuffer, 0, nullptr); FORMAT_MESSAGE_IGNORE_INSERTS,
nullptr, code, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPSTR)&messageBuffer, 0, nullptr);
std::string message(messageBuffer, size); std::string message(messageBuffer, size);
QString result(message.c_str()); QString result(message.c_str());