From 96762a2119e60aacec45e68fb52c1b9576498849 Mon Sep 17 00:00:00 2001 From: David Kocik Date: Wed, 18 Jan 2023 15:29:55 +0100 Subject: [PATCH] No new version available notification --- src/slic3r/GUI/GUI_App.cpp | 15 ++++++++++++++- src/slic3r/GUI/NotificationManager.cpp | 23 +++++++++++++++++++++++ src/slic3r/GUI/NotificationManager.hpp | 4 ++++ src/slic3r/Utils/AppUpdater.cpp | 5 +++++ 4 files changed, 46 insertions(+), 1 deletion(-) diff --git a/src/slic3r/GUI/GUI_App.cpp b/src/slic3r/GUI/GUI_App.cpp index 3e561d04e5..b901e7f10e 100644 --- a/src/slic3r/GUI/GUI_App.cpp +++ b/src/slic3r/GUI/GUI_App.cpp @@ -1249,7 +1249,7 @@ bool GUI_App::on_init_inner() std::string evt_string = into_u8(evt.GetString()); if (*Semver::parse(SLIC3R_VERSION) < *Semver::parse(evt_string)) { auto notif_type = (evt_string.find("beta") != std::string::npos ? NotificationType::NewBetaAvailable : NotificationType::NewAlphaAvailable); - this->plater_->get_notification_manager()->push_notification( notif_type + this->plater_->get_notification_manager()->push_version_notification( notif_type , NotificationManager::NotificationLevel::ImportantNotificationLevel , Slic3r::format(_u8L("New prerelease version %1% is available."), evt_string) , _u8L("See Releases page.") @@ -3300,6 +3300,19 @@ void GUI_App::on_version_read(wxCommandEvent& evt) return; } if (*Semver::parse(SLIC3R_VERSION) >= *Semver::parse(into_u8(evt.GetString()))) { + if (m_app_updater->get_triggered_by_user()) + { + std::string text = (*Semver::parse(into_u8(evt.GetString())) == Semver()) + ? Slic3r::format(_u8L("Check for application update has failed.")) + : Slic3r::format(_u8L("No new version is available. Latest release version is %1%."), evt.GetString()); + + this->plater_->get_notification_manager()->push_version_notification(NotificationType::NoNewReleaseAvailable + , NotificationManager::NotificationLevel::RegularNotificationLevel + , text + , std::string() + , std::function() + ); + } return; } // notification diff --git a/src/slic3r/GUI/NotificationManager.cpp b/src/slic3r/GUI/NotificationManager.cpp index e6f9d952a6..e8fd68c81f 100644 --- a/src/slic3r/GUI/NotificationManager.cpp +++ b/src/slic3r/GUI/NotificationManager.cpp @@ -2246,6 +2246,29 @@ void NotificationManager::push_simplify_suggestion_notification(const std::stri notification->object_id = object_id; push_notification_data(std::move(notification), 0); } +void NotificationManager::push_version_notification(NotificationType type, NotificationLevel level, const std::string& text, const std::string& hypertext, std::function callback) +{ + assert (type == NotificationType::NewAlphaAvailable + || type == NotificationType::NewBetaAvailable + || type == NotificationType::NoNewReleaseAvailable); + + for (std::unique_ptr& notification : m_pop_notifications) { + // NoNewReleaseAvailable must not show if alfa / beta is on. + NotificationType nttype = notification->get_type(); + if (type == NotificationType::NoNewReleaseAvailable + && (notification->get_type() == NotificationType::NewAlphaAvailable + || notification->get_type() == NotificationType::NewBetaAvailable)) { + return; + } + // NoNewReleaseAvailable must close if alfa / beta is being push. + if (notification->get_type() == NotificationType::NoNewReleaseAvailable + && (type == NotificationType::NewAlphaAvailable + || type == NotificationType::NewBetaAvailable)) { + notification->close(); + } + } + push_notification(type, level, text, hypertext, callback); +} void NotificationManager::close_notification_of_type(const NotificationType type) { for (std::unique_ptr ¬ification : m_pop_notifications) { diff --git a/src/slic3r/GUI/NotificationManager.hpp b/src/slic3r/GUI/NotificationManager.hpp index 7cd77a3048..b3a39a936f 100644 --- a/src/slic3r/GUI/NotificationManager.hpp +++ b/src/slic3r/GUI/NotificationManager.hpp @@ -56,6 +56,7 @@ enum class NotificationType // Like NewAppAvailable but with text and link for alpha / bet release NewAlphaAvailable, NewBetaAvailable, + NoNewReleaseAvailable, // Notification on the start of PrusaSlicer, when updates of system profiles are detected. // Contains a hyperlink to execute installation of the new system profiles. PresetUpdateAvailable, @@ -191,6 +192,9 @@ public: // Object warning with ObjectID, closes when object is deleted. ID used is of object not print like in slicing warning. void push_simplify_suggestion_notification(const std::string& text, ObjectID object_id, const std::string& hypertext = "", std::function callback = std::function()); + // Could be either NewAlphaAvailable, NewBetaAvailable or NoNewReleaseAvailable - this function only makes sure only 1 is visible. + void push_version_notification(NotificationType type, NotificationLevel level, const std::string& text, const std::string& hypertext, + std::function callback); // Close object warnings, whose ObjectID is not in the list. // living_oids is expected to be sorted. void remove_simplify_suggestion_of_released_objects(const std::vector& living_oids); diff --git a/src/slic3r/Utils/AppUpdater.cpp b/src/slic3r/Utils/AppUpdater.cpp index a17adea8a5..bd71e86ec1 100644 --- a/src/slic3r/Utils/AppUpdater.cpp +++ b/src/slic3r/Utils/AppUpdater.cpp @@ -323,6 +323,11 @@ void AppUpdater::priv::parse_version_string(const std::string& body) return; #endif // 0 BOOST_LOG_TRIVIAL(error) << "Could not find property tree in version file. Checking for application update has failed."; + // Lets send event with current version, this way if user triggered this check, it will notify him about no new version online. + std::string version = Semver().to_string(); + wxCommandEvent* evt = new wxCommandEvent(EVT_SLIC3R_VERSION_ONLINE); + evt->SetString(GUI::from_u8(version)); + GUI::wxGetApp().QueueEvent(evt); return; } std::string tree_string = body.substr(start);