diff --git a/src/slic3r/GUI/GUI_App.cpp b/src/slic3r/GUI/GUI_App.cpp index 8a5897622b..8f4d97672c 100644 --- a/src/slic3r/GUI/GUI_App.cpp +++ b/src/slic3r/GUI/GUI_App.cpp @@ -6493,16 +6493,16 @@ void GUI_App::update_single_bundle(wxCommandEvent& evt) }); } -void GUI_App::sync_bundle(std::string bundle_id, std::string version) +int GUI_App::sync_bundle(std::string bundle_id, std::string version) { // if(preset_bundle->bundles.pauseReads.load()) // { // BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << __LINE__ << "ORCA : Update thread sync_bundle function yielded to main thread. 1"; // return; // if the main thread acquires the lock at the start of our operations, we will yield // } - if (!m_agent || !m_agent->is_user_login()) return; + if (!m_agent || !m_agent->is_user_login()) return 0; auto orca_agent = std::dynamic_pointer_cast(m_agent->get_cloud_agent()); - if (!orca_agent) return; + if (!orca_agent) return 0; BOOST_LOG_TRIVIAL(info) << "sync_bundle: checking bundle " << bundle_id << " for updates"; @@ -6525,12 +6525,12 @@ void GUI_App::sync_bundle(std::string bundle_id, std::string version) BOOST_LOG_TRIVIAL(warning) << "sync_bundle: failed to parse versions for bundle " << bundle_id << " (local: " << local_version << ", remote: " << remote_version << ")"; preset_bundle->bundles.ReadUnlock(); // unlock read when fail - return; + return -1; } if (remote_version <= local_version) { BOOST_LOG_TRIVIAL(info) << "sync_bundle: bundle " << bundle_id << " is up-to-date (version " << local_version << ")"; preset_bundle->bundles.ReadUnlock(); // unlock read when fail - return; + return -1; } BOOST_LOG_TRIVIAL(info) << "sync_bundle: updating bundle " << bundle_id << " from version " << local_version @@ -6547,8 +6547,7 @@ void GUI_App::sync_bundle(std::string bundle_id, std::string version) // if it is an update, we will lock and write std::string ver; - if(is_update) - { + if (is_update) { preset_bundle->bundles.WriteLock(); preset_bundle->bundles.m_bundles[bundle_id].update_available = true; preset_bundle->bundles.m_bundles[bundle_id].is_subscribed = true; @@ -6556,8 +6555,13 @@ void GUI_App::sync_bundle(std::string bundle_id, std::string version) preset_bundle->bundles.WriteUnlock(); } - if(app_config->get_bool("preset_bundle_auto_update") == true || is_new) - { + const bool auto_update = app_config->get_bool("preset_bundle_auto_update"); + + if (is_update && !auto_update) { + return 1; + } + + if (auto_update || is_new) { // Fetch the latest bundle data from cloud std::map> bundle_presets; BundleMetadata remote_metadata; @@ -6565,22 +6569,23 @@ void GUI_App::sync_bundle(std::string bundle_id, std::string version) if (result != 0) { BOOST_LOG_TRIVIAL(warning) << "sync_bundle: failed to fetch bundle " << bundle_id << ", result=" << result; - return; + return -1; } // Import the updated bundle on the main thread - CallAfter([this, bundle_id, bundle_presets, remote_metadata,is_new,is_update,ver]() { - if (!is_closing() && preset_bundle && app_config) { - // Check the presets for any system vendors that need to be installed - for (auto data : bundle_presets) { - if (!check_preset_parent_available(data)) { - add_pending_vendor_preset(data); + CallAfter( + [this, bundle_id, bundle_presets, remote_metadata, is_new, is_update, ver]() { + if (!is_closing() && preset_bundle && app_config) { + // Check the presets for any system vendors that need to be installed + for (auto data : bundle_presets) { + if (!check_preset_parent_available(data)) { + add_pending_vendor_preset(data); + } } - } - load_pending_vendors(); + load_pending_vendors(); - // if(!preset_bundle->bundles.pauseReads.load()) // check again if we can actually update so as to not block the main thread - // { + // if(!preset_bundle->bundles.pauseReads.load()) // check again if we can actually update so as to not block the main thread + // { BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << __LINE__ << "ORCA : CallAfter from sync_bundle function actually updating subscribed presets"; preset_bundle->bundles.WriteLock(); @@ -6610,10 +6615,12 @@ void GUI_App::sync_bundle(std::string bundle_id, std::string version) if (mainframe) mainframe->update_side_preset_ui(); BOOST_LOG_TRIVIAL(info) << "sync_bundle: successfully updated bundle " << bundle_id; - // } - } - }); + // } + } + }); } + + return 0; } @@ -6817,6 +6824,8 @@ void GUI_App::start_sync_user_preset(bool with_progress_dlg) std::vector presets_to_sync; std::vector> bundles_to_sync; std::unordered_set bundles_synced; + + bool update_available = false; // Sync once immediately, then every 60 seconds. while (!t.expired()) { ++tick_tock; @@ -6922,17 +6931,28 @@ void GUI_App::start_sync_user_preset(bool with_progress_dlg) // Iterate over the bundles, and update/create for (const auto& bundle_entry : bundles_to_sync) { - bundles_synced.insert(bundle_entry.first); - // Sync each bundle individually - // if(!preset_bundle->bundles.pauseReads.load()) // if pause is true we will skip updating this frame altogether - // { - BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << __LINE__ << "ORCA : Update thread syncing bundles"; - sync_bundle(bundle_entry.first, bundle_entry.second); - // } - // Small delay between bundle syncs to avoid overwhelming the server - boost::this_thread::sleep_for(boost::chrono::milliseconds(100)); - + // Sync each bundle individually + // if(!preset_bundle->bundles.pauseReads.load()) // if pause is true we will skip updating this frame altogether + // { + BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << __LINE__ << "ORCA : Update thread syncing bundles"; + int res = sync_bundle(bundle_entry.first, bundle_entry.second); + + if (!update_available) + update_available = res == 1; + // } + // Small delay between bundle syncs to avoid overwhelming the server + boost::this_thread::sleep_for(boost::chrono::milliseconds(100)); + } + + if (update_available) { + wxGetApp() + .plater() + ->get_notification_manager() + ->push_notification(NotificationType::CustomNotification, + NotificationManager::NotificationLevel::RegularNotificationLevel, "There is an update available. Open the preset bundle dialog to update it."); + + update_available = false; } std::vector to_delete; diff --git a/src/slic3r/GUI/GUI_App.hpp b/src/slic3r/GUI/GUI_App.hpp index 60ef782f51..f72ba263aa 100644 --- a/src/slic3r/GUI/GUI_App.hpp +++ b/src/slic3r/GUI/GUI_App.hpp @@ -544,7 +544,7 @@ public: // Bundle subscription sync void check_bundle_updates(); - void sync_bundle(std::string bundle_id, std::string version); + int sync_bundle(std::string bundle_id, std::string version); bool unsubscribe_bundle(const std::string& id); void update_single_bundle(wxCommandEvent& evt);