feat: notification where there is an update available for subscribed presets

This commit is contained in:
Ian Chua
2026-06-09 21:09:57 +08:00
parent c1f3125f75
commit d2d7aa7aa8
2 changed files with 54 additions and 34 deletions

View File

@@ -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()) // if(preset_bundle->bundles.pauseReads.load())
// { // {
// BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << __LINE__ << "ORCA : Update thread sync_bundle function yielded to main thread. 1"; // 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 // 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<OrcaCloudServiceAgent>(m_agent->get_cloud_agent()); auto orca_agent = std::dynamic_pointer_cast<OrcaCloudServiceAgent>(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"; 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 BOOST_LOG_TRIVIAL(warning) << "sync_bundle: failed to parse versions for bundle " << bundle_id
<< " (local: " << local_version << ", remote: " << remote_version << ")"; << " (local: " << local_version << ", remote: " << remote_version << ")";
preset_bundle->bundles.ReadUnlock(); // unlock read when fail preset_bundle->bundles.ReadUnlock(); // unlock read when fail
return; return -1;
} }
if (remote_version <= local_version) { if (remote_version <= local_version) {
BOOST_LOG_TRIVIAL(info) << "sync_bundle: bundle " << bundle_id << " is up-to-date (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 preset_bundle->bundles.ReadUnlock(); // unlock read when fail
return; return -1;
} }
BOOST_LOG_TRIVIAL(info) << "sync_bundle: updating bundle " << bundle_id BOOST_LOG_TRIVIAL(info) << "sync_bundle: updating bundle " << bundle_id
<< " from version " << local_version << " 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 // if it is an update, we will lock and write
std::string ver; std::string ver;
if(is_update) if (is_update) {
{
preset_bundle->bundles.WriteLock(); preset_bundle->bundles.WriteLock();
preset_bundle->bundles.m_bundles[bundle_id].update_available = true; preset_bundle->bundles.m_bundles[bundle_id].update_available = true;
preset_bundle->bundles.m_bundles[bundle_id].is_subscribed = 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(); 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 // Fetch the latest bundle data from cloud
std::map<std::string, std::map<std::string, std::string>> bundle_presets; std::map<std::string, std::map<std::string, std::string>> bundle_presets;
BundleMetadata remote_metadata; BundleMetadata remote_metadata;
@@ -6565,22 +6569,23 @@ void GUI_App::sync_bundle(std::string bundle_id, std::string version)
if (result != 0) { if (result != 0) {
BOOST_LOG_TRIVIAL(warning) << "sync_bundle: failed to fetch bundle " << bundle_id << ", result=" << result; 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 // Import the updated bundle on the main thread
CallAfter([this, bundle_id, bundle_presets, remote_metadata,is_new,is_update,ver]() { CallAfter(
if (!is_closing() && preset_bundle && app_config) { [this, bundle_id, bundle_presets, remote_metadata, is_new, is_update, ver]() {
// Check the presets for any system vendors that need to be installed if (!is_closing() && preset_bundle && app_config) {
for (auto data : bundle_presets) { // Check the presets for any system vendors that need to be installed
if (!check_preset_parent_available(data)) { for (auto data : bundle_presets) {
add_pending_vendor_preset(data); 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"; BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << __LINE__ << "ORCA : CallAfter from sync_bundle function actually updating subscribed presets";
preset_bundle->bundles.WriteLock(); preset_bundle->bundles.WriteLock();
@@ -6610,10 +6615,12 @@ void GUI_App::sync_bundle(std::string bundle_id, std::string version)
if (mainframe) if (mainframe)
mainframe->update_side_preset_ui(); mainframe->update_side_preset_ui();
BOOST_LOG_TRIVIAL(info) << "sync_bundle: successfully updated bundle " << bundle_id; 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<Preset> presets_to_sync; std::vector<Preset> presets_to_sync;
std::vector<std::pair<std::string, std::string>> bundles_to_sync; std::vector<std::pair<std::string, std::string>> bundles_to_sync;
std::unordered_set<std::string> bundles_synced; std::unordered_set<std::string> bundles_synced;
bool update_available = false;
// Sync once immediately, then every 60 seconds. // Sync once immediately, then every 60 seconds.
while (!t.expired()) { while (!t.expired()) {
++tick_tock; ++tick_tock;
@@ -6922,17 +6931,28 @@ void GUI_App::start_sync_user_preset(bool with_progress_dlg)
// Iterate over the bundles, and update/create // Iterate over the bundles, and update/create
for (const auto& bundle_entry : bundles_to_sync) { for (const auto& bundle_entry : bundles_to_sync) {
bundles_synced.insert(bundle_entry.first); bundles_synced.insert(bundle_entry.first);
// Sync each bundle individually // Sync each bundle individually
// if(!preset_bundle->bundles.pauseReads.load()) // if pause is true we will skip updating this frame altogether // 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"; BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << __LINE__ << "ORCA : Update thread syncing bundles";
sync_bundle(bundle_entry.first, bundle_entry.second); int res = 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));
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<BundleMetadata> to_delete; std::vector<BundleMetadata> to_delete;

View File

@@ -544,7 +544,7 @@ public:
// Bundle subscription sync // Bundle subscription sync
void check_bundle_updates(); 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); bool unsubscribe_bundle(const std::string& id);
void update_single_bundle(wxCommandEvent& evt); void update_single_bundle(wxCommandEvent& evt);