Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 44 additions & 8 deletions src/dusk/ui/prelaunch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,21 +262,49 @@ 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)
{
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>(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) {
Expand Down Expand Up @@ -897,6 +925,14 @@ void Prelaunch::update() {
PrelaunchLog.error("Failed to check for updates: {}", result->message);
}
sUpdateCheckResult = std::move(*result);

std::optional<update_check::Asset> 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) {
Expand Down
15 changes: 15 additions & 0 deletions src/dusk/update_check.cpp
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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";
Expand Down Expand Up @@ -348,4 +351,16 @@ Result check_latest_github_release(std::string_view owner, std::string_view repo
};
}

std::optional<Asset> 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
4 changes: 4 additions & 0 deletions src/dusk/update_check.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <string>
#include <string_view>
#include <vector>
#include "version.h"

namespace dusk::update_check {

Expand Down Expand Up @@ -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<Asset> get_platform_asset(const Release& release);

} // namespace dusk::update_check

Expand Down
1 change: 1 addition & 0 deletions version.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -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@"
Expand Down
Loading