mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-06-09 21:42:56 +00:00
Compare commits
2 Commits
release/v2
...
fix/ui-fre
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
19c5eae22f | ||
|
|
9417553c32 |
@@ -27,6 +27,7 @@
|
||||
#include <iterator>
|
||||
#include <exception>
|
||||
#include <cstdlib>
|
||||
#include <future>
|
||||
#include <regex>
|
||||
#include <thread>
|
||||
#include <string_view>
|
||||
@@ -4875,31 +4876,26 @@ void GUI_App::on_http_error(wxCommandEvent &evt)
|
||||
return;
|
||||
}
|
||||
|
||||
static bool m_is_error_shown = false;
|
||||
// Show general error notification for Orca Cloud API failures (not Bambu)
|
||||
if (provider == ORCA_CLOUD_PROVIDER && status >= 400 && code != HttpErrorVersionLimited) {
|
||||
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);
|
||||
}
|
||||
|
||||
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());
|
||||
}
|
||||
}
|
||||
// 409 Conflict is expected during normal cloud sync (preset already exists on cloud).
|
||||
// Treat it as a no-op - the caller handles conflict resolution via sync_push.
|
||||
if (status == 409) {
|
||||
BOOST_LOG_TRIVIAL(info) << "Http 409 Conflict — preset already exists on cloud, no dialog needed.";
|
||||
return;
|
||||
}
|
||||
|
||||
if (!m_is_error_shown) {
|
||||
m_is_error_shown = true;
|
||||
wxMessageBox(msg, _L("Cloud Error"), wxOK | wxICON_ERROR, wxGetApp().mainframe);
|
||||
if (provider == ORCA_CLOUD_PROVIDER && status >= 400 && code != HttpErrorVersionLimited) {
|
||||
if (wxGetApp().plater() != nullptr && wxGetApp().imgui()->display_initialized()) {
|
||||
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) {
|
||||
// Load user's personal presets
|
||||
@@ -5917,10 +5913,42 @@ void GUI_App::reload_settings()
|
||||
if (plater_)
|
||||
plater_->sidebar().update_all_preset_comboboxes();
|
||||
};
|
||||
if (is_main_thread_active())
|
||||
if (is_main_thread_active()) {
|
||||
refresh_synced_ui();
|
||||
else
|
||||
CallAfter(refresh_synced_ui);
|
||||
} else {
|
||||
// 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);
|
||||
|
||||
if (ret == 0 && m_agent && !t.expired())
|
||||
reload_settings();
|
||||
reload_settings(t);
|
||||
|
||||
// For orca specific syncing
|
||||
auto orca_agent = std::dynamic_pointer_cast<OrcaCloudServiceAgent>(m_agent->get_cloud_agent());
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#define slic3r_GUI_App_hpp_
|
||||
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include "ImGuiWrapper.hpp"
|
||||
#include "ConfigWizard.hpp"
|
||||
@@ -519,7 +520,7 @@ public:
|
||||
std::string format_IP(const std::string& ip);
|
||||
void show_dialog(wxString msg);
|
||||
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();
|
||||
|
||||
bool maybe_migrate_user_presets_on_login();
|
||||
|
||||
@@ -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) {
|
||||
result.success = false;
|
||||
result.status = resp_status == 0 ? 404 : resp_status;
|
||||
result.body = body;
|
||||
result.body = resp_body;
|
||||
BOOST_LOG_TRIVIAL(error) << "OrcaCloudServiceAgent: HTTP error - " << error;
|
||||
})
|
||||
.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) {
|
||||
result.success = false;
|
||||
result.status = resp_status == 0 ? 404 : resp_status;
|
||||
result.body = body;
|
||||
result.body = resp_body;
|
||||
BOOST_LOG_TRIVIAL(error) << "OrcaCloudServiceAgent: HTTP error - " << error;
|
||||
})
|
||||
.timeout_max(30)
|
||||
|
||||
Reference in New Issue
Block a user