diff --git a/src/slic3r/GUI/UserAccount.cpp b/src/slic3r/GUI/UserAccount.cpp index 0b06c2d5e9..8bcc62e89b 100644 --- a/src/slic3r/GUI/UserAccount.cpp +++ b/src/slic3r/GUI/UserAccount.cpp @@ -152,10 +152,6 @@ void UserAccount::on_communication_fail() m_communication->enqueue_test_connection(); m_fail_counter = 0; } - // Printer models are called only after login, if it fails, it should repeat - if (m_printer_uuid_map.empty()) { - enqueue_connect_printer_models_action(); - } } namespace { @@ -299,6 +295,7 @@ bool UserAccount::on_connect_uiid_map_success(const std::string& data, AppConfig } m_printer_uuid_map[*printer_uuid] = *printer_model; } + m_communication->on_uuid_map_success(); return on_connect_printers_success(data, app_config, out_printers_changed); } diff --git a/src/slic3r/GUI/UserAccountCommunication.cpp b/src/slic3r/GUI/UserAccountCommunication.cpp index fabc1b8e4a..6c7834d8e6 100644 --- a/src/slic3r/GUI/UserAccountCommunication.cpp +++ b/src/slic3r/GUI/UserAccountCommunication.cpp @@ -214,7 +214,15 @@ void UserAccountCommunication::set_polling_enabled(bool enabled) { { std::lock_guard lock(m_session_mutex); - return m_session->set_polling_enabled(enabled); + return m_session->set_polling_action(enabled ? UserAccountActionID::USER_ACCOUNT_ACTION_CONNECT_PRINTER_MODELS : UserAccountActionID::USER_ACCOUNT_ACTION_DUMMY); + } +} + +void UserAccountCommunication::on_uuid_map_success() +{ + { + std::lock_guard lock(m_session_mutex); + return m_session->set_polling_action(UserAccountActionID::USER_ACCOUNT_ACTION_CONNECT_STATUS); } } diff --git a/src/slic3r/GUI/UserAccountCommunication.hpp b/src/slic3r/GUI/UserAccountCommunication.hpp index 0dcd3864d2..15fc41aece 100644 --- a/src/slic3r/GUI/UserAccountCommunication.hpp +++ b/src/slic3r/GUI/UserAccountCommunication.hpp @@ -60,7 +60,8 @@ public: std::string get_shared_session_key(); void set_polling_enabled(bool enabled); - + // we have map of uuids and printer_models - set polling action to lightweight STATUS action + void on_uuid_map_success(); private: std::unique_ptr m_session; std::thread m_thread; diff --git a/src/slic3r/GUI/UserAccountSession.cpp b/src/slic3r/GUI/UserAccountSession.cpp index 9c2b588179..65bfc670ab 100644 --- a/src/slic3r/GUI/UserAccountSession.cpp +++ b/src/slic3r/GUI/UserAccountSession.cpp @@ -75,11 +75,7 @@ void UserAccountSession::process_action_queue() return; if (m_priority_action_queue.empty() && m_action_queue.empty()) { // update printers periodically - if (m_polling_enabled) { - enqueue_action(UserAccountActionID::USER_ACCOUNT_ACTION_CONNECT_STATUS, nullptr, nullptr, {}); - } else { - return; - } + enqueue_action(m_polling_action, nullptr, nullptr, {}); } // priority queue works even when tokens are empty or broken while (!m_priority_action_queue.empty()) { diff --git a/src/slic3r/GUI/UserAccountSession.hpp b/src/slic3r/GUI/UserAccountSession.hpp index b40ab54f19..eaaafac0c1 100644 --- a/src/slic3r/GUI/UserAccountSession.hpp +++ b/src/slic3r/GUI/UserAccountSession.hpp @@ -38,8 +38,8 @@ enum class UserAccountActionID { USER_ACCOUNT_ACTION_USER_ID, USER_ACCOUNT_ACTION_TEST_ACCESS_TOKEN, USER_ACCOUNT_ACTION_TEST_CONNECTION, - USER_ACCOUNT_ACTION_CONNECT_STATUS, // status of all printers - USER_ACCOUNT_ACTION_CONNECT_PRINTER_MODELS, + USER_ACCOUNT_ACTION_CONNECT_STATUS, // status of all printers by UUID + USER_ACCOUNT_ACTION_CONNECT_PRINTER_MODELS, // status of all printers by UUID with printer_model. Should be called once to save printer models. USER_ACCOUNT_ACTION_AVATAR, }; class UserAction @@ -101,7 +101,7 @@ public: , m_access_token(access_token) , m_refresh_token(refresh_token) , m_shared_session_key(shared_session_key) - , m_polling_enabled(polling_enabled) + , m_polling_action(polling_enabled ? UserAccountActionID::USER_ACCOUNT_ACTION_CONNECT_PRINTER_MODELS : UserAccountActionID::USER_ACCOUNT_ACTION_DUMMY) { @@ -146,7 +146,8 @@ public: 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; } + //void set_polling_enabled(bool enabled) {m_polling_action = enabled ? UserAccountActionID::USER_ACCOUNT_ACTION_CONNECT_PRINTER_MODELS : UserAccountActionID::USER_ACCOUNT_ACTION_DUMMY; } + void set_polling_action(UserAccountActionID action) { m_polling_action = action; } private: void enqueue_refresh(const std::string& body); @@ -159,8 +160,9 @@ 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; + // action when woken up on idle - switches between USER_ACCOUNT_ACTION_CONNECT_PRINTER_MODELS and USER_ACCOUNT_ACTION_CONNECT_STATUS + // set to USER_ACCOUNT_ACTION_DUMMY to switch off polling + UserAccountActionID m_polling_action; std::string m_access_token; std::string m_refresh_token;