From 9281032fdc3925474e2afb0af8ba4cca79fc626f Mon Sep 17 00:00:00 2001 From: Ian Chua Date: Wed, 4 Nov 2026 14:41:23 +0800 Subject: [PATCH] feat: add plater notifications for orcacloud plugin updates (#17168) --- src/slic3r/GUI/GUI_App.cpp | 26 ++++++++++++--- src/slic3r/GUI/NotificationManager.hpp | 18 ++++++++++ src/slic3r/plugin/PluginManager.cpp | 46 ++++++++++++++++++++++++++ 3 files changed, 85 insertions(+), 5 deletions(-) diff --git a/src/slic3r/GUI/GUI_App.cpp b/src/slic3r/GUI/GUI_App.cpp index 69e071c617..e4693d3056 100644 --- a/src/slic3r/GUI/GUI_App.cpp +++ b/src/slic3r/GUI/GUI_App.cpp @@ -3662,9 +3662,10 @@ bool GUI_App::on_init_inner() if (m_agent && m_agent->is_user_login()) { enable_user_preset_folder(true); - plugin_mgr.set_cloud_user(m_agent->get_user_id()); + const std::string cloud_user_id = m_agent->get_user_id(); + plugin_mgr.set_cloud_user(cloud_user_id); // Sync cloud plugin metadata off the UI thread; the network round trips took ~2 s of startup. - m_startup_cloud_plugin_fetch_thread = Slic3r::create_thread([this] { + m_startup_cloud_plugin_fetch_thread = Slic3r::create_thread([this, cloud_user_id] { std::vector not_found, unauthorized; try { PluginManager::instance().fetch_plugins_from_cloud(¬_found, &unauthorized); @@ -3675,14 +3676,15 @@ bool GUI_App::on_init_inner() BOOST_LOG_TRIVIAL(error) << "Startup cloud plugin fetch failed"; return; } - auto report = [this, not_found = std::move(not_found), unauthorized = std::move(unauthorized)] { + auto report = [this, cloud_user_id, not_found = std::move(not_found), unauthorized = std::move(unauthorized)] { if (is_closing()) return; if (m_plugins_dlg) m_plugins_dlg->update_plugin_dialog_ui(); Plater* plater = this->plater(); - if (plater == nullptr || m_agent == nullptr || !m_agent->is_user_login()) - return; // logged out meanwhile + if (plater == nullptr || m_agent == nullptr || !m_agent->is_user_login() || + m_agent->get_user_id() != cloud_user_id) + return; // logged out or switched account meanwhile for (const auto& uuid : not_found) { plater->get_notification_manager()->push_notification( NotificationType::CustomNotification, @@ -3695,6 +3697,20 @@ bool GUI_App::on_init_inner() NotificationManager::NotificationLevel::RegularNotificationLevel, format(_L("Plugin %s access is unauthorized."), uuid)); } + + // If the fetch finished before the plater existed, PluginManager could not deliver + // its update notice. Deliver it here from post_init(). update_available is only set + // by a successful fetch, so this remains success-only, and reading it now keeps the + // notice fresh if updates were installed while the report was deferred. + NotificationManager* notifications = plater->get_notification_manager(); + if (notifications != nullptr && + !notifications->has_notification_of_type(NotificationType::OrcaCloudPluginUpdateAvailable)) { + const std::vector descriptors = PluginManager::instance().get_plugin_descriptors(); + const bool has_update = std::any_of(descriptors.begin(), descriptors.end(), + [](const PluginDescriptor& descriptor) { return descriptor.has_update_available(); }); + if (has_update) + notifications->push_notification(NotificationType::OrcaCloudPluginUpdateAvailable); + } }; // This can run in a splash wxYield() before the main window exists. CallAfter([this, report = std::move(report)]() mutable { diff --git a/src/slic3r/GUI/NotificationManager.hpp b/src/slic3r/GUI/NotificationManager.hpp index ff40a2b5c1..713a8a599c 100644 --- a/src/slic3r/GUI/NotificationManager.hpp +++ b/src/slic3r/GUI/NotificationManager.hpp @@ -17,6 +17,7 @@ #include #include +#include #include #include #include @@ -197,6 +198,9 @@ enum class NotificationType // Active preset references a capability the installed+loaded plugin does not provide (outdated // plugin). Informational; cannot be auto-resolved; persistent, blocks slicing. OrcaPluginCapabilityUnavailableError, + // One aggregate notice that installed OrcaCloud plugins have updates. "More" opens the + // Plugins dialog, where the updates can be installed. + OrcaCloudPluginUpdateAvailable, NotificationTypeCount }; @@ -1130,6 +1134,20 @@ private: return true; }}, + // One notice for all OrcaCloud plugin updates found by a successful metadata fetch. + NotificationData{NotificationType::OrcaCloudPluginUpdateAvailable, NotificationLevel::ImportantNotificationLevel, BBL_NOTICE_MAX_INTERVAL, + _u8L("Updates are available for your OrcaCloud plugins."), _u8L("More"), + [](wxEvtHandler*) { + // Defer past the notification's render frame: the Plugins dialog is a + // webview window and must not be created from inside an ImGui pass. + if (wxTheApp != nullptr) + wxGetApp().CallAfter([] { + if (wxTheApp != nullptr && !wxGetApp().is_closing()) + wxGetApp().open_plugins_dialog(); + }); + return true; + }}, + NotificationData{NotificationType::BBLPrinterConfigUpdateAvailable, NotificationLevel::ImportantNotificationLevel, BBL_NOTICE_MAX_INTERVAL, _u8L("New printer config available."), _u8L("Details"), [](wxEvtHandler *evnthndlr) { diff --git a/src/slic3r/plugin/PluginManager.cpp b/src/slic3r/plugin/PluginManager.cpp index 137aa9696a..ef58df74fb 100644 --- a/src/slic3r/plugin/PluginManager.cpp +++ b/src/slic3r/plugin/PluginManager.cpp @@ -1677,6 +1677,52 @@ void PluginManager::fetch_plugins_from_cloud(std::vector* out_not_f } } + // A successful fetch is the only point where update availability is authoritative. Publish + // one aggregate notice after the orphan/unauthorized verdicts above so a plugin the user can + // no longer act on is not advertised. The check is repeated when the callback runs, keeping + // the notice fresh if an update was installed while the fetch was in flight. + if (cloud_fetch_succeeded) { + std::string fetched_cloud_user; + { + std::lock_guard lock(m_mutex); + fetched_cloud_user = m_cloud_user_id; + } + + auto push_update_notification = [this, fetched_cloud_user]() { + if (wxTheApp == nullptr || m_shutting_down.load(std::memory_order_acquire)) + return; + if (GUI::wxGetApp().is_closing()) + return; + GUI::Plater* plater = GUI::wxGetApp().plater(); + // Before post_init() there is no plater yet; GUI_App's startup report delivers the + // notice instead of dropping it. + if (plater == nullptr) + return; + + bool update_available = false; + { + std::lock_guard lock(m_mutex); + if (m_cloud_user_id != fetched_cloud_user) + return; // login/logout while the fetch was in flight + update_available = std::any_of(m_plugins.begin(), m_plugins.end(), [](const Plugin& plugin) { + return plugin.descriptor.has_update_available(); + }); + } + if (!update_available) + return; + + GUI::NotificationManager* notifications = plater->get_notification_manager(); + if (notifications == nullptr || + notifications->has_notification_of_type(GUI::NotificationType::OrcaCloudPluginUpdateAvailable)) + return; + notifications->push_notification(GUI::NotificationType::OrcaCloudPluginUpdateAvailable); + }; + if (wxTheApp == nullptr || wxIsMainThread()) + push_update_notification(); + else + GUI::wxGetApp().CallAfter(std::move(push_update_notification)); + } + if (out_not_found) *out_not_found = std::move(not_found); if (out_unauthorized)