From 5e79e9196fa1324131cee566265c90fae05df86c Mon Sep 17 00:00:00 2001 From: "zorro.zhang" Date: Tue, 7 Jan 2025 17:02:13 +0800 Subject: [PATCH] ENH: SaveProfileData to AppConfig in MainThread JIRA: none Change-Id: I22ae3dac5e2bed42a2edfb848d627cd5092ef171 (cherry picked from commit c2042d7e20ab03001e4b38f366d0f129f2ee0918) (cherry picked from commit d027e098acf37330076273799d2ff873a07044b5) --- src/slic3r/GUI/WebGuideDialog.cpp | 39 ++++++++++++++++++++----------- src/slic3r/GUI/WebGuideDialog.hpp | 3 ++- 2 files changed, 28 insertions(+), 14 deletions(-) diff --git a/src/slic3r/GUI/WebGuideDialog.cpp b/src/slic3r/GUI/WebGuideDialog.cpp index 00d5346661..ce9e3e20d9 100644 --- a/src/slic3r/GUI/WebGuideDialog.cpp +++ b/src/slic3r/GUI/WebGuideDialog.cpp @@ -296,7 +296,7 @@ void GuideFrame::OnNavigationComplete(wxWebViewEvent &evt) { //wxLogMessage("%s", "Navigation complete; url='" + evt.GetURL() + "'"); if (!bFirstComplete) { - boost::thread LoadProfileThread(boost::bind(&GuideFrame::LoadProfile, this)); + boost::thread LoadProfileThread(boost::bind(&GuideFrame::LoadProfileData, this)); LoadProfileThread.detach(); bFirstComplete = true; @@ -977,8 +977,7 @@ int GuideFrame::GetFilamentInfo( std::string VendorDirectory, json & pFilaList, return 0; } - -int GuideFrame::LoadProfile() +int GuideFrame::LoadProfileData() { try { m_ProfileJson = json::parse("{}"); @@ -987,7 +986,7 @@ int GuideFrame::LoadProfile() m_ProfileJson["filament"] = json::object(); m_ProfileJson["process"] = json::array(); - vendor_dir = (boost::filesystem::path(Slic3r::data_dir()) / PRESET_SYSTEM_DIR ).make_preferred(); + vendor_dir = (boost::filesystem::path(Slic3r::data_dir()) / PRESET_SYSTEM_DIR).make_preferred(); rsrc_vendor_dir = (boost::filesystem::path(resources_dir()) / "profiles").make_preferred(); // Orca: add custom as default @@ -1046,8 +1045,31 @@ int GuideFrame::LoadProfile() } } + //sync to web + std::string strAll = m_ProfileJson.dump(-1, ' ', false, json::error_handler_t::ignore); + BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ", finished, json contents: " << std::endl << strAll; + json m_Res = json::object(); + m_Res["command"] = "userguide_profile_load_finish"; + m_Res["sequence_id"] = "10001"; + wxString strJS = wxString::Format("HandleStudio(%s)", m_Res.dump(-1, ' ', true)); + wxGetApp().CallAfter([this, strJS] { RunScript(strJS); }); + //sync to appconfig + wxGetApp().CallAfter([this] { SaveProfileData(); }); + + } catch (std::exception &e) { + // wxLogMessage("GUIDE: load_profile_error %s ", e.what()); + // wxMessageBox(e.what(), "", MB_OK); + BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << ", error: " << e.what() << std::endl; + } + + return 0; +} + +int GuideFrame::SaveProfileData() +{ + try { const auto enabled_filaments = wxGetApp().app_config->has_section(AppConfig::SECTION_FILAMENTS) ? wxGetApp().app_config->get_section(AppConfig::SECTION_FILAMENTS) : std::map(); m_appconfig_new.set_vendors(*wxGetApp().app_config); m_appconfig_new.set_section(AppConfig::SECTION_FILAMENTS, enabled_filaments); @@ -1120,15 +1142,6 @@ int GuideFrame::LoadProfile() BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << ", error: "<< e.what() <