From 0163f9b31aeb7e54410becb4792da50fd2283b0c Mon Sep 17 00:00:00 2001 From: alves Date: Wed, 31 Dec 2025 16:18:55 +0800 Subject: [PATCH] feature add tips dialog for no update on preset --- src/slic3r/GUI/GUI_App.cpp | 16 +++++++---- src/slic3r/GUI/GUI_App.hpp | 2 +- src/slic3r/GUI/MainFrame.cpp | 4 +-- src/slic3r/Utils/PresetUpdater.cpp | 45 ++++++++++++++++++++++++++---- src/slic3r/Utils/PresetUpdater.hpp | 3 ++ 5 files changed, 55 insertions(+), 15 deletions(-) diff --git a/src/slic3r/GUI/GUI_App.cpp b/src/slic3r/GUI/GUI_App.cpp index c5649d002e..f30c0f2b84 100644 --- a/src/slic3r/GUI/GUI_App.cpp +++ b/src/slic3r/GUI/GUI_App.cpp @@ -2578,6 +2578,12 @@ bool GUI_App::on_init_inner() }); dlg.ShowModal(); }); + + Bind(EVT_NO_PRESET_UPDATE, [this](const wxCommandEvent& evt) { + wxString msg = _L("This is the newest version."); + InfoDialog dlg(nullptr, _L("Info"), msg); + dlg.ShowModal(); + }); } else { #ifdef __WXMSW__ @@ -4724,12 +4730,10 @@ void maybe_attach_updater_signature(Http& http, const std::string& canonical_que } // namespace -bool GUI_App::check_preset_version() -{ - bool is_newest_version = false; - - - return is_newest_version; +void GUI_App::check_preset_version() +{ + if (preset_updater != nullptr) + preset_updater->sync_config_async(); } void GUI_App::check_new_version_sf(bool show_tips, bool by_user) { diff --git a/src/slic3r/GUI/GUI_App.hpp b/src/slic3r/GUI/GUI_App.hpp index 07e820a42f..24d1ab1690 100644 --- a/src/slic3r/GUI/GUI_App.hpp +++ b/src/slic3r/GUI/GUI_App.hpp @@ -578,7 +578,7 @@ private: bool m_studio_active = true; std::chrono::system_clock::time_point last_active_point; - bool check_preset_version(); + void check_preset_version(); void check_new_version_sf(bool show_tips = false, bool by_user = false); void process_network_msg(std::string dev_id, std::string msg); void enter_force_upgrade(); diff --git a/src/slic3r/GUI/MainFrame.cpp b/src/slic3r/GUI/MainFrame.cpp index 6366cbf428..b6597ffedc 100644 --- a/src/slic3r/GUI/MainFrame.cpp +++ b/src/slic3r/GUI/MainFrame.cpp @@ -2300,10 +2300,8 @@ static wxMenu* generate_help_menu() append_menu_item( helpMenu, wxID_ANY, _L("Check for Preset Update"), _L("Check for Preset Update"), [](wxCommandEvent&) { + wxGetApp().check_preset_version(); - wxString msg = _L("This is the newest version."); - InfoDialog dlg(nullptr, _L("Info"), msg); - dlg.ShowModal(); }, "", nullptr, []() { return true; }); diff --git a/src/slic3r/Utils/PresetUpdater.cpp b/src/slic3r/Utils/PresetUpdater.cpp index 709568900f..60daeebe9b 100644 --- a/src/slic3r/Utils/PresetUpdater.cpp +++ b/src/slic3r/Utils/PresetUpdater.cpp @@ -182,6 +182,7 @@ struct Updates }; +wxDEFINE_EVENT(EVT_NO_PRESET_UPDATE, wxCommandEvent); wxDEFINE_EVENT(EVT_SLIC3R_VERSION_ONLINE, wxCommandEvent); wxDEFINE_EVENT(EVT_SLIC3R_EXPERIMENTAL_VERSION_ONLINE, wxCommandEvent); @@ -226,7 +227,7 @@ struct PresetUpdater::priv void sync_version() const; void parse_version_string(const std::string& body) const; void sync_resources(std::string http_url, std::map &resources, bool check_patch = false, std::string current_version="", std::string changelog_file=""); - void sync_config(); + void sync_config(bool isAuto_check = true); bool download_file(const std::string& url, const std::string& target_path, int timeout_sec = 30, bool* cancel_flag = nullptr); void sync_tooltip(std::string http_url, std::string language); void sync_plugins(std::string http_url, std::string plugin_version); @@ -709,7 +710,7 @@ bool PresetUpdater::priv::download_file(const std::string& url, return res; } // Orca: sync config update for currect App version -void PresetUpdater::priv::sync_config() +void PresetUpdater::priv::sync_config(bool isAuto_check) { auto cache_profile_path = cache_path; @@ -720,13 +721,13 @@ void PresetUpdater::priv::sync_config() // parse the assets section and get the latest asset by comparing the name Http::get(profile_update_url) - .on_error([cache_profile_path ](std::string body, std::string error, unsigned http_status) { + .on_error([cache_profile_path, isAuto_check](std::string body, std::string error, unsigned http_status) { // Orca: we check the response body to see if it's "Not Found", if so, it means for the current Orca version we don't have OTA // updates, we can delete the cache file BOOST_LOG_TRIVIAL(info) << format("Error getting: `%1%`: HTTP %2%, %3%", "sync_config_orca", http_status, error); }) .timeout_connect(5) - .on_complete([this, cache_profile_path](std::string body, unsigned http_status) { + .on_complete([this, cache_profile_path, isAuto_check](std::string body, unsigned http_status) { // Http response OK if (http_status != 200) return; @@ -755,13 +756,27 @@ void PresetUpdater::priv::sync_config() Semver localOtaVersion = get_version_from_json(localProfilesjson.string()); if (localOtaVersion >= remoteVersion) { - BOOST_LOG_TRIVIAL(info) << format("this the newest preset config for snapmaker orca"); + if (!isAuto_check) + { + wxCommandEvent* evt = new wxCommandEvent(EVT_NO_PRESET_UPDATE); + GUI::wxGetApp().QueueEvent(evt); + + BOOST_LOG_TRIVIAL(info) << format("use check the preset update."); + } return; } } if (currentPresetVersion < remoteVersion) download_file(fileUrl, fileName); + { + if (!isAuto_check) { + wxCommandEvent* evt = new wxCommandEvent(EVT_NO_PRESET_UPDATE); + GUI::wxGetApp().QueueEvent(evt); + + BOOST_LOG_TRIVIAL(info) << format("use check the preset update local no profiles."); + } + } } catch (...) {} }) @@ -1540,6 +1555,26 @@ bool PresetUpdater::install_bundles_rsrc(std::vector bundles, bool return p->install_bundles_rsrc(bundles, snapshot); } + +void PresetUpdater::sync_config_async() +{ + if (p->thread.joinable()) { + p->cancel = true; + p->thread.join(); + } + + p->cancel = false; + p->thread = std::thread([this]() { + BOOST_LOG_TRIVIAL(debug) << "[Orca Updater] sync_config_async started"; + this->p->sync_config(false); + + GUI::wxGetApp().CallAfter([] { + BOOST_LOG_TRIVIAL(debug) << "[Orca Updater] sync_config_async completed, checking updates..."; + GUI::wxGetApp().check_config_updates_from_updater(); + }); + }); +} + void PresetUpdater::on_update_notification_confirm() { if (!p->has_waiting_updates) diff --git a/src/slic3r/Utils/PresetUpdater.hpp b/src/slic3r/Utils/PresetUpdater.hpp index 59215926d8..3e8edaa7ca 100644 --- a/src/slic3r/Utils/PresetUpdater.hpp +++ b/src/slic3r/Utils/PresetUpdater.hpp @@ -65,11 +65,14 @@ public: void import_flutter_web(); + void sync_config_async(); + public: struct priv; std::unique_ptr p; }; +wxDECLARE_EVENT(EVT_NO_PRESET_UPDATE, wxCommandEvent); wxDECLARE_EVENT(EVT_SLIC3R_VERSION_ONLINE, wxCommandEvent); wxDECLARE_EVENT(EVT_SLIC3R_EXPERIMENTAL_VERSION_ONLINE, wxCommandEvent);