diff --git a/src/dusk/ui/prelaunch.cpp b/src/dusk/ui/prelaunch.cpp index ef6b6e5709..7838674a58 100644 --- a/src/dusk/ui/prelaunch.cpp +++ b/src/dusk/ui/prelaunch.cpp @@ -262,6 +262,10 @@ std::string update_release_label(const update_check::Release& release) { return std::string(tagName); } +void download_update(Modal& modal) { + +} + void open_update_release() { if (!sUpdateCheckResult.has_value() || sUpdateCheckResult->status != update_check::Status::UpdateAvailable) @@ -269,14 +273,38 @@ void open_update_release() { return; } - const std::string url = sUpdateCheckResult->latest.htmlUrl; - if (url.empty()) { - PrelaunchLog.warn("Update is available, but the release did not include a download URL"); - return; - } - if (!SDL_OpenURL(url.c_str())) { - PrelaunchLog.warn("Failed to open update URL '{}': {}", url, SDL_GetError()); - } + std::string updateTag = sUpdateCheckResult->latest.tagName; + std::string msg = std::format( + "Do you want to download and update to {}? Dusklight will close and restart.", + updateTag + ); + + + push_document(std::make_unique(Modal::Props{ + .title = "Updater", + .bodyRml = escape(msg), + .actions = + { + ModalAction{ + .label = "YES", + .onPressed = download_update, + }, + }, + .onDismiss = download_update, + .icon = "info", + })); + if (auto* doc = top_document()) { + doc->focus(); + } + + // const std::string url = sUpdateCheckResult->latest.htmlUrl; + // if (url.empty()) { + // PrelaunchLog.warn("Update is available, but the release did not include a download URL"); + // return; + // } + // if (!SDL_OpenURL(url.c_str())) { + // PrelaunchLog.warn("Failed to open update URL '{}': {}", url, SDL_GetError()); + // } } std::string get_error_msg(iso::ValidationError error) { @@ -897,6 +925,14 @@ void Prelaunch::update() { PrelaunchLog.error("Failed to check for updates: {}", result->message); } sUpdateCheckResult = std::move(*result); + + std::optional correctAsset = update_check::get_platform_asset(sUpdateCheckResult->latest); + + if (correctAsset.has_value()) { + PrelaunchLog.info("Platform asset download: {}", correctAsset->browserDownloadUrl); + } else { + PrelaunchLog.info("Could not find correct Asset for Platform ID \"{}\"", update_check::DUSKLIGHT_PLATFORM_ID); + } } if (sUpdateCheckTask != nullptr) { diff --git a/src/dusk/update_check.cpp b/src/dusk/update_check.cpp index 737facc027..b40b5b27ba 100644 --- a/src/dusk/update_check.cpp +++ b/src/dusk/update_check.cpp @@ -1,5 +1,6 @@ #include "update_check.hpp" +#include "aurora/lib/logging.hpp" #include "dusk/http/http.hpp" #include "fmt/format.h" #include "nlohmann/json.hpp" @@ -15,6 +16,8 @@ namespace dusk::update_check { namespace { +aurora::Module UpdateCheckLog{"dusk::update_check"}; + using json = nlohmann::json; constexpr std::string_view GitHubApiVersion = "2026-03-10"; @@ -348,4 +351,16 @@ Result check_latest_github_release(std::string_view owner, std::string_view repo }; } +std::optional get_platform_asset(const Release& release) { + for (const auto& asset : release.assets) { + UpdateCheckLog.info("Asset link: {}", asset.name); + + if (asset.name.find(DUSKLIGHT_PLATFORM_ID) != std::string::npos) { + return asset; // Found it + } + } + + return std::nullopt; // Nothing matched our platform +} + } // namespace dusk::update_check diff --git a/src/dusk/update_check.hpp b/src/dusk/update_check.hpp index 72c66449dc..e915ef7beb 100644 --- a/src/dusk/update_check.hpp +++ b/src/dusk/update_check.hpp @@ -4,6 +4,7 @@ #include #include #include +#include "version.h" namespace dusk::update_check { @@ -35,6 +36,9 @@ struct Result { }; Result check_latest_github_release(std::string_view owner, std::string_view repo); +inline const std::string DUSKLIGHT_PLATFORM_ID = DUSK_PLATFORM_ID; + +std::optional get_platform_asset(const Release& release); } // namespace dusk::update_check diff --git a/version.h.in b/version.h.in index 6d94ce406a..daa0338a58 100644 --- a/version.h.in +++ b/version.h.in @@ -19,6 +19,7 @@ #define DUSK_PLATFORM_NAME "@PLATFORM_NAME@" #define DUSK_DLPACKAGE "dusklight-@DUSK_WC_DESCRIBE@-" DUSK_PLATFORM_NAME "-" DUSK_ARCH +#define DUSK_PLATFORM_ID DUSK_PLATFORM_NAME "-" DUSK_ARCH #define DUSK_SENTRY_DSN "@DUSK_SENTRY_DSN@" #define DUSK_SENTRY_ENVIRONMENT "@DUSK_SENTRY_ENVIRONMENT@"