-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ If versions have not been fetched yet, wait before trying to instal…
…l it
- Loading branch information
1 parent
3763344
commit 8547176
Showing
11 changed files
with
114 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#include "Task_WaitForDownloadUrlToInstallVersion.hpp" | ||
#include <ImGuiNotify/ImGuiNotify.hpp> | ||
#include <optional> | ||
#include "Cool/Task/TaskManager.hpp" | ||
#include "Task_InstallVersion.hpp" | ||
#include "VersionManager.hpp" | ||
|
||
Task_WaitForDownloadUrlToInstallVersion::Task_WaitForDownloadUrlToInstallVersion(VersionName version_name, ImGuiNotify::NotificationId notification_id, std::shared_ptr<std::atomic<bool>> do_cancel) | ||
: _version_name{std::move(version_name)} | ||
, _notification_id{notification_id} | ||
, _cancel{std::move(do_cancel)} | ||
{ | ||
if (_notification_id == ImGuiNotify::NotificationId{}) | ||
{ | ||
_notification_id = ImGuiNotify::send({ | ||
.type = ImGuiNotify::Type::Info, | ||
.title = name(), | ||
.content = "You are offline\nWaiting for an Internet connection", | ||
.custom_imgui_content = [cancel = _cancel]() { | ||
if (ImGui::Button("Cancel")) | ||
cancel->store(true); | ||
}, | ||
.duration = std::nullopt, | ||
.is_closable = false, | ||
}); | ||
} | ||
} | ||
|
||
void Task_WaitForDownloadUrlToInstallVersion::do_work() | ||
{ | ||
if (_cancel->load()) | ||
{ | ||
ImGuiNotify::close_immediately(_notification_id); | ||
return; | ||
} | ||
|
||
version_manager().with_version_found(_version_name, [&](Version const& version) { | ||
if (version.download_url.has_value()) | ||
Cool::task_manager().submit(std::make_shared<Task_InstallVersion>(version.name, *version.download_url, _notification_id)); | ||
else | ||
Cool::task_manager().run_small_task_in(100ms, std::make_shared<Task_WaitForDownloadUrlToInstallVersion>(_version_name, _notification_id, _cancel)); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#pragma once | ||
#include "Cool/Task/Task.hpp" | ||
#include "ImGuiNotify/ImGuiNotify.hpp" | ||
#include "VersionName.hpp" | ||
|
||
class Task_WaitForDownloadUrlToInstallVersion : public Cool::Task { | ||
public: | ||
explicit Task_WaitForDownloadUrlToInstallVersion(VersionName version_name, ImGuiNotify::NotificationId = {}, std::shared_ptr<std::atomic<bool>> = std::make_unique<std::atomic<bool>>(false)); | ||
|
||
void do_work() override; | ||
void cancel() override | ||
{ | ||
_cancel->store(true); | ||
ImGuiNotify::close_immediately(_notification_id); | ||
} | ||
auto needs_user_confirmation_to_cancel_when_closing_app() const -> bool override { return true; } | ||
auto name() const -> std::string override { return fmt::format("Installing {}", _version_name.as_string()); } | ||
|
||
private: | ||
VersionName _version_name; | ||
ImGuiNotify::NotificationId _notification_id{}; | ||
std::shared_ptr<std::atomic<bool>> _cancel; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters