SaveTool: launch the thread, and add basic response handling.

This commit is contained in:
Guillaume Jacquemin 2021-07-28 14:17:21 +02:00
parent 7f32166ab0
commit ee384843e9
2 changed files with 21 additions and 2 deletions

View file

@ -133,6 +133,11 @@ SaveTool::SaveTool(const Arguments& arguments):
}
initialiseConfiguration();
if(_checkUpdatesOnStartup) {
_thread = std::thread{[this]{ checkForUpdates(); }};
_queue.addToast(Toast::Type::Default, "Checking for updates...");
}
}
SaveTool::~SaveTool() {
@ -286,7 +291,18 @@ void SaveTool::initEvent(SDL_Event& event) {
void SaveTool::updateCheckEvent(SDL_Event& event) {
_thread.join();
// TODO: implement
cpr::Response r{std::move(*static_cast<cpr::Response*>(event.user.data1))};
delete static_cast<cpr::Response*>(event.user.data1);
if(r.elapsed > 10.0) {
_queue.addToast(Toast::Type::Error, "The request timed out.");
return;
}
if(r.status_code != 200) {
_queue.addToast(Toast::Type::Error, Utility::formatString("The request failed with error code {}: {}", r.status_code, r.reason));
return;
}
}
void SaveTool::initialiseConfiguration() {

View file

@ -62,7 +62,10 @@ void SaveTool::drawMainMenu() {
ImGui::Checkbox("Check for updates on startup", &_checkUpdatesOnStartup);
ImGui::SameLine();
ImGui::Button(ICON_FA_SYNC_ALT " Check now");
if(ImGui::Button(ICON_FA_SYNC_ALT " Check now")) {
_queue.addToast(Toast::Type::Default, "Checking for updates...");
_thread = std::thread{[this]{ checkForUpdates(); }};
}
ImGui::EndMenu();
}