diff --git a/src/OS/haiku.cpp b/src/OS/haiku.cpp deleted file mode 100644 index ebc2e26..0000000 --- a/src/OS/haiku.cpp +++ /dev/null @@ -1,155 +0,0 @@ -#ifdef __HAIKU__ - -// clang-format off -#include // For BAppFileInfo and version_info -#include // B_OK, strerror, status_t -#include // For BFile -#include // get_system_info, system_info -#include // PATH_MAX -#include // std::strlen -#include // DBUS_TYPE_* -#include // DBUS_BUS_SESSION -#include // BPackageKit::BPackageInfoSet -#include // BPackageKit::BPackageInfo -#include // BPackageKit::BPackageRoster -#include // ucred, getsockopt, SOL_SOCKET, SO_PEERCRED -#include // statvfs -#include // std::move - -#include "src/core/package.hpp" -#include "src/util/defs.hpp" -#include "src/util/error.hpp" -#include "src/util/helpers.hpp" -#include "src/util/logging.hpp" -#include "src/util/types.hpp" - -#include "os.hpp" -// clang-format on - -using namespace util::types; -using util::error::DracError, util::error::DracErrorCode; -using util::helpers::GetEnv; - -namespace os { - fn GetOSVersion() -> Result { - BFile file; - status_t status = file.SetTo("/boot/system/lib/libbe.so", B_READ_ONLY); - - if (status != B_OK) - return Err(DracError(DracErrorCode::InternalError, "Error opening /boot/system/lib/libbe.so")); - - BAppFileInfo appInfo; - status = appInfo.SetTo(&file); - - if (status != B_OK) - return Err(DracError(DracErrorCode::InternalError, "Error initializing BAppFileInfo")); - - version_info versionInfo; - status = appInfo.GetVersionInfo(&versionInfo, B_APP_VERSION_KIND); - - if (status != B_OK) - return Err(DracError(DracErrorCode::InternalError, "Error reading version info attribute")); - - String versionShortString = versionInfo.short_info; - - if (versionShortString.empty()) - return Err(DracError(DracErrorCode::InternalError, "Version info short_info is empty")); - - return std::format("Haiku {}", versionShortString); - } - - fn GetMemInfo() -> Result { - system_info sysinfo; - const status_t status = get_system_info(&sysinfo); - - if (status != B_OK) - return Err(DracError(DracErrorCode::InternalError, std::format("get_system_info failed: {}", strerror(status)))); - - return static_cast(sysinfo.max_pages) * B_PAGE_SIZE; - } - - fn GetNowPlaying() -> Result { - return Err(DracError(DracErrorCode::NotSupported, "Now playing is not supported on Haiku")); - } - - fn GetWindowManager() -> Result { - return "app_server"; - } - - fn GetDesktopEnvironment() -> Result { - return "Haiku Desktop Environment"; - } - - fn GetShell() -> Result { - if (const Result shellPath = GetEnv("SHELL")) { - // clang-format off - constexpr Array, 5> shellMap {{ - { "bash", "Bash" }, - { "zsh", "Zsh" }, - { "fish", "Fish" }, - { "nu", "Nushell" }, - { "sh", "SH" }, // sh last because other shells contain "sh" - }}; - // clang-format on - - for (const auto& [exe, name] : shellMap) - if (shellPath->contains(exe)) - return String(name); - - return *shellPath; // fallback to the raw shell path - } - - return Err(DracError(DracErrorCode::NotFound, "Could not find SHELL environment variable")); - } - - fn GetHost() -> Result { - Array hostnameBuffer {}; - - if (gethostname(hostnameBuffer.data(), hostnameBuffer.size()) != 0) - return Err(DracError( - DracErrorCode::ApiUnavailable, std::format("gethostname() failed: {} (errno {})", strerror(errno), errno) - )); - - hostnameBuffer.at(HOST_NAME_MAX) = '\0'; - - return String(hostnameBuffer.data(), hostnameBuffer.size()); - } - - fn GetKernelVersion() -> Result { - system_info sysinfo; - const status_t status = get_system_info(&sysinfo); - - if (status != B_OK) - return Err(DracError(DracErrorCode::InternalError, std::format("get_system_info failed: {}", strerror(status)))); - - return std::to_string(sysinfo.kernel_version); - } - - fn GetDiskUsage() -> Result { - struct statvfs stat; - - if (statvfs("/boot", &stat) == -1) - return Err(DracError::withErrno(std::format("Failed to get filesystem stats for '/boot' (statvfs call failed)"))); - - return DiskSpace { - .used_bytes = (stat.f_blocks * stat.f_frsize) - (stat.f_bfree * stat.f_frsize), - .total_bytes = stat.f_blocks * stat.f_frsize, - }; - } -} // namespace os - -namespace package { - fn GetHaikuCount() -> Result { - BPackageKit::BPackageRoster roster; - BPackageKit::BPackageInfoSet packageList; - - const status_t status = roster.GetActivePackages(BPackageKit::B_PACKAGE_INSTALLATION_LOCATION_SYSTEM, packageList); - - if (status != B_OK) - return Err(DracError(DracErrorCode::ApiUnavailable, "Failed to get active package list")); - - return static_cast(packageList.CountInfos()); - } -} // namespace package - -#endif // __HAIKU__ diff --git a/src/Services/Weather/MetNoService.cpp b/src/Services/Weather/MetNoService.cpp index 6703b77..7ee1a98 100644 --- a/src/Services/Weather/MetNoService.cpp +++ b/src/Services/Weather/MetNoService.cpp @@ -3,6 +3,7 @@ #include "MetNoService.hpp" #include // std::chrono::{system_clock, minutes, seconds} +#include // std::tm, std::timegm #include // CURL, CURLcode, CURLOPT_*, CURLE_OK #include // curl_easy_init, curl_easy_setopt, curl_easy_perform, curl_easy_strerror, curl_easy_cleanup #include // std::format @@ -216,9 +217,9 @@ namespace { return 0; #ifdef _WIN32 - return static_cast(_mkgmtime(&time)); + return static_cast(_mkgmtime(&time)); #else - return static_cast(timegm(&time)); + return static_cast(timegm(&time)); #endif } } // namespace @@ -297,4 +298,4 @@ fn MetNoService::getWeatherInfo() const -> util::types::Result { return Err(writeResult.error()); return out; -} \ No newline at end of file +} diff --git a/src/Services/Weather/OpenMeteoService.cpp b/src/Services/Weather/OpenMeteoService.cpp index 327fcdd..0d78338 100644 --- a/src/Services/Weather/OpenMeteoService.cpp +++ b/src/Services/Weather/OpenMeteoService.cpp @@ -2,13 +2,13 @@ #include "OpenMeteoService.hpp" -#include -#include -#include -#include -#include -#include -#include +#include // std::chrono::{system_clock, minutes, seconds} +#include // std::tm, std::timegm +#include // CURL, CURLcode, CURLOPT_*, CURLE_OK +#include // curl_easy_init, curl_easy_setopt, curl_easy_perform, curl_easy_strerror, curl_easy_cleanup +#include // std::format +#include // glz::read +#include // std::istringstream #include "Util/Caching.hpp" #include "Util/Error.hpp" @@ -60,31 +60,31 @@ struct glz::meta : weather::CurrentW namespace { using glz::opts; using util::error::DracError, util::error::DracErrorCode; - using util::types::usize, util::types::Err; + using util::types::usize, util::types::Err, util::types::String; constexpr opts glazeOpts = { .error_on_unknown_keys = false }; - fn WriteCallback(void* contents, size_t size, size_t nmemb, std::string* str) -> size_t { - size_t totalSize = size * nmemb; + fn WriteCallback(void* contents, usize size, usize nmemb, String* str) -> usize { + usize totalSize = size * nmemb; str->append(static_cast(contents), totalSize); return totalSize; } - fn parse_iso8601_to_epoch(const std::string& iso8601) -> usize { + fn parse_iso8601_to_epoch(const String& iso8601) -> usize { std::tm time = {}; std::istringstream stream(iso8601); stream >> std::get_time(&time, "%Y-%m-%dT%H:%M"); if (stream.fail()) return 0; #ifdef _WIN32 - return static_cast(_mkgmtime(&time)); + return static_cast(_mkgmtime(&time)); #else - return static_cast(timegm(&time)); + return static_cast(timegm(&time)); #endif } } // namespace -OpenMeteoService::OpenMeteoService(double lat, double lon, std::string units) +OpenMeteoService::OpenMeteoService(f64 lat, f64 lon, String units) : m_lat(lat), m_lon(lon), m_units(std::move(units)) {} fn OpenMeteoService::getWeatherInfo() const -> util::types::Result { @@ -153,4 +153,4 @@ fn OpenMeteoService::getWeatherInfo() const -> util::types::Result