diff --git a/flake.nix b/flake.nix index ea81a5b..b70ec89 100644 --- a/flake.nix +++ b/flake.nix @@ -29,12 +29,16 @@ else pkgs # TODO: Remove when fixed on darwin ); [ - curl fmt glib tomlplusplus yyjson ] + ++ ( + if !stdenv.isDarwin && system == "x86_64-linux" + then [pkgsStatic.curl] + else [pkgs.curl] + ) ++ linuxPkgs ++ darwinPkgs; diff --git a/src/config/weather.cpp b/src/config/weather.cpp index 7ba6770..27fff94 100644 --- a/src/config/weather.cpp +++ b/src/config/weather.cpp @@ -1,4 +1,5 @@ #include +#include #include #include #include @@ -48,21 +49,17 @@ fn WriteCacheToFile(const WeatherOutput& data) -> Result<> { return Ok(); } -fn WriteCallback(void* contents, size_t size, size_t nmemb, std::string* buffer) - -> size_t { - size_t realsize = size * nmemb; - - buffer->append(static_cast(contents), realsize); - - return realsize; +fn WriteCallback(void* contents, size_t size, size_t nmemb, std::string* str) -> size_t { + size_t totalSize = size * nmemb; + str->append(static_cast(contents), totalSize); + return totalSize; } // Function to make API request fn MakeApiRequest(const std::string& url) -> Result { - fmt::println("Making API request..."); + fmt::println("Making API request to URL: {}", url); CURL* curl = curl_easy_init(); - std::string responseBuffer; if (curl) { @@ -72,17 +69,16 @@ fn MakeApiRequest(const std::string& url) -> Result { CURLcode res = curl_easy_perform(curl); curl_easy_cleanup(curl); - if (res != CURLE_OK) - return Error(fmt::format( - "Failed to perform cURL request: {}", curl_easy_strerror(res) - )); + if (res != CURLE_OK) { + return Error(fmt::format("Failed to perform cURL request: {}", curl_easy_strerror(res))); + } + + fmt::println("Received response from API. Response size: {}", responseBuffer.size()); - fmt::println("Received response from API."); - // Parse the JSON response WeatherOutput output = rfl::json::read(responseBuffer).value(); - return Ok(output); + return Ok(output); // Return an empty result for now } return Error("Failed to initialize cURL.");