diff --git a/src/libslic3r/AppConfig.cpp b/src/libslic3r/AppConfig.cpp index 114ac7489a..da6e0a4fa0 100644 --- a/src/libslic3r/AppConfig.cpp +++ b/src/libslic3r/AppConfig.cpp @@ -215,6 +215,9 @@ void AppConfig::set_defaults() if (get("wifi_config_dialog_declined").empty()) set("wifi_config_dialog_declined", "0"); + if (get("connect_polling").empty()) + set("connect_polling", "1"); + #ifdef _WIN32 if (get("use_legacy_3DConnexion").empty()) set("use_legacy_3DConnexion", "0"); diff --git a/src/slic3r/GUI/Auth.cpp b/src/slic3r/GUI/Auth.cpp index 68ed0a2d4b..54e1194858 100644 --- a/src/slic3r/GUI/Auth.cpp +++ b/src/slic3r/GUI/Auth.cpp @@ -147,7 +147,7 @@ PrusaAuthCommunication::PrusaAuthCommunication(wxEvtHandler* evt_handler, AppCon } if (!access_token.empty() || !refresh_token.empty()) m_remember_session = true; - m_session = std::make_unique(evt_handler, access_token, refresh_token, shared_session_key); + m_session = std::make_unique(evt_handler, access_token, refresh_token, shared_session_key, app_config->get_bool("connect_polling")); init_session_thread(); // perform login at the start if (m_remember_session) @@ -193,6 +193,14 @@ std::string PrusaAuthCommunication::get_access_token() } } +void PrusaAuthCommunication::set_polling_enabled(bool enabled) +{ + { + std::lock_guard lock(m_session_mutex); + return m_session->set_polling_enabled(enabled); + } +} + void PrusaAuthCommunication::login_redirect() { const std::string AUTH_HOST = "https://test-account.prusa3d.com"; diff --git a/src/slic3r/GUI/Auth.hpp b/src/slic3r/GUI/Auth.hpp index 408c221139..96832861d9 100644 --- a/src/slic3r/GUI/Auth.hpp +++ b/src/slic3r/GUI/Auth.hpp @@ -58,7 +58,7 @@ public: std::string get_username() const { return m_username; } std::string get_access_token(); - + void set_polling_enabled(bool enabled); private: std::unique_ptr m_session; diff --git a/src/slic3r/GUI/AuthSession.cpp b/src/slic3r/GUI/AuthSession.cpp index 0d625fd5e9..2955a95e60 100644 --- a/src/slic3r/GUI/AuthSession.cpp +++ b/src/slic3r/GUI/AuthSession.cpp @@ -81,8 +81,10 @@ void AuthSession::process_action_queue() if (m_priority_action_queue.empty() && m_action_queue.empty()) { //BOOST_LOG_TRIVIAL(debug) << "process_action_queue queues empty"; // update printers on every periodic wakeup call - enqueue_action(UserActionID::CONNECT_PRINTERS, nullptr, nullptr, {}); - //return; + if (m_polling_enabled) + enqueue_action(UserActionID::CONNECT_PRINTERS, nullptr, nullptr, {}); + else + return; } if (this->is_initialized()) { diff --git a/src/slic3r/GUI/AuthSession.hpp b/src/slic3r/GUI/AuthSession.hpp index 7a5a476d85..5ed7e4a1ae 100644 --- a/src/slic3r/GUI/AuthSession.hpp +++ b/src/slic3r/GUI/AuthSession.hpp @@ -93,10 +93,11 @@ struct ActionQueueData class AuthSession { public: - AuthSession(wxEvtHandler* evt_handler, const std::string& access_token, const std::string& refresh_token, const std::string& shared_session_key) + AuthSession(wxEvtHandler* evt_handler, const std::string& access_token, const std::string& refresh_token, const std::string& shared_session_key, bool polling_enabled) : m_access_token(access_token) , m_refresh_token(refresh_token) , m_shared_session_key(shared_session_key) + , m_polling_enabled(polling_enabled) { // do not forget to add delete to destructor m_actions[UserActionID::DUMMY_ACTION] = std::make_unique(); @@ -134,7 +135,8 @@ public: std::string get_access_token() const { return m_access_token; } std::string get_refresh_token() const { return m_refresh_token; } std::string get_shared_session_key() const { return m_shared_session_key; } - + + void set_polling_enabled(bool enabled) {m_polling_enabled = enabled; } private: void enqueue_test_with_refresh(); void enqueue_refresh(const std::string& body); @@ -145,6 +147,8 @@ private: // false prevents action queu to be processed - no communication is done // sets to true by init_with_code or enqueue_action call bool m_proccessing_enabled {false}; + // triggers CONNECT_PRINTERS action when woken up on idle + bool m_polling_enabled; std::string m_access_token; std::string m_refresh_token;