connect_polling app config variable

Can be used to disable periodical update of Connect printers.
This commit is contained in:
David Kocik 2024-01-09 15:06:09 +01:00
parent db43c069d9
commit 30a1279d90
5 changed files with 23 additions and 6 deletions

View File

@ -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");

View File

@ -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<AuthSession>(evt_handler, access_token, refresh_token, shared_session_key);
m_session = std::make_unique<AuthSession>(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<std::mutex> 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";

View File

@ -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<AuthSession> m_session;

View File

@ -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()) {

View File

@ -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<DummyUserAction>();
@ -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;