Compare commits

...

2 Commits

Author SHA1 Message Date
ExPikaPaka
19c5eae22f Removed pop-up error dialog. Resolved improper preset location 2026-05-29 08:37:15 +02:00
Mykola Nahirnyi
9417553c32 Resolves UI freeze issue by properly treating 409 issue 2026-05-29 08:18:01 +03:00
3 changed files with 61 additions and 32 deletions

View File

@@ -27,6 +27,7 @@
#include <iterator> #include <iterator>
#include <exception> #include <exception>
#include <cstdlib> #include <cstdlib>
#include <future>
#include <regex> #include <regex>
#include <thread> #include <thread>
#include <string_view> #include <string_view>
@@ -4875,31 +4876,26 @@ void GUI_App::on_http_error(wxCommandEvent &evt)
return; return;
} }
static bool m_is_error_shown = false; // 409 Conflict is expected during normal cloud sync (preset already exists on cloud).
// Show general error notification for Orca Cloud API failures (not Bambu) // Treat it as a no-op - the caller handles conflict resolution via sync_push.
if (provider == ORCA_CLOUD_PROVIDER && status >= 400 && code != HttpErrorVersionLimited) { if (status == 409) {
wxString msg; BOOST_LOG_TRIVIAL(info) << "Http 409 Conflict — preset already exists on cloud, no dialog needed.";
if (!error.empty()) { return;
msg = wxString::Format(_L("Failed to connect to OrcaCloud.\nPlease check your network connectivity\n(HTTP %u): %s"), status, wxString::FromUTF8(error)); }
} else {
msg = wxString::Format(_L("Failed to connect to OrcaCloud.\nPlease check your network connectivity\n(HTTP %u)"), status);
}
if (app_config->get_bool("developer_mode")) {
// Use notification manager if ImGui is ready; fall back to wxMessageBox on Linux
// where ImGui may not be initialized until the user switches to the Prepare tab.
if (wxGetApp().plater() != nullptr && wxGetApp().imgui()->display_initialized()) {
wxGetApp()
.plater()
->get_notification_manager()
->push_notification(NotificationType::PlaterError, NotificationManager::NotificationLevel::WarningNotificationLevel,
msg.ToUTF8().data());
}
}
if (!m_is_error_shown) { if (provider == ORCA_CLOUD_PROVIDER && status >= 400 && code != HttpErrorVersionLimited) {
m_is_error_shown = true; if (wxGetApp().plater() != nullptr && wxGetApp().imgui()->display_initialized()) {
wxMessageBox(msg, _L("Cloud Error"), wxOK | wxICON_ERROR, wxGetApp().mainframe); wxString msg;
if (!error.empty()) {
msg = wxString::Format(_L("Failed to connect to OrcaCloud.\nPlease check your network connectivity\n(HTTP %u): %s"), status, wxString::FromUTF8(error));
} else {
msg = wxString::Format(_L("Failed to connect to OrcaCloud.\nPlease check your network connectivity\n(HTTP %u)"), status);
}
wxGetApp()
.plater()
->get_notification_manager()
->push_notification(NotificationType::PlaterError, NotificationManager::NotificationLevel::WarningNotificationLevel,
msg.ToUTF8().data());
} }
} }
} }
@@ -5840,7 +5836,7 @@ void GUI_App::push_notification(const MachineObject* obj, wxString msg, wxStrin
} }
} }
void GUI_App::reload_settings() void GUI_App::reload_settings(std::optional<std::weak_ptr<int>> cancel_token)
{ {
if (preset_bundle && m_agent) { if (preset_bundle && m_agent) {
// Load user's personal presets // Load user's personal presets
@@ -5917,10 +5913,42 @@ void GUI_App::reload_settings()
if (plater_) if (plater_)
plater_->sidebar().update_all_preset_comboboxes(); plater_->sidebar().update_all_preset_comboboxes();
}; };
if (is_main_thread_active()) if (is_main_thread_active()) {
refresh_synced_ui(); refresh_synced_ui();
else } else {
CallAfter(refresh_synced_ui); // Block the background sync thread until the main thread has applied the
// cloud-sourced setting_ids back into local presets. Without this wait,
// the periodic push loop starts immediately with stale sync_info="create"
// / empty setting_ids and re-uploads every preset, getting a 409 from the
// cloud for each one (it already has them from the pull that just finished).
auto p = std::make_shared<std::promise<void>>();
std::future<void> fut = p->get_future();
CallAfter([refresh_synced_ui = std::move(refresh_synced_ui), p]() mutable {
try {
refresh_synced_ui();
} catch (const std::exception& e) {
BOOST_LOG_TRIVIAL(error) << "reload_settings: refresh_synced_ui threw: " << e.what();
} catch (...) {
BOOST_LOG_TRIVIAL(error) << "reload_settings: refresh_synced_ui threw unknown exception";
}
p->set_value(); // always unblock the sync thread
});
// Poll every 100 ms so we can bail out on cancellation (app close)
// without blocking stop_sync_user_preset()'s join() for up to 10 s.
auto deadline = std::chrono::steady_clock::now() + std::chrono::seconds(10);
while (fut.wait_for(std::chrono::milliseconds(100)) == std::future_status::timeout) {
if (cancel_token.has_value() && cancel_token->expired()) {
BOOST_LOG_TRIVIAL(warning) << "reload_settings: cancelled while waiting for UI "
"preset update — sync loop may see stale setting_ids";
break;
}
if (std::chrono::steady_clock::now() >= deadline) {
BOOST_LOG_TRIVIAL(warning) << "reload_settings: timed out waiting for UI "
"preset update — sync loop may see stale setting_ids";
break;
}
}
}
} }
} }
@@ -6699,7 +6727,7 @@ void GUI_App::start_sync_user_preset(bool with_progress_dlg)
finishFn(ret == 0); finishFn(ret == 0);
if (ret == 0 && m_agent && !t.expired()) if (ret == 0 && m_agent && !t.expired())
reload_settings(); reload_settings(t);
// For orca specific syncing // For orca specific syncing
auto orca_agent = std::dynamic_pointer_cast<OrcaCloudServiceAgent>(m_agent->get_cloud_agent()); auto orca_agent = std::dynamic_pointer_cast<OrcaCloudServiceAgent>(m_agent->get_cloud_agent());

View File

@@ -2,6 +2,7 @@
#define slic3r_GUI_App_hpp_ #define slic3r_GUI_App_hpp_
#include <memory> #include <memory>
#include <optional>
#include <string> #include <string>
#include "ImGuiWrapper.hpp" #include "ImGuiWrapper.hpp"
#include "ConfigWizard.hpp" #include "ConfigWizard.hpp"
@@ -519,7 +520,7 @@ public:
std::string format_IP(const std::string& ip); std::string format_IP(const std::string& ip);
void show_dialog(wxString msg); void show_dialog(wxString msg);
void push_notification(const MachineObject* obj, wxString msg, wxString title = wxEmptyString, UserNotificationStyle style = UserNotificationStyle::UNS_NORMAL); void push_notification(const MachineObject* obj, wxString msg, wxString title = wxEmptyString, UserNotificationStyle style = UserNotificationStyle::UNS_NORMAL);
void reload_settings(); void reload_settings(std::optional<std::weak_ptr<int>> cancel_token = std::nullopt);
void remove_user_presets(); void remove_user_presets();
bool maybe_migrate_user_presets_on_login(); bool maybe_migrate_user_presets_on_login();

View File

@@ -1888,7 +1888,7 @@ int OrcaCloudServiceAgent::http_post(const std::string& path, const std::string&
.on_error([&](std::string resp_body, std::string error, unsigned resp_status) { .on_error([&](std::string resp_body, std::string error, unsigned resp_status) {
result.success = false; result.success = false;
result.status = resp_status == 0 ? 404 : resp_status; result.status = resp_status == 0 ? 404 : resp_status;
result.body = body; result.body = resp_body;
BOOST_LOG_TRIVIAL(error) << "OrcaCloudServiceAgent: HTTP error - " << error; BOOST_LOG_TRIVIAL(error) << "OrcaCloudServiceAgent: HTTP error - " << error;
}) })
.timeout_max(30) .timeout_max(30)
@@ -1958,7 +1958,7 @@ int OrcaCloudServiceAgent::http_put(const std::string& path, const std::string&
.on_error([&](std::string resp_body, std::string error, unsigned resp_status) { .on_error([&](std::string resp_body, std::string error, unsigned resp_status) {
result.success = false; result.success = false;
result.status = resp_status == 0 ? 404 : resp_status; result.status = resp_status == 0 ? 404 : resp_status;
result.body = body; result.body = resp_body;
BOOST_LOG_TRIVIAL(error) << "OrcaCloudServiceAgent: HTTP error - " << error; BOOST_LOG_TRIVIAL(error) << "OrcaCloudServiceAgent: HTTP error - " << error;
}) })
.timeout_max(30) .timeout_max(30)