feature remove not work code and add some logs for check bug, add protect for some logic.

This commit is contained in:
alves
2026-03-11 17:00:18 +08:00
parent 028bcaa2b7
commit 65116f61ed
7 changed files with 103 additions and 150 deletions

View File

@@ -140,6 +140,10 @@ if (APPLE)
# add_definitions(-DBOOST_THREAD_DONT_USE_CHRONO -DBOOST_NO_CXX11_RVALUE_REFERENCES -DBOOST_THREAD_USES_MOVE)
# -liconv: boost links to libiconv by default
target_link_libraries(Snapmaker_Orca "-liconv -framework IOKit" "-framework CoreFoundation" "-framework AVFoundation" "-framework AVKit" "-framework CoreMedia" "-framework VideoToolbox" -lc++)
# Use the configured Info.plist for the macOS bundle
set_target_properties(Snapmaker_Orca PROPERTIES
MACOSX_BUNDLE_INFO_PLIST ${CMAKE_CURRENT_BINARY_DIR}/Info.plist
)
elseif (MSVC)
# Manifest is provided through Snapmaker_Orca.rc, don't generate your own.
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /MANIFEST:NO")

View File

@@ -2526,6 +2526,8 @@ bool GUI_App::on_init_inner()
}
if (!skip_this_version || evt.GetInt() != 0) {
wxString extmsg = wxString::FromUTF8(version_info.description);
if(!m_updateDialog)
return;
m_updateDialog->update_version_info(extmsg, version_info.version_str);
if (evt.GetInt() != 0) {
m_updateDialog->m_button_skip_version->Hide();
@@ -2669,12 +2671,15 @@ bool GUI_App::on_init_inner()
BOOST_LOG_TRIVIAL(info) << "create the main window";
mainframe = new MainFrame();
m_updateDialog = new UpdateVersionDialog(mainframe);
m_updateDialog->Hide();
m_updateDialog->Bind(EVT_DOWN_URL_PACK, [this](wxCommandEvent& event) {
auto downloadUlr = m_updateDialog->getUrl();
wxLaunchDefaultBrowser(downloadUlr);
});
if (!m_updateDialog)
{
m_updateDialog = new UpdateVersionDialog(mainframe);
m_updateDialog->Hide();
m_updateDialog->Bind(EVT_DOWN_URL_PACK, [this](wxCommandEvent& event) {
auto downloadUlr = m_updateDialog->getUrl();
wxLaunchDefaultBrowser(downloadUlr);
});
}
// hide settings tabs after first Layout
if (is_editor()) {
@@ -3530,6 +3535,15 @@ void GUI_App::recreate_GUI(const wxString &msg_name)
switch_window_pools();
mainframe = new MainFrame();
if (!m_updateDialog) {
m_updateDialog = new UpdateVersionDialog(mainframe);
m_updateDialog->Hide();
m_updateDialog->Bind(EVT_DOWN_URL_PACK, [this](wxCommandEvent& event) {
auto downloadUlr = m_updateDialog->getUrl();
wxLaunchDefaultBrowser(downloadUlr);
});
}
if (is_editor())
// hide settings tabs after first Layout
mainframe->select_tab(size_t(MainFrame::tp3DEditor));
@@ -5317,20 +5331,20 @@ void GUI_App::stop_sync_user_preset()
}
}
void GUI_App::start_http_server()
{
if (!m_http_server.is_started())
m_http_server.start();
}
void GUI_App::stop_http_server()
{
m_http_server.stop();
}
//void GUI_App::start_http_server()
//{
// if (!m_http_server.is_started())
// m_http_server.start();
//}
//void GUI_App::stop_http_server()
//{
// m_http_server.stop();
//}
void GUI_App::start_page_http_server()
{
if (!m_page_http_server.is_started())
m_page_http_server;
m_page_http_server.start();
}
void GUI_App::stop_page_http_server()
{

View File

@@ -336,7 +336,7 @@ private:
bool m_side_popup_status{false};
bool m_show_http_errpr_msgdlg{false};
wxString m_info_dialog_content;
HttpServer m_http_server;
//HttpServer m_http_server;
public:
HttpServer m_page_http_server;
@@ -604,8 +604,8 @@ private:
void sync_preset(Preset* preset);
void start_sync_user_preset(bool with_progress_dlg = false);
void stop_sync_user_preset();
void start_http_server();
void stop_http_server();
//void start_http_server();
//void stop_http_server();
// page loading http server
void start_page_http_server();

View File

@@ -228,13 +228,23 @@ void HttpServer::IOServer::stop_all()
HttpServer::IOServer::IOServer(HttpServer& server) : server(server), acceptor(io_service)
{
boost::asio::ip::tcp::endpoint endpoint(boost::asio::ip::tcp::v4(), server.port);
acceptor.open(endpoint.protocol());
acceptor.set_option(boost::asio::ip::tcp::acceptor::reuse_address(true));
acceptor.bind(endpoint);
try {
boost::asio::ip::tcp::endpoint endpoint(boost::asio::ip::tcp::v4(), server.port);
acceptor.open(endpoint.protocol());
acceptor.set_option(boost::asio::ip::tcp::acceptor::reuse_address(true));
acceptor.bind(endpoint);
}
catch (const boost::system::system_error& errorInfo)
{
BOOST_LOG_TRIVIAL(error) << "local server start failed with port:" << server.port;
BOOST_LOG_TRIVIAL(error) << "local server start failed with errorInfo:" << errorInfo.what();
}
}
HttpServer::HttpServer(boost::asio::ip::port_type port) : port(port) {}
HttpServer::HttpServer(boost::asio::ip::port_type port) : port(port)
{
std::cout << "local server init";
}
HttpServer::~HttpServer()
{
@@ -265,9 +275,12 @@ boost::asio::ip::port_type HttpServer::find_available_port(boost::asio::ip::port
// 尝试从起始端口开始查找可用端口
for (boost::asio::ip::port_type p = start_port; p < start_port + 1000; ++p) {
if (is_port_available(p)) {
BOOST_LOG_TRIVIAL(error) << "use new port for start server:"<<p;
return p;
}
}
BOOST_LOG_TRIVIAL(fatal) << "no available port for start server:";
throw std::runtime_error("No available ports found");
}
@@ -302,6 +315,7 @@ void HttpServer::start()
std::this_thread::sleep_for(std::chrono::milliseconds(100));
if (!start_http_server) {
BOOST_LOG_TRIVIAL(error) << "Failed to start HTTP server:" << port;
throw std::runtime_error("Failed to start HTTP server");
}
@@ -370,20 +384,20 @@ void HttpServer::restart()
bool HttpServer::is_healthy()
{
if (!start_http_server || !server_) {
BOOST_LOG_TRIVIAL(debug) << "Health check failed: server not started or server object is null";
BOOST_LOG_TRIVIAL(fatal) << "Health check failed: server not started or server object is null";
return false;
}
try {
// 检查acceptor是否正常打开
if (!server_->acceptor.is_open()) {
BOOST_LOG_TRIVIAL(debug) << "Health check failed: acceptor is not open";
BOOST_LOG_TRIVIAL(fatal) << "Health check failed: acceptor is not open";
return false;
}
// 检查io_service是否正在运行
if (server_->io_service.stopped()) {
BOOST_LOG_TRIVIAL(debug) << "Health check failed: io_service is stopped";
BOOST_LOG_TRIVIAL(fatal) << "Health check failed: io_service is stopped";
return false;
}
@@ -397,14 +411,14 @@ bool HttpServer::is_healthy()
if (!ec) {
test_socket.close();
BOOST_LOG_TRIVIAL(debug) << "Health check passed: test connection successful on port " << port;
BOOST_LOG_TRIVIAL(error) << "Health check passed: test connection successful on port " << port;
return true;
}
BOOST_LOG_TRIVIAL(debug) << "Health check failed: test connection failed with error: " << ec.message();
BOOST_LOG_TRIVIAL(fatal) << "Health check failed: test connection failed with error: " << ec.message();
return false;
} catch (const std::exception& e) {
BOOST_LOG_TRIVIAL(debug) << "Health check failed with exception: " << e.what();
BOOST_LOG_TRIVIAL(fatal) << "Health check failed with exception: " << e.what();
return false;
}
}
@@ -457,7 +471,7 @@ void HttpServer::start_health_check()
// 检查服务器是否健康,或者服务器是否已经停止运行
if ((start_http_server && !is_healthy()) || !start_http_server) {
BOOST_LOG_TRIVIAL(warning) << "HTTP server health check failed or server stopped, performing restart...";
BOOST_LOG_TRIVIAL(error) << "HTTP server health check failed or server stopped, performing restart...";
try {
// 在健康检查线程中直接执行重启,避免通过标志传递
restart();
@@ -482,7 +496,7 @@ void HttpServer::stop_health_check()
std::lock_guard<std::mutex> lock(m_health_check_mutex);
if (!m_health_check_enabled) {
BOOST_LOG_TRIVIAL(debug) << "Health check is not running";
BOOST_LOG_TRIVIAL(error) << "Health check is not running";
return;
}
@@ -697,6 +711,11 @@ std::shared_ptr<HttpServer::Response> HttpServer::web_server_handle_request(cons
std::string file_path = map_url_to_file_path(url);
if (file_path.empty())
{
BOOST_LOG_TRIVIAL(error) << "file path is null for: " << url;
}
BOOST_LOG_TRIVIAL(info) << "Handling file_path request for URL: " << file_path;
return std::make_shared<ResponseFile>(file_path);
}
@@ -715,10 +734,17 @@ std::string HttpServer::map_url_to_file_path(const std::string& url)
}
if (trimmed_url == "/") {
trimmed_url = "/flutter_web/index.html"; // 默认首页
} else if (trimmed_url.substr(0, 11) == "/localfile/") {
trimmed_url = "/flutter_web/index.html"; // defualt home page
}
else if (trimmed_url.substr(0, 11) == "/localfile/") {
auto real_path = trimmed_url.substr(11);
return real_path.ToStdString(wxConvUTF8);
auto realUTF8Path = real_path.ToStdString(wxConvUTF8);
if (realUTF8Path.empty()) {
BOOST_LOG_TRIVIAL(error) << "realUTF8Path is null for: " << trimmed_url;
}
return realUTF8Path;
}
auto data_web_path = boost::filesystem::path(data_dir()) / "web";
if (!boost::filesystem::exists(data_web_path / "flutter_web")) {
@@ -727,13 +753,25 @@ std::string HttpServer::map_url_to_file_path(const std::string& url)
copy_directory_recursively(source_path, target_path);
}
if (trimmed_url.find("flutter_web") == std::string::npos) {
wxString res = wxString::FromUTF8(resources_dir()) + trimmed_url;
return res.ToStdString(wxConvUTF8);
} else {
wxString res = wxString::FromUTF8(data_dir()) + trimmed_url;
return res.ToStdString(wxConvUTF8);
wxString res = "";
if (trimmed_url.find("flutter_web") == std::string::npos)
{
res = wxString::FromUTF8(resources_dir()) + trimmed_url;
}
else
{
res = wxString::FromUTF8(data_dir()) + trimmed_url;
}
auto strUTF8 = res.ToStdString(wxConvUTF8);
if (strUTF8.empty())
{
BOOST_LOG_TRIVIAL(error) << "strUTF8 is null for: " << res;
}
return strUTF8;
}
void HttpServer::ResponseRedirect::write_response(std::stringstream& ssOut)

View File

@@ -2822,23 +2822,10 @@ void MainFrame::init_menubar_as_editor()
[this](wxCommandEvent&) { m_plater->toggle_show_wireframe(); m_plater->get_current_canvas3D()->post_event(SimpleEvent(wxEVT_PAINT)); }, this,
[this]() { return m_plater->is_wireframe_enabled(); }, [this]() { return m_plater->is_show_wireframe(); }, this);*/
//viewMenu->AppendSeparator();
////BBS orthogonal view
//append_menu_check_item(viewMenu, wxID_ANY, _L("Show Edges(TODO)"), _L("Show Edges."),
// [this](wxCommandEvent& evt) {
// wxGetApp().app_config->set("show_build_edges", evt.GetInt() == 1 ? "true" : "false");
// }, nullptr, [this]() {return can_select(); }, [this]() {
// std::string show_build_edges = wxGetApp().app_config->get("show_build_edges");
// return show_build_edges.compare("true") == 0;
// }, this);
}
wxWindowID config_id_base = wxWindow::NewControlId(int(ConfigMenuCnt));
//TODO remove
//auto config_wizard_name = _(ConfigWizard::name(true) + "(Debug)");
//const auto config_wizard_tooltip = from_u8((boost::format(_utf8(L("Run %s"))) % config_wizard_name).str());
//auto config_item = new wxMenuItem(m_topbar->GetTopMenu(), ConfigMenuWizard + config_id_base, config_wizard_name, config_wizard_tooltip);
#ifdef __APPLE__
#ifdef __APPLE__
wxWindowID bambu_studio_id_base = wxWindow::NewControlId(int(2));
wxMenu* parent_menu = m_menubar->OSXGetAppleMenu();
//auto preference_item = new wxMenuItem(parent_menu, OrcaSlicerMenuPreferences + bambu_studio_id_base, _L("Preferences") + "\t" + ctrl + ",", "");
@@ -2847,98 +2834,11 @@ void MainFrame::init_menubar_as_editor()
auto preference_item = new wxMenuItem(parent_menu, ConfigMenuPreferences + config_id_base, _L("Preferences") + "\t" + ctrl + "P", "");
#endif
//auto printer_item = new wxMenuItem(parent_menu, ConfigMenuPrinter + config_id_base, _L("Printer"), "");
//auto language_item = new wxMenuItem(parent_menu, ConfigMenuLanguage + config_id_base, _L("Switch Language"), "");
// parent_menu->Bind(wxEVT_MENU, [this, config_id_base](wxEvent& event) {
// switch (event.GetId() - config_id_base) {
// //case ConfigMenuLanguage:
// //{
// // /* Before change application language, let's check unsaved changes on 3D-Scene
// // * and draw user's attention to the application restarting after a language change
// // */
// // {
// // // the dialog needs to be destroyed before the call to switch_language()
// // // or sometimes the application crashes into wxDialogBase() destructor
// // // so we put it into an inner scope
// // wxString title = _L("Language selection");
// // wxMessageDialog dialog(nullptr,
// // _L("Switching the language requires application restart.\n") + "\n\n" +
// // _L("Do you want to continue?"),
// // title,
// // wxICON_QUESTION | wxOK | wxCANCEL);
// // if (dialog.ShowModal() == wxID_CANCEL)
// // return;
// // }
//
// // wxGetApp().switch_language();
// // break;
// //}
// //case ConfigMenuWizard:
// //{
// // wxGetApp().run_wizard(ConfigWizard::RR_USER);
// // break;
// //}
// case ConfigMenuPrinter:
// {
// wxGetApp().params_dialog()->Popup();
// wxGetApp().get_tab(Preset::TYPE_PRINTER)->restore_last_select_item();
// break;
// }
// case ConfigMenuPreferences:
// {
// CallAfter([this] {
// PreferencesDialog dlg(this);
// dlg.ShowModal();
//#if ENABLE_GCODE_LINES_ID_IN_H_SLIDER
// if (dlg.seq_top_layer_only_changed() || dlg.seq_seq_top_gcode_indices_changed())
//#else
// if (dlg.seq_top_layer_only_changed())
//#endif // ENABLE_GCODE_LINES_ID_IN_H_SLIDER
// plater()->refresh_print();
//#if ENABLE_CUSTOMIZABLE_FILES_ASSOCIATION_ON_WIN
//#ifdef _WIN32
// /*
// if (wxGetApp().app_config()->get("associate_3mf") == "true")
// wxGetApp().associate_3mf_files();
// if (wxGetApp().app_config()->get("associate_stl") == "true")
// wxGetApp().associate_stl_files();
// /*if (wxGetApp().app_config()->get("associate_step") == "true")
// wxGetApp().associate_step_files();*/
//#endif // _WIN32
//#endif
// });
// break;
// }
// default:
// break;
// }
// });
#ifdef __APPLE__
wxString about_title = wxString::Format(_L("&About %s"), SLIC3R_APP_FULL_NAME);
//auto about_item = new wxMenuItem(parent_menu, Snapmaker_OrcaMenuAbout + bambu_studio_id_base, about_title, "");
//parent_menu->Bind(wxEVT_MENU, [this, bambu_studio_id_base](wxEvent& event) {
// switch (event.GetId() - bambu_studio_id_base) {
// case Snapmaker_OrcaMenuAbout:
// Slic3r::GUI::about();
// break;
// case Snapmaker_OrcaMenuPreferences:
// CallAfter([this] {
// PreferencesDialog dlg(this);
// dlg.ShowModal();
//#if ENABLE_GCODE_LINES_ID_IN_H_SLIDER
// if (dlg.seq_top_layer_only_changed() || dlg.seq_seq_top_gcode_indices_changed())
//#else
// if (dlg.seq_top_layer_only_changed())
//#endif // ENABLE_GCODE_LINES_ID_IN_H_SLIDER
// plater()->refresh_print();
// });
// break;
// default:
// break;
// }
//});
//parent_menu->Insert(0, about_item);
append_menu_item(
parent_menu, wxID_ANY, _L(about_title), "",
[this](wxCommandEvent &) { Slic3r::GUI::about();},
@@ -2978,10 +2878,7 @@ void MainFrame::init_menubar_as_editor()
plater()->get_current_canvas3D()->force_set_focus();
},
"", nullptr, []() { return true; }, this);
//m_topbar->AddDropDownMenuItem(preference_item);
//m_topbar->AddDropDownMenuItem(printer_item);
//m_topbar->AddDropDownMenuItem(language_item);
//m_topbar->AddDropDownMenuItem(config_item);
m_topbar->AddDropDownSubMenu(helpMenu, _L("Help"));
// SoftFever calibrations

View File

@@ -309,7 +309,7 @@ void SMUserLogin::OnScriptMessage(wxWebViewEvent &evt)
}
else if (strCmd == "get_localhost_url") {
BOOST_LOG_TRIVIAL(info) << "thirdparty_login: get_localhost_url";
wxGetApp().start_http_server();
//wxGetApp().start_http_server();
std::string sequence_id = j["sequence_id"].get<std::string>();
CallAfter([this, sequence_id] {
json ack_j;

View File

@@ -283,7 +283,7 @@ void ZUserLogin::OnScriptMessage(wxWebViewEvent &evt)
}
else if (strCmd == "get_localhost_url") {
BOOST_LOG_TRIVIAL(info) << "thirdparty_login: get_localhost_url";
wxGetApp().start_http_server();
//wxGetApp().start_http_server();
std::string sequence_id = j["sequence_id"].get<std::string>();
CallAfter([this, sequence_id] {
json ack_j;