This commit is contained in:
Mars 2025-03-05 13:44:56 -05:00
parent 55f0027969
commit e4e80568da
4 changed files with 76 additions and 45 deletions

View file

@ -1,4 +1,5 @@
#include <ctime>
#include <expected>
#include <fmt/chrono.h>
#include <fmt/color.h>
#include <fmt/core.h>
@ -37,7 +38,7 @@ namespace {
std::time_t now = std::time(nullptr);
std::tm localTime;
#ifdef __WIN32__
#ifdef _WIN32
if (localtime_s(&localTime, &now) != 0)
ERROR_LOG("localtime_s failed");
#else
@ -53,11 +54,11 @@ namespace {
date.erase(date.begin());
// Append appropriate suffix for the datE
if (date.ends_with("1") && date != "11")
if (date.back() == '1' && date != "11")
date += "st";
else if (date.ends_with("2") && date != "12")
else if (date.back() == '2' && date != "12")
date += "nd";
else if (date.ends_with("3") && date != "13")
else if (date.back() == '3' && date != "13")
date += "rd";
else
date += "th";
@ -89,9 +90,9 @@ namespace {
data.os_version = GetOSVersion();
data.mem_info = GetMemInfo();
// Desktop environment info (not relevant for Windows)
data.desktop_environment = std::nullopt;
data.window_manager = "Windows";
// Desktop environment info
data.desktop_environment = GetDesktopEnvironment();
data.window_manager = GetWindowManager();
// Parallel execution for disk/shell only
auto diskShell = std::async(std::launch::async, [] {
@ -287,7 +288,7 @@ namespace {
DEBUG_LOG("DBus error: {}", std::get<LinuxError>(error));
#endif
#ifdef __WIN32__
#ifdef _WIN32
if (std::holds_alternative<WindowsError>(error))
DEBUG_LOG("WinRT error: {}", to_string(std::get<WindowsError>(error).message()));
#endif

View file

@ -1,4 +1,4 @@
#ifdef __WIN32__
#ifdef _WIN32
// clang-format off
#define WIN32_LEAN_AND_MEAN
@ -11,6 +11,7 @@
#include <cstring>
// clang-format on
#include <guiddef.h>
#include <winrt/Windows.Foundation.h>
#include <winrt/Windows.Media.Control.h>
#include <winrt/base.h>
@ -113,7 +114,7 @@ namespace {
while (true) {
if (pe32.th32ProcessID == pid) {
// Explicitly cast array to string to avoid implicit array decay
processName = std::string(static_cast<const char*>(pe32.szExeFile));
processName = string(reinterpret_cast<const char*>(pe32.szExeFile));
break;
}
@ -239,7 +240,7 @@ fn GetWindowManager() -> string {
if (windowManager.empty()) {
BOOL compositionEnabled = FALSE;
if (SUCCEEDED(DwmIsCompositionEnabled(&compositionEnabled)))
windowManager = compositionEnabled ? "Desktop Window Manager" : "Windows Manager (Basic)";
windowManager = compositionEnabled ? "DWM" : "Windows Manager (Basic)";
else
windowManager = "Windows Manager";
}
@ -252,8 +253,12 @@ fn GetDesktopEnvironment() -> optional<string> {
const string buildStr =
GetRegistryValue(HKEY_LOCAL_MACHINE, R"(SOFTWARE\Microsoft\Windows NT\CurrentVersion)", "CurrentBuildNumber");
if (buildStr.empty())
DEBUG_LOG("buildStr: {}", buildStr);
if (buildStr.empty()) {
DEBUG_LOG("Failed to get CurrentBuildNumber from registry");
return std::nullopt;
}
try {
const i32 build = stoi(buildStr);
@ -287,7 +292,10 @@ fn GetDesktopEnvironment() -> optional<string> {
// Older versions
return "Classic";
} catch (...) { return std::nullopt; }
} catch (...) {
DEBUG_LOG("Failed to parse CurrentBuildNumber");
return std::nullopt;
}
}
fn GetShell() -> string {

View file

@ -4,7 +4,9 @@
#include <cstdint>
#include <string>
#ifdef __WIN32__
#ifdef _WIN32
#include <guiddef.h>
#include <variant>
#include <winrt/base.h>
#endif
@ -155,7 +157,7 @@ using LinuxError = std::string;
* @brief Represents a macOS-specific error.
*/
using MacError = std::string;
#elif defined(__WIN32__)
#elif defined(_WIN32)
/**
* @typedef WindowsError
* @brief Represents a Windows-specific error.
@ -170,7 +172,7 @@ using NowPlayingError = std::variant<
LinuxError
#elif defined(__APPLE__)
MacError
#elif defined(__WIN32__)
#elif defined(_WIN32)
WindowsError
#endif
>;