diff --git a/src/slic3r/GUI/CalibrationPanel.cpp b/src/slic3r/GUI/CalibrationPanel.cpp index b66a347db..3bd5f73f8 100644 --- a/src/slic3r/GUI/CalibrationPanel.cpp +++ b/src/slic3r/GUI/CalibrationPanel.cpp @@ -309,7 +309,6 @@ bool SelectMObjectPopup::Show(bool show) { void SelectMObjectPopup::on_timer(wxTimerEvent& event) { BOOST_LOG_TRIVIAL(trace) << "SelectMObjectPopup on_timer"; - wxGetApp().reset_to_active(); wxCommandEvent user_event(EVT_UPDATE_USER_MLIST); user_event.SetEventObject(this); wxPostEvent(this, user_event); @@ -563,25 +562,8 @@ void CalibrationPanel::update_all() { } } - if (wxGetApp().is_user_login()) { - dev->check_pushing(); - try { - m_agent->refresh_connection(); - } - catch (...) { - ; - } - } - - if (obj) { - m_agent->install_device_cert(obj->dev_id, obj->is_lan_mode_printer()); - } - - if (obj) { - wxGetApp().reset_to_active(); - if (obj->connection_type() != last_conn_type) { - last_conn_type = obj->connection_type(); - } + if (obj && obj->connection_type() != last_conn_type) { + last_conn_type = obj->connection_type(); } m_side_tools->update_status(obj); diff --git a/src/slic3r/GUI/CalibrationWizardPresetPage.cpp b/src/slic3r/GUI/CalibrationWizardPresetPage.cpp index b921400ac..98e70484e 100644 --- a/src/slic3r/GUI/CalibrationWizardPresetPage.cpp +++ b/src/slic3r/GUI/CalibrationWizardPresetPage.cpp @@ -1797,7 +1797,6 @@ void CalibrationPresetPage::update_show_status() DeviceManager* dev = Slic3r::GUI::wxGetApp().getDeviceManager(); if (!agent) {return;} if (!dev) return; - dev->check_pushing(); MachineObject* obj_ = dev->get_selected_machine(); if (!obj_) { @@ -1812,7 +1811,6 @@ void CalibrationPresetPage::update_show_status() if (!obj_->is_lan_mode_printer()) { if (!agent->is_server_connected()) { - agent->refresh_connection(); show_status(CaliPresetPageStatus::CaliPresetStatusConnectingServer); return; } diff --git a/src/slic3r/GUI/DeviceManager.cpp b/src/slic3r/GUI/DeviceManager.cpp index a71ec6b67..25706ef91 100644 --- a/src/slic3r/GUI/DeviceManager.cpp +++ b/src/slic3r/GUI/DeviceManager.cpp @@ -6682,10 +6682,13 @@ std::vector nozzle_type_list{ "hardened_steel", "stainless_steel" } DeviceManager::DeviceManager(NetworkAgent* agent) { m_agent = agent; + m_refresher = new DeviceManagerRefresher(this); } DeviceManager::~DeviceManager() { + delete m_refresher; + for (auto it = localMachineList.begin(); it != localMachineList.end(); it++) { if (it->second) { delete it->second; @@ -6747,6 +6750,8 @@ void DeviceManager::set_agent(NetworkAgent* agent) m_agent = agent; } +void DeviceManager::start_refresher() { m_refresher->Start(); } +void DeviceManager::stop_refresher() { m_refresher->Stop(); } void DeviceManager::keep_alive() { MachineObject* obj = this->get_selected_machine(); @@ -7738,6 +7743,51 @@ std::string DeviceManager::load_gcode(std::string type_str, std::string gcode_fi return ""; } +DeviceManagerRefresher::DeviceManagerRefresher(DeviceManager *manger) : wxObject() { + m_manager = manger; + m_timer = new wxTimer(); + m_timer->Bind(wxEVT_TIMER, &DeviceManagerRefresher::on_timer, this); +} + +DeviceManagerRefresher::~DeviceManagerRefresher() { + m_timer->Stop(); + delete m_timer; +} + +void DeviceManagerRefresher::on_timer(wxTimerEvent &event) { + if (!m_manager) { return;} + + NetworkAgent *agent = m_manager->get_agent(); + if (!agent) { return; } + + // reset to active + Slic3r::GUI::wxGetApp().reset_to_active(); + + MachineObject *obj = m_manager->get_selected_machine(); + if (!obj) { return; } + + // check valid machine + if (obj && m_manager->get_my_machine(obj->dev_id) == nullptr) { + m_manager->set_selected_machine(""); + agent->set_user_selected_machine(""); + return; + } + + // do some refresh + if (Slic3r::GUI::wxGetApp().is_user_login()) + { + m_manager->check_pushing(); + try { + agent->refresh_connection(); + } catch (...) { + ; + } + } + + // certificate + agent->install_device_cert(obj->dev_id, obj->is_lan_mode_printer()); +} + void change_the_opacity(wxColour& colour) { if (colour.Alpha() == 255) { diff --git a/src/slic3r/GUI/DeviceManager.hpp b/src/slic3r/GUI/DeviceManager.hpp index c509d7268..7c69fe989 100644 --- a/src/slic3r/GUI/DeviceManager.hpp +++ b/src/slic3r/GUI/DeviceManager.hpp @@ -17,6 +17,9 @@ #include "CameraPopup.hpp" #include "libslic3r/Calib.hpp" #include "libslic3r/Utils.hpp" + +#include + #define USE_LOCAL_SOCKET_BIND 0 #define DISCONNECT_TIMEOUT 30000.f // milliseconds @@ -1355,15 +1358,19 @@ private: time_t xcam__save_remote_print_file_to_storage_start_time = 0; }; +class DeviceManagerRefresher; class DeviceManager { private: - NetworkAgent* m_agent { nullptr }; + NetworkAgent* m_agent { nullptr }; + DeviceManagerRefresher* m_refresher{nullptr}; + public: static bool EnableMultiMachine; DeviceManager(NetworkAgent* agent = nullptr); ~DeviceManager(); + NetworkAgent *get_agent() const{ return m_agent; } void set_agent(NetworkAgent* agent); std::mutex listMutex; @@ -1372,6 +1379,9 @@ public: std::map localMachineList; /* dev_id -> MachineObject*, localMachine SSDP */ std::map userMachineList; /* dev_id -> MachineObject* cloudMachine of User */ + void start_refresher(); + void stop_refresher(); + void keep_alive(); void check_pushing(); @@ -1464,8 +1474,29 @@ public: static std::string load_gcode(std::string type_str, std::string gcode_file); static bool is_virtual_slot(int ams_id); static std::string get_filament_name_from_ams(int ams_id, int slot_id); + }; +class DeviceManagerRefresher : public wxObject +{ + wxTimer *m_timer{nullptr}; + int m_timer_interval_msec = 1000; + + DeviceManager *m_manager{nullptr}; + +public: + DeviceManagerRefresher(DeviceManager* manger); + ~DeviceManagerRefresher(); + +public: + void Start() { m_timer->Start(m_timer_interval_msec); } + void Stop() { m_timer->Stop(); } + +protected: + virtual void on_timer(wxTimerEvent &event); +}; + + // change the opacity void change_the_opacity(wxColour& colour); diff --git a/src/slic3r/GUI/MainFrame.cpp b/src/slic3r/GUI/MainFrame.cpp index e2172ae8b..54d315d0e 100644 --- a/src/slic3r/GUI/MainFrame.cpp +++ b/src/slic3r/GUI/MainFrame.cpp @@ -677,6 +677,13 @@ DPIFrame(NULL, wxID_ANY, "", wxDefaultPosition, wxDefaultSize, BORDERLESS_FRAME_ evt.Skip(); }); + Bind(wxEVT_SHOW, [this](wxShowEvent &evt) { + DeviceManager *manger = wxGetApp().getDeviceManager(); + if (manger) { + evt.IsShown() ? manger->start_refresher() : manger->stop_refresher(); + } + }); + #ifdef _MSW_DARK_MODE wxGetApp().UpdateDarkUIWin(this); #endif // _MSW_DARK_MODE diff --git a/src/slic3r/GUI/Monitor.cpp b/src/slic3r/GUI/Monitor.cpp index baaa0e38b..ad576e891 100644 --- a/src/slic3r/GUI/Monitor.cpp +++ b/src/slic3r/GUI/Monitor.cpp @@ -353,41 +353,9 @@ void MonitorPanel::update_all() { NetworkAgent* m_agent = wxGetApp().getAgent(); Slic3r::DeviceManager* dev = Slic3r::GUI::wxGetApp().getDeviceManager(); - if (!dev) - return; + if (!dev) return; obj = dev->get_selected_machine(); - // check valid machine - if (obj && dev->get_my_machine(obj->dev_id) == nullptr) { - dev->set_selected_machine(""); - if (m_agent) - m_agent->set_user_selected_machine(""); - show_status((int)MONITOR_NO_PRINTER); - return; - } - - - //BBS check mqtt connections if user is login - if (wxGetApp().is_user_login()) { - dev->check_pushing(); - // check mqtt connection and reconnect if disconnected - try { - m_agent->refresh_connection(); - } - catch (...) { - ; - } - } - if (obj) - m_agent->install_device_cert(obj->dev_id, obj->is_lan_mode_printer()); - - if (obj) { - wxGetApp().reset_to_active(); - if (obj->connection_type() != last_conn_type) { - last_conn_type = obj->connection_type(); - } - } - m_status_info_panel->obj = obj; m_upgrade_panel->update(obj); m_status_info_panel->m_media_play_ctrl->SetMachineObject(obj); @@ -402,6 +370,7 @@ void MonitorPanel::update_all() return; } + if (obj->connection_type() != last_conn_type) { last_conn_type = obj->connection_type(); } if (obj->is_connecting()) { show_status(MONITOR_CONNECTING); return; diff --git a/src/slic3r/GUI/SelectMachine.cpp b/src/slic3r/GUI/SelectMachine.cpp index 7b473ee06..52ccffdc3 100644 --- a/src/slic3r/GUI/SelectMachine.cpp +++ b/src/slic3r/GUI/SelectMachine.cpp @@ -3053,7 +3053,6 @@ void SelectMachineDialog::update_printer_combobox(wxCommandEvent &event) void SelectMachineDialog::on_timer(wxTimerEvent &event) { - wxGetApp().reset_to_active(); update_show_status(); ///show auto refill @@ -3309,7 +3308,6 @@ void SelectMachineDialog::update_show_status() return; } if (!dev) return; - dev->check_pushing(); PartPlate* plate = m_plater->get_partplate_list().get_curr_plate(); @@ -3333,12 +3331,10 @@ void SelectMachineDialog::update_show_status() } return; } - agent->install_device_cert(obj_->dev_id, obj_->is_lan_mode_printer()); /* check cloud machine connections */ if (!obj_->is_lan_mode_printer()) { if (!agent->is_server_connected()) { - agent->refresh_connection(); show_status(PrintDialogStatus::PrintStatusConnectingServer); reset_timeout(); return; diff --git a/src/slic3r/GUI/SendToPrinter.cpp b/src/slic3r/GUI/SendToPrinter.cpp index 1c21c971b..c43a61dba 100644 --- a/src/slic3r/GUI/SendToPrinter.cpp +++ b/src/slic3r/GUI/SendToPrinter.cpp @@ -1111,7 +1111,6 @@ void SendToPrinterDialog::update_printer_combobox(wxCommandEvent &event) void SendToPrinterDialog::on_timer(wxTimerEvent &event) { - wxGetApp().reset_to_active(); update_show_status(); } @@ -1182,7 +1181,6 @@ void SendToPrinterDialog::update_show_status() /* check cloud machine connections */ if (!obj_->is_lan_mode_printer()) { if (!agent->is_server_connected()) { - agent->refresh_connection(); show_status(PrintDialogStatus::PrintStatusConnectingServer); reset_timeout(); return; @@ -1678,7 +1676,6 @@ bool SendToPrinterDialog::Show(bool show) if (show) { m_ability_list.clear(); //update_storage_list(std::vector()); - wxGetApp().reset_to_active(); set_default(); update_user_machine_list(); } diff --git a/src/slic3r/GUI/SyncAmsInfoDialog.cpp b/src/slic3r/GUI/SyncAmsInfoDialog.cpp index 1b7627c63..74e4d4afb 100644 --- a/src/slic3r/GUI/SyncAmsInfoDialog.cpp +++ b/src/slic3r/GUI/SyncAmsInfoDialog.cpp @@ -61,7 +61,6 @@ bool SyncAmsInfoDialog::Show(bool show) } // set default value when show this dialog wxGetApp().UpdateDlgDarkUI(this); - wxGetApp().reset_to_active(); set_default(true); reinit_dialog(); update_user_machine_list(); @@ -2367,7 +2366,6 @@ void SyncAmsInfoDialog::update_printer_combobox(wxCommandEvent &event) void SyncAmsInfoDialog::on_timer(wxTimerEvent &event) { - wxGetApp().reset_to_active(); update_show_status(); /// show auto refill @@ -2417,7 +2415,6 @@ void SyncAmsInfoDialog::update_show_status() return; } if (!dev) return; - dev->check_pushing(); // blank plate has no valid gcode file if (is_must_finish_slice_then_connected_printer()) { return; } @@ -2433,12 +2430,10 @@ void SyncAmsInfoDialog::update_show_status() } return; } - agent->install_device_cert(obj_->dev_id, obj_->is_lan_mode_printer()); /* check cloud machine connections */ if (!obj_->is_lan_mode_printer()) { if (!agent->is_server_connected()) { - agent->refresh_connection(); show_status(PrintDialogStatus::PrintStatusConnectingServer); reset_timeout(); return;