ENH:optimized the retry of requests

jira:[for network optimized]

Change-Id: Iea43f4a97c7cd568171287278a07689e954d1093
(cherry picked from commit 35d3de8abe63a0cba30948581ed26a8bc7f94162)
(cherry picked from commit 30bad38fb979f5c5a10e4b869ec2e41fa99857f8)
This commit is contained in:
tao wang 2024-09-16 22:29:39 +08:00 committed by Noisyfox
parent 569d4e6307
commit 8bb7ea7cfc
7 changed files with 156 additions and 2 deletions

View file

@ -1571,6 +1571,17 @@ void GUI_App::init_networking_callbacks()
// GUI::wxGetApp().request_user_handle(online_login);
// });
m_agent->set_server_callback([this](std::string url, int status) {
if (!m_server_error_dialog) {
m_server_error_dialog = new NetworkErrorDialog(mainframe);
}
if (!m_server_error_dialog->IsShown()) {
m_server_error_dialog->ShowModal();
}
});
m_agent->set_on_server_connected_fn([this](int return_code, int reason_code) {
if (m_is_closing) {
return;
@ -3227,6 +3238,23 @@ void GUI_App::link_to_network_check()
wxLaunchDefaultBrowser(url);
}
void GUI_App::link_to_lan_only_wiki()
{
std::string url;
std::string country_code = app_config->get_country_code();
if (country_code == "US") {
url = "https://wiki.bambulab.com/en/knowledge-sharing/enable-lan-mode";
}
else if (country_code == "CN") {
url = "https://wiki.bambulab.com/zh/knowledge-sharing/enable-lan-mode";
}
else {
url = "https://wiki.bambulab.com/en/knowledge-sharing/enable-lan-mode";
}
wxLaunchDefaultBrowser(url);
}
bool GUI_App::tabs_as_menu() const
{
return false;

View file

@ -81,6 +81,7 @@ class ParamsDialog;
class HMSQuery;
class ModelMallDialog;
class PingCodeBindDialog;
class NetworkErrorDialog;
enum FileType
@ -393,9 +394,9 @@ private:
bool get_side_menu_popup_status();
void set_side_menu_popup_status(bool status);
void link_to_network_check();
void link_to_lan_only_wiki();
const wxColour& get_label_clr_modified(){ return m_color_label_modified; }
const wxColour& get_label_clr_modified() { return m_color_label_modified; }
const wxColour& get_label_clr_sys() { return m_color_label_sys; }
const wxColour& get_label_clr_default() { return m_color_label_default; }
const wxColour& get_window_default_clr(){ return m_color_window_default; }
@ -574,6 +575,8 @@ private:
ModelMallDialog* m_mall_publish_dialog{ nullptr };
PingCodeBindDialog* m_ping_code_binding_dialog{ nullptr };
NetworkErrorDialog* m_server_error_dialog { nullptr };
void set_download_model_url(std::string url) {m_mall_model_download_url = url;}
void set_download_model_name(std::string name) {m_mall_model_download_name = name;}
std::string get_download_model_url() {return m_mall_model_download_url;}

View file

@ -660,6 +660,93 @@ wxBoxSizer *Newer3mfVersionDialog::get_btn_sizer()
return horizontal_sizer;
}
NetworkErrorDialog::NetworkErrorDialog(wxWindow* parent)
: DPIDialog(parent ? parent : nullptr, wxID_ANY, _L("Server Exception"), wxDefaultPosition, wxDefaultSize, wxCAPTION | wxCLOSE_BOX)
{
this->SetBackgroundColour(*wxWHITE);
std::string icon_path = (boost::format("%1%/images/BambuStudioTitle.ico") % resources_dir()).str();
SetIcon(wxIcon(encode_path(icon_path.c_str()), wxBITMAP_TYPE_ICO));
wxBoxSizer* sizer_main = new wxBoxSizer(wxVERTICAL);
auto m_line_top = new wxPanel(this, wxID_ANY, wxDefaultPosition, wxSize(-1, 1), wxTAB_TRAVERSAL);
m_line_top->SetBackgroundColour(wxColour(166, 169, 170));
wxBoxSizer* sizer_bacis_text = new wxBoxSizer(wxVERTICAL);
m_text_basic = new Label(this, _L("The server is unable to respond. Please click the link below to check the server status."));
m_text_basic->SetForegroundColour(0x323A3C);
m_text_basic->SetMinSize(wxSize(FromDIP(450), -1));
m_text_basic->SetMaxSize(wxSize(FromDIP(450), -1));
m_text_basic->Wrap(FromDIP(450));
m_text_basic->SetFont(::Label::Body_14);
sizer_bacis_text->Add(m_text_basic, 0, wxALL, 0);
wxBoxSizer* sizer_link = new wxBoxSizer(wxVERTICAL);
m_link_server_state = new wxHyperlinkCtrl(this, wxID_ANY, _L("Check the status of current system services"), "");
m_link_server_state->SetFont(::Label::Body_13);
m_link_server_state->Bind(wxEVT_LEFT_DOWN, [this](auto& e) {wxGetApp().link_to_network_check(); });
m_link_server_state->Bind(wxEVT_ENTER_WINDOW, [this](auto& e) {SetCursor(wxCURSOR_HAND); });
m_link_server_state->Bind(wxEVT_LEAVE_WINDOW, [this](auto& e) {SetCursor(wxCURSOR_ARROW); });
sizer_link->Add(m_link_server_state, 0, wxALL, 0);
wxBoxSizer* sizer_help = new wxBoxSizer(wxVERTICAL);
m_text_proposal = new Label(this, _L("If the server is in a fault state, you can temporarily use offline printing or local network printing."));
m_text_proposal->SetMinSize(wxSize(FromDIP(450), -1));
m_text_proposal->SetMaxSize(wxSize(FromDIP(450), -1));
m_text_proposal->Wrap(FromDIP(450));
m_text_proposal->SetFont(::Label::Body_14);
m_text_proposal->SetForegroundColour(0x323A3C);
m_text_wiki = new wxHyperlinkCtrl(this, wxID_ANY, _L("How to use LAN only mode"), "");
m_text_wiki->SetFont(::Label::Body_13);
m_text_wiki->Bind(wxEVT_LEFT_DOWN, [this](auto& e) {wxGetApp().link_to_lan_only_wiki(); });
m_text_wiki->Bind(wxEVT_ENTER_WINDOW, [this](auto& e) {SetCursor(wxCURSOR_HAND); });
m_text_wiki->Bind(wxEVT_LEAVE_WINDOW, [this](auto& e) {SetCursor(wxCURSOR_ARROW); });
sizer_help->Add(m_text_proposal, 0, wxEXPAND, 0);
sizer_main->Add(0, 0, 0, wxTOP, 6);
sizer_help->Add(m_text_wiki, 0, wxALL, 0);
wxBoxSizer* sizer_button = new wxBoxSizer(wxHORIZONTAL);
sizer_button->Add(0, 0, 1, wxEXPAND, 5);
auto bt_enable = StateColor(std::pair<wxColour, int>(wxColour(27, 136, 68), StateColor::Pressed), std::pair<wxColour, int>(wxColour(61, 203, 115), StateColor::Hovered),
std::pair<wxColour, int>(wxColour(0, 174, 66), StateColor::Normal));
m_button_confirm = new Button(this, _L("Confirm"));
m_button_confirm->SetBackgroundColor(bt_enable);
m_button_confirm->SetBorderColor(bt_enable);
m_button_confirm->SetTextColor(StateColor::darkModeColorFor("#FFFFFE"));
m_button_confirm->SetMinSize(wxSize(FromDIP(68), FromDIP(23)));
m_button_confirm->SetMinSize(wxSize(FromDIP(68), FromDIP(23)));
m_button_confirm->SetCornerRadius(12);
m_button_confirm->Bind(wxEVT_LEFT_DOWN, [this](auto& e) {EndModal(wxCLOSE);});
sizer_button->Add(m_button_confirm, 0, wxALL, 5);
sizer_main->Add(m_line_top, 0, wxEXPAND, 0);
sizer_main->Add(0, 0, 0, wxTOP, 20);
sizer_main->Add(sizer_bacis_text, 0, wxEXPAND | wxLEFT | wxRIGHT, 15);
sizer_main->Add(0, 0, 0, wxTOP, 6);
sizer_main->Add(sizer_link, 0, wxLEFT | wxRIGHT, 15);
sizer_main->Add(0, 0, 0, wxEXPAND | wxTOP, 8);
sizer_main->Add(sizer_help, 1, wxLEFT | wxRIGHT, 15);
sizer_main->Add(0, 0, 0, wxEXPAND | wxTOP, 8);
sizer_main->Add(sizer_button, 1, wxEXPAND | wxLEFT | wxRIGHT, 15);
sizer_main->Add(0, 0, 0, wxTOP, 18);
SetSizer(sizer_main);
Layout();
sizer_main->Fit(this);
Centre(wxBOTH);
}
} // namespace GUI
} // namespace Slic3r

View file

@ -410,6 +410,22 @@ private:
wxStaticText *m_msg_text = nullptr;
};
class NetworkErrorDialog : public DPIDialog
{
public:
NetworkErrorDialog(wxWindow* parent);
~NetworkErrorDialog() {};
virtual void on_dpi_changed(const wxRect& suggested_rect) {};
private:
Label* m_text_basic;
wxHyperlinkCtrl* m_link_server_state;
Label* m_text_proposal;
wxHyperlinkCtrl* m_text_wiki;
Button* m_button_confirm;
};
}
}

View file

@ -76,6 +76,7 @@ func_build_login_info NetworkAgent::build_login_info_ptr = nullptr
func_get_model_id_from_desgin_id NetworkAgent::get_model_id_from_desgin_id_ptr = nullptr;
func_ping_bind NetworkAgent::ping_bind_ptr = nullptr;
func_bind_detect NetworkAgent::bind_detect_ptr = nullptr;
func_set_server_callback NetworkAgent::set_server_callback_ptr = nullptr;
func_bind NetworkAgent::bind_ptr = nullptr;
func_unbind NetworkAgent::unbind_ptr = nullptr;
func_get_bambulab_host NetworkAgent::get_bambulab_host_ptr = nullptr;
@ -286,6 +287,7 @@ int NetworkAgent::initialize_network_module(bool using_backup)
build_login_info_ptr = reinterpret_cast<func_build_login_info>(get_network_function("bambu_network_build_login_info"));
ping_bind_ptr = reinterpret_cast<func_ping_bind>(get_network_function("bambu_network_ping_bind"));
bind_detect_ptr = reinterpret_cast<func_bind_detect>(get_network_function("bambu_network_bind_detect"));
set_server_callback_ptr = reinterpret_cast<func_set_server_callback>(get_network_function("bambu_network_set_server_callback"));
get_model_id_from_desgin_id_ptr = reinterpret_cast<func_get_model_id_from_desgin_id>(get_network_function("bambu_network_get_model_id_from_desgin_id"));
bind_ptr = reinterpret_cast<func_bind>(get_network_function("bambu_network_bind"));
unbind_ptr = reinterpret_cast<func_unbind>(get_network_function("bambu_network_unbind"));
@ -1037,6 +1039,18 @@ int NetworkAgent::bind_detect(std::string dev_ip, std::string sec_link, detectRe
return ret;
}
int NetworkAgent::set_server_callback(OnServerErrFn fn)
{
int ret = 0;
if (network_agent && set_server_callback_ptr) {
ret = set_server_callback_ptr(network_agent, fn);
if (ret)
BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << boost::format(" error: network_agent=%1%, ret=%2%")
% network_agent % ret;
}
return ret;
}
int NetworkAgent::bind(std::string dev_ip, std::string dev_id, std::string sec_link, std::string timezone, bool improved, OnUpdateStatusFn update_fn)
{
int ret = 0;

View file

@ -56,6 +56,7 @@ typedef std::string (*func_build_login_info)(void *agent);
typedef int (*func_get_model_id_from_desgin_id)(void *agent, std::string& desgin_id, std::string& model_id);
typedef int (*func_ping_bind)(void *agent, std::string ping_code);
typedef int (*func_bind_detect)(void *agent, std::string dev_ip, std::string sec_link, detectResult& detect);
typedef int (*func_set_server_callback)(void *agent, OnServerErrFn fn);
typedef int (*func_bind)(void *agent, std::string dev_ip, std::string dev_id, std::string sec_link, std::string timezone, bool improved, OnUpdateStatusFn update_fn);
typedef int (*func_unbind)(void *agent, std::string dev_id);
typedef std::string (*func_get_bambulab_host)(void *agent);
@ -174,6 +175,7 @@ public:
int get_model_id_from_desgin_id(std::string& desgin_id, std::string& model_id);
int ping_bind(std::string ping_code);
int bind_detect(std::string dev_ip, std::string sec_link, detectResult& detect);
int set_server_callback(OnServerErrFn fn);
int bind(std::string dev_ip, std::string dev_id, std::string sec_link, std::string timezone, bool improved, OnUpdateStatusFn update_fn);
int unbind(std::string dev_id);
std::string get_bambulab_host();
@ -282,6 +284,7 @@ private:
static func_get_model_id_from_desgin_id get_model_id_from_desgin_id_ptr;
static func_ping_bind ping_bind_ptr;
static func_bind_detect bind_detect_ptr;
static func_set_server_callback set_server_callback_ptr;
static func_bind bind_ptr;
static func_unbind unbind_ptr;
static func_get_bambulab_host get_bambulab_host_ptr;

View file

@ -138,6 +138,9 @@ typedef std::function<void(int result, std::string info)> ResultFn;
typedef std::function<bool()> CancelFn;
typedef std::function<bool(std::map<std::string, std::string> info)> CheckFn;
//err callbacks
typedef std::function<void(std::string url, int status)> OnServerErrFn;
enum SendingPrintJobStage {
PrintingStageCreate = 0,
PrintingStageUpload = 1,