diff --git a/src/slic3r/GUI/Auth.cpp b/src/slic3r/GUI/Auth.cpp index 7b2cd54e5b..23cb4b5ce2 100644 --- a/src/slic3r/GUI/Auth.cpp +++ b/src/slic3r/GUI/Auth.cpp @@ -130,7 +130,7 @@ bool load_secret(const std::string& opt, std::string& usr, std::string& psswd) } } -PrusaAuthCommunication::PrusaAuthCommunication(wxEvtHandler* evt_handler, AppConfig* app_config) +UserAccountCommunication::UserAccountCommunication(wxEvtHandler* evt_handler, AppConfig* app_config) : m_evt_handler(evt_handler) , m_app_config(app_config) { @@ -147,14 +147,14 @@ PrusaAuthCommunication::PrusaAuthCommunication(wxEvtHandler* evt_handler, AppCon shared_session_key = m_app_config->get("shared_session_key"); } bool has_token = !access_token.empty() && !refresh_token.empty(); - m_session = std::make_unique(evt_handler, access_token, refresh_token, shared_session_key, m_app_config->get_bool("connect_polling")); + m_session = std::make_unique(evt_handler, access_token, refresh_token, shared_session_key, m_app_config->get_bool("connect_polling")); init_session_thread(); // perform login at the start, but only with tokens if (has_token) do_login(); } -PrusaAuthCommunication::~PrusaAuthCommunication() { +UserAccountCommunication::~UserAccountCommunication() { if (m_thread.joinable()) { // Stop the worker thread, if running. { @@ -168,7 +168,7 @@ PrusaAuthCommunication::~PrusaAuthCommunication() { } } -void PrusaAuthCommunication::set_username(const std::string& username) +void UserAccountCommunication::set_username(const std::string& username) { m_username = username; { @@ -185,14 +185,14 @@ void PrusaAuthCommunication::set_username(const std::string& username) } } -void PrusaAuthCommunication::set_remember_session(bool b) +void UserAccountCommunication::set_remember_session(bool b) { m_remember_session = b; // tokens needs to be stored or deleted set_username(m_username); } -std::string PrusaAuthCommunication::get_access_token() +std::string UserAccountCommunication::get_access_token() { { std::lock_guard lock(m_session_mutex); @@ -200,7 +200,7 @@ std::string PrusaAuthCommunication::get_access_token() } } -void PrusaAuthCommunication::set_polling_enabled(bool enabled) +void UserAccountCommunication::set_polling_enabled(bool enabled) { { std::lock_guard lock(m_session_mutex); @@ -208,7 +208,7 @@ void PrusaAuthCommunication::set_polling_enabled(bool enabled) } } -void PrusaAuthCommunication::login_redirect() +void UserAccountCommunication::login_redirect() { const std::string AUTH_HOST = "https://test-account.prusa3d.com"; const std::string CLIENT_ID = client_id(); @@ -223,11 +223,11 @@ void PrusaAuthCommunication::login_redirect() wxQueueEvent(m_evt_handler,new OpenPrusaAuthEvent(GUI::EVT_OPEN_PRUSAAUTH, std::move(url))); } -bool PrusaAuthCommunication::is_logged() +bool UserAccountCommunication::is_logged() { return !m_username.empty(); } -void PrusaAuthCommunication::do_login() +void UserAccountCommunication::do_login() { { std::lock_guard lock(m_session_mutex); @@ -239,13 +239,13 @@ void PrusaAuthCommunication::do_login() } wakeup_session_thread(); } -void PrusaAuthCommunication::do_logout() +void UserAccountCommunication::do_logout() { do_clear(); - wxQueueEvent(m_evt_handler, new PrusaAuthSuccessEvent(GUI::EVT_LOGGEDOUT_PRUSAAUTH, {})); + wxQueueEvent(m_evt_handler, new UserAccountSuccessEvent(GUI::EVT_UA_LOGGEDOUT, {})); } -void PrusaAuthCommunication::do_clear() +void UserAccountCommunication::do_clear() { { std::lock_guard lock(m_session_mutex); @@ -254,7 +254,7 @@ void PrusaAuthCommunication::do_clear() set_username({}); } -void PrusaAuthCommunication::on_login_code_recieved(const std::string& url_message) +void UserAccountCommunication::on_login_code_recieved(const std::string& url_message) { { std::lock_guard lock(m_session_mutex); @@ -265,19 +265,19 @@ void PrusaAuthCommunication::on_login_code_recieved(const std::string& url_messa } #if 0 -void PrusaAuthCommunication::enqueue_user_id_action() +void UserAccountCommunication::enqueue_user_id_action() { { std::lock_guard lock(m_session_mutex); if (!m_session->is_initialized()) { return; } - m_session->enqueue_action(UserActionID::USER_ID, nullptr, nullptr, {}); + m_session->enqueue_action(UserAccountActionID::USER_ID, nullptr, nullptr, {}); } wakeup_session_thread(); } -void PrusaAuthCommunication::enqueue_connect_dummy_action() +void UserAccountCommunication::enqueue_connect_dummy_action() { { std::lock_guard lock(m_session_mutex); @@ -285,13 +285,13 @@ void PrusaAuthCommunication::enqueue_connect_dummy_action() BOOST_LOG_TRIVIAL(error) << "Connect Dummy endpoint connection failed - Not Logged in."; return; } - m_session->enqueue_action(UserActionID::CONNECT_DUMMY, nullptr, nullptr, {}); + m_session->enqueue_action(UserAccountActionID::CONNECT_DUMMY, nullptr, nullptr, {}); } wakeup_session_thread(); } #endif 0 -void PrusaAuthCommunication::enqueue_connect_printers_action() +void UserAccountCommunication::enqueue_connect_printers_action() { { std::lock_guard lock(m_session_mutex); @@ -299,11 +299,11 @@ void PrusaAuthCommunication::enqueue_connect_printers_action() BOOST_LOG_TRIVIAL(error) << "Connect Printers endpoint connection failed - Not Logged in."; return; } - m_session->enqueue_action(UserActionID::AUTH_ACTION_CONNECT_PRINTERS, nullptr, nullptr, {}); + m_session->enqueue_action(UserAccountActionID::USER_ACCOUNT_ACTION_CONNECT_PRINTERS, nullptr, nullptr, {}); } wakeup_session_thread(); } -void PrusaAuthCommunication::enqueue_test_connection() +void UserAccountCommunication::enqueue_test_connection() { { std::lock_guard lock(m_session_mutex); @@ -311,12 +311,12 @@ void PrusaAuthCommunication::enqueue_test_connection() BOOST_LOG_TRIVIAL(error) << "Connect Printers endpoint connection failed - Not Logged in."; return; } - m_session->enqueue_action(UserActionID::AUTH_ACTION_TEST_CONNECTION, nullptr, nullptr, {}); + m_session->enqueue_action(UserAccountActionID::USER_ACCOUNT_ACTION_TEST_CONNECTION, nullptr, nullptr, {}); } wakeup_session_thread(); } -void PrusaAuthCommunication::enqueue_avatar_action(const std::string url) +void UserAccountCommunication::enqueue_avatar_action(const std::string url) { { std::lock_guard lock(m_session_mutex); @@ -324,11 +324,11 @@ void PrusaAuthCommunication::enqueue_avatar_action(const std::string url) BOOST_LOG_TRIVIAL(error) << "Connect Printers endpoint connection failed - Not Logged in."; return; } - m_session->enqueue_action(UserActionID::AUTH_ACTION_AVATAR, nullptr, nullptr, url); + m_session->enqueue_action(UserAccountActionID::USER_ACCOUNT_ACTION_AVATAR, nullptr, nullptr, url); } wakeup_session_thread(); } -void PrusaAuthCommunication::init_session_thread() +void UserAccountCommunication::init_session_thread() { m_thread = std::thread([this]() { for (;;) { @@ -349,7 +349,7 @@ void PrusaAuthCommunication::init_session_thread() }); } -void PrusaAuthCommunication::wakeup_session_thread() +void UserAccountCommunication::wakeup_session_thread() { m_thread_stop_condition.notify_all(); } diff --git a/src/slic3r/GUI/Auth.hpp b/src/slic3r/GUI/Auth.hpp index b536ea6b4b..bda8112cdb 100644 --- a/src/slic3r/GUI/Auth.hpp +++ b/src/slic3r/GUI/Auth.hpp @@ -26,10 +26,10 @@ private: std::string sha256(const std::string& input); }; -class PrusaAuthCommunication { +class UserAccountCommunication { public: - PrusaAuthCommunication(wxEvtHandler* evt_handler, AppConfig* app_config); - ~PrusaAuthCommunication(); + UserAccountCommunication(wxEvtHandler* evt_handler, AppConfig* app_config); + ~UserAccountCommunication(); // UI Session thread Interface // @@ -63,7 +63,7 @@ public: void set_polling_enabled(bool enabled); private: - std::unique_ptr m_session; + std::unique_ptr m_session; std::thread m_thread; std::mutex m_session_mutex; std::mutex m_thread_stop_mutex; diff --git a/src/slic3r/GUI/AuthSession.cpp b/src/slic3r/GUI/AuthSession.cpp index 6f0026038b..925741b426 100644 --- a/src/slic3r/GUI/AuthSession.cpp +++ b/src/slic3r/GUI/AuthSession.cpp @@ -19,15 +19,13 @@ namespace Slic3r { namespace GUI { wxDEFINE_EVENT(EVT_OPEN_PRUSAAUTH, OpenPrusaAuthEvent); -wxDEFINE_EVENT(EVT_LOGGEDOUT_PRUSAAUTH, PrusaAuthSuccessEvent); -wxDEFINE_EVENT(EVT_PA_ID_USER_SUCCESS, PrusaAuthSuccessEvent); -wxDEFINE_EVENT(EVT_PA_ID_USER_FAIL, PrusaAuthFailEvent); -wxDEFINE_EVENT(EVT_PRUSAAUTH_SUCCESS, PrusaAuthSuccessEvent); -wxDEFINE_EVENT(EVT_PRUSACONNECT_PRINTERS_SUCCESS, PrusaAuthSuccessEvent); -wxDEFINE_EVENT(EVT_PA_AVATAR_SUCCESS, PrusaAuthSuccessEvent); -wxDEFINE_EVENT(EVT_PRUSAAUTH_FAIL, PrusaAuthFailEvent); -wxDEFINE_EVENT(EVT_PA_AVATAR_FAIL, PrusaAuthFailEvent); -wxDEFINE_EVENT(EVT_PRUSAAUTH_RESET, PrusaAuthFailEvent); +wxDEFINE_EVENT(EVT_UA_LOGGEDOUT, UserAccountSuccessEvent); +wxDEFINE_EVENT(EVT_UA_ID_USER_SUCCESS, UserAccountSuccessEvent); +wxDEFINE_EVENT(EVT_UA_SUCCESS, UserAccountSuccessEvent); +wxDEFINE_EVENT(EVT_UA_PRUSACONNECT_PRINTERS_SUCCESS, UserAccountSuccessEvent); +wxDEFINE_EVENT(EVT_UA_AVATAR_SUCCESS, UserAccountSuccessEvent); +wxDEFINE_EVENT(EVT_UA_FAIL, UserAccountFailEvent); +wxDEFINE_EVENT(EVT_UA_RESET, UserAccountFailEvent); void UserActionPost::perform(/*UNUSED*/ wxEvtHandler* evt_handler, /*UNUSED*/ const std::string& access_token, UserActionSuccessFn success_callback, UserActionFailFn fail_callback, const std::string& input) @@ -59,26 +57,26 @@ void UserActionGetWithEvent::perform(wxEvtHandler* evt_handler, const std::strin fail_callback(body); std::string message = GUI::format("%1% action failed (%2%): %3%", action_name, std::to_string(status), body); if (fail_evt_type != wxEVT_NULL) - wxQueueEvent(evt_handler, new PrusaAuthFailEvent(fail_evt_type, std::move(message))); + wxQueueEvent(evt_handler, new UserAccountFailEvent(fail_evt_type, std::move(message))); }); http.on_complete([evt_handler, success_callback, succ_evt_type = m_succ_evt_type](std::string body, unsigned status) { if (success_callback) success_callback(body); if (succ_evt_type != wxEVT_NULL) - wxQueueEvent(evt_handler, new PrusaAuthSuccessEvent(succ_evt_type, body)); + wxQueueEvent(evt_handler, new UserAccountSuccessEvent(succ_evt_type, body)); }); http.perform_sync(); } -void AuthSession::process_action_queue() +void UserAccountSession::process_action_queue() { if (!m_proccessing_enabled) return; if (m_priority_action_queue.empty() && m_action_queue.empty()) { // update printers on every periodic wakeup call if (m_polling_enabled) - enqueue_action(UserActionID::AUTH_ACTION_CONNECT_PRINTERS, nullptr, nullptr, {}); + enqueue_action(UserAccountActionID::USER_ACCOUNT_ACTION_CONNECT_PRINTERS, nullptr, nullptr, {}); else return; } @@ -98,14 +96,14 @@ void AuthSession::process_action_queue() } } -void AuthSession::enqueue_action(UserActionID id, UserActionSuccessFn success_callback, UserActionFailFn fail_callback, const std::string& input) +void UserAccountSession::enqueue_action(UserAccountActionID id, UserActionSuccessFn success_callback, UserActionFailFn fail_callback, const std::string& input) { m_proccessing_enabled = true; m_action_queue.push({ id, success_callback, fail_callback, input }); } -void AuthSession::init_with_code(const std::string& code, const std::string& code_verifier) +void UserAccountSession::init_with_code(const std::string& code, const std::string& code_verifier) { // Data we have const std::string REDIRECT_URI = "prusaslicer://login"; @@ -117,13 +115,13 @@ void AuthSession::init_with_code(const std::string& code, const std::string& cod m_proccessing_enabled = true; // fail fn might be cancel_queue here - m_priority_action_queue.push({ UserActionID::AUTH_ACTION_CODE_FOR_TOKEN - , std::bind(&AuthSession::token_success_callback, this, std::placeholders::_1) - , std::bind(&AuthSession::code_exchange_fail_callback, this, std::placeholders::_1) + m_priority_action_queue.push({ UserAccountActionID::USER_ACCOUNT_ACTION_CODE_FOR_TOKEN + , std::bind(&UserAccountSession::token_success_callback, this, std::placeholders::_1) + , std::bind(&UserAccountSession::code_exchange_fail_callback, this, std::placeholders::_1) , post_fields }); } -void AuthSession::token_success_callback(const std::string& body) +void UserAccountSession::token_success_callback(const std::string& body) { // Data we need std::string access_token, refresh_token, shared_session_key; @@ -145,7 +143,7 @@ void AuthSession::token_success_callback(const std::string& body) } catch (const std::exception&) { std::string msg = "Could not parse server response after code exchange."; - wxQueueEvent(p_evt_handler, new PrusaAuthFailEvent(EVT_PRUSAAUTH_RESET, std::move(msg))); + wxQueueEvent(p_evt_handler, new UserAccountFailEvent(EVT_UA_RESET, std::move(msg))); return; } @@ -155,7 +153,7 @@ void AuthSession::token_success_callback(const std::string& body) m_access_token = std::string(); m_refresh_token = std::string(); m_shared_session_key = std::string(); - wxQueueEvent(p_evt_handler, new PrusaAuthFailEvent(EVT_PRUSAAUTH_RESET, std::move(msg))); + wxQueueEvent(p_evt_handler, new UserAccountFailEvent(EVT_UA_RESET, std::move(msg))); return; } @@ -166,49 +164,49 @@ void AuthSession::token_success_callback(const std::string& body) m_access_token = access_token; m_refresh_token = refresh_token; m_shared_session_key = shared_session_key; - enqueue_action(UserActionID::AUTH_ACTION_USER_ID, nullptr, nullptr, {}); + enqueue_action(UserAccountActionID::USER_ACCOUNT_ACTION_USER_ID, nullptr, nullptr, {}); } -void AuthSession::code_exchange_fail_callback(const std::string& body) +void UserAccountSession::code_exchange_fail_callback(const std::string& body) { clear(); cancel_queue(); - // Unlike refresh_fail_callback, no event was triggered so far, do it. (AUTH_ACTION_CODE_FOR_TOKEN does not send events) - wxQueueEvent(p_evt_handler, new PrusaAuthFailEvent(EVT_PRUSAAUTH_RESET, std::move(body))); + // Unlike refresh_fail_callback, no event was triggered so far, do it. (USER_ACCOUNT_ACTION_CODE_FOR_TOKEN does not send events) + wxQueueEvent(p_evt_handler, new UserAccountFailEvent(EVT_UA_RESET, std::move(body))); } -void AuthSession::enqueue_test_with_refresh() +void UserAccountSession::enqueue_test_with_refresh() { // on test fail - try refresh m_proccessing_enabled = true; - m_priority_action_queue.push({ UserActionID::AUTH_ACTION_TEST_ACCESS_TOKEN, nullptr, std::bind(&AuthSession::enqueue_refresh, this, std::placeholders::_1), {} }); + m_priority_action_queue.push({ UserAccountActionID::USER_ACCOUNT_ACTION_TEST_ACCESS_TOKEN, nullptr, std::bind(&UserAccountSession::enqueue_refresh, this, std::placeholders::_1), {} }); } -void AuthSession::enqueue_refresh(const std::string& body) +void UserAccountSession::enqueue_refresh(const std::string& body) { assert(!m_refresh_token.empty()); std::string post_fields = "grant_type=refresh_token" "&client_id=" + client_id() + "&refresh_token=" + m_refresh_token; - m_priority_action_queue.push({ UserActionID::AUTH_ACTION_REFRESH_TOKEN - , std::bind(&AuthSession::token_success_callback, this, std::placeholders::_1) - , std::bind(&AuthSession::refresh_fail_callback, this, std::placeholders::_1) + m_priority_action_queue.push({ UserAccountActionID::USER_ACCOUNT_ACTION_REFRESH_TOKEN + , std::bind(&UserAccountSession::token_success_callback, this, std::placeholders::_1) + , std::bind(&UserAccountSession::refresh_fail_callback, this, std::placeholders::_1) , post_fields }); } -void AuthSession::refresh_fail_callback(const std::string& body) +void UserAccountSession::refresh_fail_callback(const std::string& body) { clear(); cancel_queue(); // No need to notify UI thread here // backtrace: load tokens -> TEST_TOKEN fail (access token bad) -> REFRESH_TOKEN fail (refresh token bad) - // AUTH_ACTION_TEST_ACCESS_TOKEN triggers EVT_PRUSAAUTH_FAIL, we need also RESET - wxQueueEvent(p_evt_handler, new PrusaAuthFailEvent(EVT_PRUSAAUTH_RESET, std::move(body))); + // USER_ACCOUNT_ACTION_TEST_ACCESS_TOKEN triggers EVT_UA_FAIL, we need also RESET + wxQueueEvent(p_evt_handler, new UserAccountFailEvent(EVT_UA_RESET, std::move(body))); } -void AuthSession::cancel_queue() +void UserAccountSession::cancel_queue() { while (!m_priority_action_queue.empty()) { m_priority_action_queue.pop(); diff --git a/src/slic3r/GUI/AuthSession.hpp b/src/slic3r/GUI/AuthSession.hpp index 4f098511d6..246f196609 100644 --- a/src/slic3r/GUI/AuthSession.hpp +++ b/src/slic3r/GUI/AuthSession.hpp @@ -14,33 +14,34 @@ namespace Slic3r { namespace GUI { using OpenPrusaAuthEvent = Event; -using PrusaAuthSuccessEvent = Event; -using PrusaAuthFailEvent = Event; +using UserAccountSuccessEvent = Event; +using UserAccountFailEvent = Event; wxDECLARE_EVENT(EVT_OPEN_PRUSAAUTH, OpenPrusaAuthEvent); -wxDECLARE_EVENT(EVT_LOGGEDOUT_PRUSAAUTH, PrusaAuthSuccessEvent); -wxDECLARE_EVENT(EVT_PA_ID_USER_SUCCESS, PrusaAuthSuccessEvent); -wxDECLARE_EVENT(EVT_PA_ID_USER_FAIL, PrusaAuthFailEvent); -wxDECLARE_EVENT(EVT_PRUSAAUTH_SUCCESS, PrusaAuthSuccessEvent); -wxDECLARE_EVENT(EVT_PRUSACONNECT_PRINTERS_SUCCESS, PrusaAuthSuccessEvent); -wxDECLARE_EVENT(EVT_PA_AVATAR_SUCCESS, PrusaAuthSuccessEvent); -wxDECLARE_EVENT(EVT_PRUSAAUTH_FAIL, PrusaAuthFailEvent); // Soft fail - clears only after some number of fails -wxDECLARE_EVENT(EVT_PA_AVATAR_FAIL, PrusaAuthFailEvent); // Soft fail - clears only after some number of fails -wxDECLARE_EVENT(EVT_PRUSAAUTH_RESET, PrusaAuthFailEvent); // Hard fail - clears all +wxDECLARE_EVENT(EVT_UA_LOGGEDOUT, UserAccountSuccessEvent); +wxDECLARE_EVENT(EVT_UA_ID_USER_SUCCESS, UserAccountSuccessEvent); +wxDECLARE_EVENT(EVT_UA_SUCCESS, UserAccountSuccessEvent); +wxDECLARE_EVENT(EVT_UA_PRUSACONNECT_PRINTERS_SUCCESS, UserAccountSuccessEvent); +wxDECLARE_EVENT(EVT_UA_AVATAR_SUCCESS, UserAccountSuccessEvent); +wxDECLARE_EVENT(EVT_UA_FAIL, UserAccountFailEvent); // Soft fail - clears only after some number of fails +wxDECLARE_EVENT(EVT_UA_RESET, UserAccountFailEvent); // Hard fail - clears all typedef std::function UserActionSuccessFn; typedef std::function UserActionFailFn; // UserActions implements different operations via trigger() method. Stored in m_actions. -enum class UserActionID { - AUTH_ACTION_DUMMY, - AUTH_ACTION_REFRESH_TOKEN, - AUTH_ACTION_CODE_FOR_TOKEN, - AUTH_ACTION_USER_ID, - AUTH_ACTION_TEST_ACCESS_TOKEN, - AUTH_ACTION_TEST_CONNECTION, - AUTH_ACTION_CONNECT_DUMMY, - AUTH_ACTION_CONNECT_PRINTERS, - AUTH_ACTION_AVATAR, +enum class UserAccountActionID { + USER_ACCOUNT_ACTION_DUMMY, + USER_ACCOUNT_ACTION_REFRESH_TOKEN, + USER_ACCOUNT_ACTION_CODE_FOR_TOKEN, + USER_ACCOUNT_ACTION_USER_ID, + USER_ACCOUNT_ACTION_TEST_ACCESS_TOKEN, + USER_ACCOUNT_ACTION_TEST_CONNECTION, + USER_ACCOUNT_ACTION_CONNECT_PRINTERS, + USER_ACCOUNT_ACTION_AVATAR, +#if 0 + USER_ACCOUNT_ACTION_CONNECT_DUMMY, +#endif // 0 + }; class UserAction { @@ -86,16 +87,16 @@ public: struct ActionQueueData { - UserActionID action_id; + UserAccountActionID action_id; UserActionSuccessFn success_callback; UserActionFailFn fail_callback; std::string input; }; -class AuthSession +class UserAccountSession { public: - AuthSession(wxEvtHandler* evt_handler, const std::string& access_token, const std::string& refresh_token, const std::string& shared_session_key, bool polling_enabled) + UserAccountSession(wxEvtHandler* evt_handler, const std::string& access_token, const std::string& refresh_token, const std::string& shared_session_key, bool polling_enabled) : p_evt_handler(evt_handler) , m_access_token(access_token) , m_refresh_token(refresh_token) @@ -105,28 +106,33 @@ public: { // do not forget to add delete to destructor - m_actions[UserActionID::AUTH_ACTION_DUMMY] = std::make_unique(); - m_actions[UserActionID::AUTH_ACTION_REFRESH_TOKEN] = std::make_unique("EXCHANGE_TOKENS", "https://test-account.prusa3d.com/o/token/"); - m_actions[UserActionID::AUTH_ACTION_CODE_FOR_TOKEN] = std::make_unique("EXCHANGE_TOKENS", "https://test-account.prusa3d.com/o/token/"); - m_actions[UserActionID::AUTH_ACTION_USER_ID] = std::make_unique("USER_ID", "https://test-account.prusa3d.com/api/v1/me/", EVT_PA_ID_USER_SUCCESS, EVT_PRUSAAUTH_RESET); - m_actions[UserActionID::AUTH_ACTION_TEST_ACCESS_TOKEN] = std::make_unique("TEST_ACCESS_TOKEN", "https://test-account.prusa3d.com/api/v1/me/", EVT_PA_ID_USER_SUCCESS, EVT_PRUSAAUTH_FAIL); - m_actions[UserActionID::AUTH_ACTION_TEST_CONNECTION] = std::make_unique("TEST_CONNECTION", "https://test-account.prusa3d.com/api/v1/me/", wxEVT_NULL, EVT_PRUSAAUTH_RESET); - m_actions[UserActionID::AUTH_ACTION_CONNECT_DUMMY] = std::make_unique("CONNECT_DUMMY", "https://dev.connect.prusa3d.com/slicer/dummy"/*"dev.connect.prusa:8000/slicer/dummy"*/, EVT_PRUSAAUTH_SUCCESS, EVT_PRUSAAUTH_FAIL); - m_actions[UserActionID::AUTH_ACTION_CONNECT_PRINTERS] = std::make_unique("CONNECT_PRINTERS", "https://dev.connect.prusa3d.com/slicer/printers"/*"dev.connect.prusa:8000/slicer/printers"*/, EVT_PRUSACONNECT_PRINTERS_SUCCESS, EVT_PRUSAAUTH_FAIL); - m_actions[UserActionID::AUTH_ACTION_AVATAR] = std::make_unique("AVATAR", "https://test-media.printables.com/media/", EVT_PA_AVATAR_SUCCESS, EVT_PA_AVATAR_FAIL); + m_actions[UserAccountActionID::USER_ACCOUNT_ACTION_DUMMY] = std::make_unique(); + m_actions[UserAccountActionID::USER_ACCOUNT_ACTION_REFRESH_TOKEN] = std::make_unique("EXCHANGE_TOKENS", "https://test-account.prusa3d.com/o/token/"); + m_actions[UserAccountActionID::USER_ACCOUNT_ACTION_CODE_FOR_TOKEN] = std::make_unique("EXCHANGE_TOKENS", "https://test-account.prusa3d.com/o/token/"); + m_actions[UserAccountActionID::USER_ACCOUNT_ACTION_USER_ID] = std::make_unique("USER_ID", "https://test-account.prusa3d.com/api/v1/me/", EVT_UA_ID_USER_SUCCESS, EVT_UA_RESET); + m_actions[UserAccountActionID::USER_ACCOUNT_ACTION_TEST_ACCESS_TOKEN] = std::make_unique("TEST_ACCESS_TOKEN", "https://test-account.prusa3d.com/api/v1/me/", EVT_UA_ID_USER_SUCCESS, EVT_UA_FAIL); + m_actions[UserAccountActionID::USER_ACCOUNT_ACTION_TEST_CONNECTION] = std::make_unique("TEST_CONNECTION", "https://test-account.prusa3d.com/api/v1/me/", wxEVT_NULL, EVT_UA_RESET); + m_actions[UserAccountActionID::USER_ACCOUNT_ACTION_CONNECT_PRINTERS] = std::make_unique("CONNECT_PRINTERS", "https://dev.connect.prusa3d.com/slicer/printers", EVT_UA_PRUSACONNECT_PRINTERS_SUCCESS, EVT_UA_FAIL); + m_actions[UserAccountActionID::USER_ACCOUNT_ACTION_AVATAR] = std::make_unique("AVATAR", "https://test-media.printables.com/media/", EVT_UA_AVATAR_SUCCESS, EVT_UA_FAIL); +#if 0 + m_actions[UserAccountActionID::USER_ACCOUNT_ACTION_CONNECT_DUMMY] = std::make_unique("CONNECT_DUMMY", "https://dev.connect.prusa3d.com/slicer/dummy", EVT_UA_SUCCESS, EVT_UA_FAIL); +#endif // 0 + } - ~AuthSession() + ~UserAccountSession() { - m_actions[UserActionID::AUTH_ACTION_DUMMY].reset(nullptr); - m_actions[UserActionID::AUTH_ACTION_REFRESH_TOKEN].reset(nullptr); - m_actions[UserActionID::AUTH_ACTION_CODE_FOR_TOKEN].reset(nullptr); - m_actions[UserActionID::AUTH_ACTION_USER_ID].reset(nullptr); - m_actions[UserActionID::AUTH_ACTION_TEST_ACCESS_TOKEN].reset(nullptr); - m_actions[UserActionID::AUTH_ACTION_TEST_CONNECTION].reset(nullptr); - m_actions[UserActionID::AUTH_ACTION_CONNECT_DUMMY].reset(nullptr); - m_actions[UserActionID::AUTH_ACTION_CONNECT_PRINTERS].reset(nullptr); - m_actions[UserActionID::AUTH_ACTION_AVATAR].reset(nullptr); - //assert(m_actions.empty()); + m_actions[UserAccountActionID::USER_ACCOUNT_ACTION_DUMMY].reset(nullptr); + m_actions[UserAccountActionID::USER_ACCOUNT_ACTION_REFRESH_TOKEN].reset(nullptr); + m_actions[UserAccountActionID::USER_ACCOUNT_ACTION_CODE_FOR_TOKEN].reset(nullptr); + m_actions[UserAccountActionID::USER_ACCOUNT_ACTION_USER_ID].reset(nullptr); + m_actions[UserAccountActionID::USER_ACCOUNT_ACTION_TEST_ACCESS_TOKEN].reset(nullptr); + m_actions[UserAccountActionID::USER_ACCOUNT_ACTION_TEST_CONNECTION].reset(nullptr); + m_actions[UserAccountActionID::USER_ACCOUNT_ACTION_CONNECT_PRINTERS].reset(nullptr); + m_actions[UserAccountActionID::USER_ACCOUNT_ACTION_AVATAR].reset(nullptr); +#if 0 + m_actions[UserAccountActionID::USER_ACCOUNT_ACTION_CONNECT_DUMMY].reset(nullptr); +#endif // 0 + } void clear() { m_access_token.clear(); @@ -137,7 +143,7 @@ public: // Functions that automatically enable action queu processing void init_with_code(const std::string& code, const std::string& code_verifier); - void enqueue_action(UserActionID id, UserActionSuccessFn success_callback, UserActionFailFn fail_callback, const std::string& input); + void enqueue_action(UserAccountActionID id, UserActionSuccessFn success_callback, UserActionFailFn fail_callback, const std::string& input); // Special enques, that sets callbacks. void enqueue_test_with_refresh(); @@ -169,7 +175,7 @@ private: std::queue m_action_queue; std::queue m_priority_action_queue; - std::map> m_actions; + std::map> m_actions; wxEvtHandler* p_evt_handler; }; diff --git a/src/slic3r/GUI/GUI_App.cpp b/src/slic3r/GUI/GUI_App.cpp index cb062ee3c3..2c833f0cd0 100644 --- a/src/slic3r/GUI/GUI_App.cpp +++ b/src/slic3r/GUI/GUI_App.cpp @@ -3685,8 +3685,8 @@ void GUI_App::handle_web_request(std::string cmd) (is_installed ? GUI::format(_L("Installed and Select Printer:\n%1%"), preset->name) : GUI::format(_L("Select Printer:\n%1%"), preset->name) ): GUI::format(_L("Printer not found:\n%1%"), model_name); - this->plater()->get_notification_manager()->close_notification_of_type(NotificationType::PrusaAuthUserID); - this->plater()->get_notification_manager()->push_notification(NotificationType::PrusaAuthUserID, NotificationManager::NotificationLevel::ImportantNotificationLevel, out); + this->plater()->get_notification_manager()->close_notification_of_type(NotificationType::UserAccountID); + this->plater()->get_notification_manager()->push_notification(NotificationType::UserAccountID, NotificationManager::NotificationLevel::ImportantNotificationLevel, out); } void GUI_App::show_monitor_tab(bool show, const std::string& address/* = {}*/) diff --git a/src/slic3r/GUI/MainFrame.cpp b/src/slic3r/GUI/MainFrame.cpp index 624d640c53..70d7007c22 100644 --- a/src/slic3r/GUI/MainFrame.cpp +++ b/src/slic3r/GUI/MainFrame.cpp @@ -904,10 +904,10 @@ void MainFrame::set_monitor_tab_url(const wxString& url) m_monitor_webview->load_default_url(); } -void Slic3r::GUI::MainFrame::refresh_auth_menu(bool avatar/* = false */) +void Slic3r::GUI::MainFrame::refresh_account_menu(bool avatar/* = false */) { // Update User name in TopBar - dynamic_cast(m_tabpanel)->GetTopBarItemsCtrl()->UpdateAuthMenu(avatar); + dynamic_cast(m_tabpanel)->GetTopBarItemsCtrl()->UpdateAccountMenu(avatar); } void MainFrame::add_created_tab(Tab* panel, const std::string& bmp_name /*= ""*/) diff --git a/src/slic3r/GUI/MainFrame.hpp b/src/slic3r/GUI/MainFrame.hpp index a6d5e6992b..1b4106563c 100644 --- a/src/slic3r/GUI/MainFrame.hpp +++ b/src/slic3r/GUI/MainFrame.hpp @@ -223,7 +223,7 @@ public: void set_monitor_tab_url(const wxString& url); bool get_monitor_tab_added() const { return m_monitor_webview_added; } - void refresh_auth_menu(bool avatar = false); + void refresh_account_menu(bool avatar = false); PrintHostQueueDialog* printhost_queue_dlg() { return m_printhost_queue_dlg; } diff --git a/src/slic3r/GUI/NotificationManager.hpp b/src/slic3r/GUI/NotificationManager.hpp index ff42f50c1c..f95a367545 100644 --- a/src/slic3r/GUI/NotificationManager.hpp +++ b/src/slic3r/GUI/NotificationManager.hpp @@ -131,7 +131,7 @@ enum class NotificationType // Config file was detected during startup, open wifi config dialog via hypertext WifiConfigFileDetected, // Info abouty successful login or logout - PrusaAuthUserID, + UserAccountID, // Debug notification for connect communication PrusaConnectPrinters, }; diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index 338f937291..7f1a513c21 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -883,59 +883,62 @@ Plater::priv::priv(Plater *q, MainFrame *main_frame) wxGetApp().open_login_browser_with_dialog(evt.data); }); - this->q->Bind(EVT_LOGGEDOUT_PRUSAAUTH, [this](PrusaAuthSuccessEvent& evt) { + this->q->Bind(EVT_UA_LOGGEDOUT, [this](UserAccountSuccessEvent& evt) { user_account->clear(); std::string text = _u8L("Logged out from Prusa Account."); - this->notification_manager->close_notification_of_type(NotificationType::PrusaAuthUserID); - this->notification_manager->push_notification(NotificationType::PrusaAuthUserID, NotificationManager::NotificationLevel::ImportantNotificationLevel, text); + this->notification_manager->close_notification_of_type(NotificationType::UserAccountID); + this->notification_manager->push_notification(NotificationType::UserAccountID, NotificationManager::NotificationLevel::ImportantNotificationLevel, text); this->main_frame->disable_connect_tab(); - this->main_frame->refresh_auth_menu(true); + this->main_frame->refresh_account_menu(true); }); - this->q->Bind(EVT_PA_ID_USER_SUCCESS, [this](PrusaAuthSuccessEvent& evt) { + this->q->Bind(EVT_UA_ID_USER_SUCCESS, [this](UserAccountSuccessEvent& evt) { std::string username; if (user_account->on_user_id_success(evt.data, username)) { // login notification std::string text = format(_u8L("Logged to Prusa Account as %1%."), username); - this->notification_manager->close_notification_of_type(NotificationType::PrusaAuthUserID); - this->notification_manager->push_notification(NotificationType::PrusaAuthUserID, NotificationManager::NotificationLevel::ImportantNotificationLevel, text); + this->notification_manager->close_notification_of_type(NotificationType::UserAccountID); + this->notification_manager->push_notification(NotificationType::UserAccountID, NotificationManager::NotificationLevel::ImportantNotificationLevel, text); // show connect tab this->main_frame->enable_connect_tab(); // Update User name in TopBar - this->main_frame->refresh_auth_menu(); + this->main_frame->refresh_account_menu(); } else { // data were corrupt and username was not retrieved - // procced as if EVT_PRUSAAUTH_RESET was recieved + // procced as if EVT_UA_RESET was recieved BOOST_LOG_TRIVIAL(error) << "Reseting Prusa Account communication. Recieved data were corrupt."; user_account->clear(); - this->notification_manager->close_notification_of_type(NotificationType::PrusaAuthUserID); - this->notification_manager->push_notification(NotificationType::PrusaAuthUserID, NotificationManager::NotificationLevel::WarningNotificationLevel, _u8L("Failed to connect to Prusa Account.")); + this->notification_manager->close_notification_of_type(NotificationType::UserAccountID); + this->notification_manager->push_notification(NotificationType::UserAccountID, NotificationManager::NotificationLevel::WarningNotificationLevel, _u8L("Failed to connect to Prusa Account.")); // Update User name in TopBar - this->main_frame->refresh_auth_menu(); + this->main_frame->refresh_account_menu(); // Update sidebar printer status sidebar->update_printer_presets_combobox(); } }); - this->q->Bind(EVT_PRUSAAUTH_RESET, [this](PrusaAuthFailEvent& evt) { + this->q->Bind(EVT_UA_RESET, [this](UserAccountFailEvent& evt) { BOOST_LOG_TRIVIAL(error) << "Reseting Prusa Account communication. Error message: " << evt.data; user_account->clear(); - this->notification_manager->close_notification_of_type(NotificationType::PrusaAuthUserID); - this->notification_manager->push_notification(NotificationType::PrusaAuthUserID, NotificationManager::NotificationLevel::WarningNotificationLevel, _u8L("Failed to connect to Prusa Account.")); + this->notification_manager->close_notification_of_type(NotificationType::UserAccountID); + this->notification_manager->push_notification(NotificationType::UserAccountID, NotificationManager::NotificationLevel::WarningNotificationLevel, _u8L("Failed to connect to Prusa Account.")); // Update User name in TopBar - this->main_frame->refresh_auth_menu(); + this->main_frame->refresh_account_menu(); // Update sidebar printer status sidebar->update_printer_presets_combobox(); }); - this->q->Bind(EVT_PRUSAAUTH_FAIL, [this](PrusaAuthFailEvent& evt) { + this->q->Bind(EVT_UA_FAIL, [this](UserAccountFailEvent& evt) { BOOST_LOG_TRIVIAL(error) << "Failed communication with Prusa Account: " << evt.data; user_account->on_communication_fail(); }); - this->q->Bind(EVT_PRUSAAUTH_SUCCESS, [this](PrusaAuthSuccessEvent& evt) { - this->notification_manager->close_notification_of_type(NotificationType::PrusaAuthUserID); - this->notification_manager->push_notification(NotificationType::PrusaAuthUserID, NotificationManager::NotificationLevel::ImportantNotificationLevel, evt.data); +#if 0 + // for debug purposes only + this->q->Bind(EVT_UA_SUCCESS, [this](UserAccountSuccessEvent& evt) { + this->notification_manager->close_notification_of_type(NotificationType::UserAccountID); + this->notification_manager->push_notification(NotificationType::UserAccountID, NotificationManager::NotificationLevel::ImportantNotificationLevel, evt.data); }); - this->q->Bind(EVT_PRUSACONNECT_PRINTERS_SUCCESS, [this](PrusaAuthSuccessEvent& evt) { +#endif // 0 + this->q->Bind(EVT_UA_PRUSACONNECT_PRINTERS_SUCCESS, [this](UserAccountSuccessEvent& evt) { std::string text; bool printers_changed = false; if (user_account->on_connect_printers_success(evt.data, wxGetApp().app_config, printers_changed)) { @@ -943,17 +946,17 @@ Plater::priv::priv(Plater *q, MainFrame *main_frame) sidebar->update_printer_presets_combobox(); } } else { - // message was corrupt, procceed like EVT_PRUSAAUTH_FAIL + // message was corrupt, procceed like EVT_UA_FAIL user_account->on_communication_fail(); } }); - this->q->Bind(EVT_PA_AVATAR_SUCCESS, [this](PrusaAuthSuccessEvent& evt) { + this->q->Bind(EVT_UA_AVATAR_SUCCESS, [this](UserAccountSuccessEvent& evt) { boost::filesystem::path png_path = boost::filesystem::path(Slic3r::data_dir()) / "cache" / "avatar.png"; FILE* file; file = fopen(png_path.string().c_str(), "wb"); fwrite(evt.data.c_str(), 1, evt.data.size(), file); fclose(file); - this->main_frame->refresh_auth_menu(true); + this->main_frame->refresh_account_menu(true); }); wxGetApp().other_instance_message_handler()->init(this->q); diff --git a/src/slic3r/GUI/TopBar.cpp b/src/slic3r/GUI/TopBar.cpp index ac95095464..adc19cd421 100644 --- a/src/slic3r/GUI/TopBar.cpp +++ b/src/slic3r/GUI/TopBar.cpp @@ -154,28 +154,30 @@ void TopBarItemsCtrl::ApplyWorkspacesMenu() } } -void TopBarItemsCtrl::CreateAuthMenu() +void TopBarItemsCtrl::CreateAccountMenu() { - m_user_menu_item = append_menu_item(&m_auth_menu, wxID_ANY, "", "", + m_user_menu_item = append_menu_item(&m_account_menu, wxID_ANY, "", "", [this](wxCommandEvent& e) { - m_auth_btn->set_selected(true); - wxGetApp().plater()->PopupMenu(&m_auth_menu, m_auth_btn->GetPosition()); + m_account_btn->set_selected(true); + wxGetApp().plater()->PopupMenu(&m_account_menu, m_account_btn->GetPosition()); }, get_bmp_bundle("user", 16)); - m_auth_menu.AppendSeparator(); - /* - m_connect_dummy_menu_item = append_menu_item(&m_auth_menu, wxID_ANY, _L("PrusaConnect Printers"), "", + m_account_menu.AppendSeparator(); + +#if 0 + m_connect_dummy_menu_item = append_menu_item(&m_account_menu, wxID_ANY, _L("PrusaConnect Printers"), "", [](wxCommandEvent&) { wxGetApp().plater()->get_user_account()->enqueue_connect_printers_action(); }, "", nullptr, []() { return wxGetApp().plater()->get_user_account()->is_logged(); }, this->GetParent()); - */ - wxMenuItem* remember_me_menu_item = append_menu_check_item(&m_auth_menu, wxID_ANY, _L("Remember me"), "" +#endif // 0 + + wxMenuItem* remember_me_menu_item = append_menu_check_item(&m_account_menu, wxID_ANY, _L("Remember me"), "" , [](wxCommandEvent&) { wxGetApp().plater()->get_user_account()->toggle_remember_session(); } - , &m_auth_menu + , &m_account_menu , []() { return wxGetApp().plater()->get_user_account() ? wxGetApp().plater()->get_user_account()->is_logged() : false; } , []() { return wxGetApp().plater()->get_user_account() ? wxGetApp().plater()->get_user_account()->get_remember_session() : false; } , this->GetParent()); - m_login_menu_item = append_menu_item(&m_auth_menu, wxID_ANY, "", "", + m_login_menu_item = append_menu_item(&m_account_menu, wxID_ANY, "", "", [](wxCommandEvent&) { auto user_account = wxGetApp().plater()->get_user_account(); if (user_account->is_logged()) @@ -185,7 +187,7 @@ void TopBarItemsCtrl::CreateAuthMenu() }, get_bmp_bundle("login", 16)); } -void TopBarItemsCtrl::UpdateAuthMenu(bool avatar/* = false*/) +void TopBarItemsCtrl::UpdateAccountMenu(bool avatar/* = false*/) { auto user_account = wxGetApp().plater()->get_user_account(); if (m_login_menu_item) { @@ -197,21 +199,21 @@ void TopBarItemsCtrl::UpdateAuthMenu(bool avatar/* = false*/) if (m_user_menu_item) m_user_menu_item->SetItemLabel(user_name); - m_auth_btn->SetLabel(user_name); + m_account_btn->SetLabel(user_name); if (avatar) { if (user_account->is_logged()) { boost::filesystem::path path = boost::filesystem::path(boost::filesystem::path(Slic3r::data_dir()) / "cache" / "avatar.png"); - ScalableBitmap new_logo(this, path, m_auth_btn->GetBitmapSize()); + ScalableBitmap new_logo(this, path, m_account_btn->GetBitmapSize()); if (new_logo.IsOk()) - m_auth_btn->SetBitmap_(new_logo); + m_account_btn->SetBitmap_(new_logo); else - m_auth_btn->SetBitmap_("user"); + m_account_btn->SetBitmap_("user"); } else { - m_auth_btn->SetBitmap_("user"); + m_account_btn->SetBitmap_("user"); } } - m_auth_btn->Refresh(); + m_account_btn->Refresh(); } void TopBarItemsCtrl::CreateSearch() @@ -286,20 +288,20 @@ TopBarItemsCtrl::TopBarItemsCtrl(wxWindow *parent) : }); m_workspaces_menu.Bind(wxEVT_MENU_CLOSE, [this](wxMenuEvent&) { m_workspace_btn->set_selected(false); }); - // create Auth menu - CreateAuthMenu(); + // create Account menu + CreateAccountMenu(); -// m_auth_btn = new ButtonWithPopup(this, "user", 35); - m_auth_btn = new ButtonWithPopup(this, _L("Anonymus"), "user"); - right_sizer->Add(m_auth_btn, 0, wxALIGN_CENTER_VERTICAL | wxALIGN_RIGHT | wxRIGHT | wxLEFT, m_btn_margin); +// m_account_btn = new ButtonWithPopup(this, "user", 35); + m_account_btn = new ButtonWithPopup(this, _L("Anonymus"), "user"); + right_sizer->Add(m_account_btn, 0, wxALIGN_CENTER_VERTICAL | wxALIGN_RIGHT | wxRIGHT | wxLEFT, m_btn_margin); - m_auth_btn->Bind(wxEVT_BUTTON, [this](wxCommandEvent& event) { - UpdateAuthMenu(); - m_auth_btn->set_selected(true); - wxPoint pos = m_auth_btn->GetPosition(); - wxGetApp().plater()->PopupMenu(&m_auth_menu, pos); + m_account_btn->Bind(wxEVT_BUTTON, [this](wxCommandEvent& event) { + UpdateAccountMenu(); + m_account_btn->set_selected(true); + wxPoint pos = m_account_btn->GetPosition(); + wxGetApp().plater()->PopupMenu(&m_account_menu, pos); }); - m_auth_menu.Bind(wxEVT_MENU_CLOSE, [this](wxMenuEvent&) { m_auth_btn->set_selected(false); }); + m_account_menu.Bind(wxEVT_MENU_CLOSE, [this](wxMenuEvent&) { m_account_btn->set_selected(false); }); m_sizer->Add(right_sizer, 0, wxALIGN_CENTER_VERTICAL); @@ -366,7 +368,7 @@ void TopBarItemsCtrl::OnColorsChanged() m_menu_btn->sys_color_changed(); m_workspace_btn->sys_color_changed(); - m_auth_btn->sys_color_changed(); + m_account_btn->sys_color_changed(); m_search->SysColorsChanged(); UpdateSelection(); diff --git a/src/slic3r/GUI/TopBar.hpp b/src/slic3r/GUI/TopBar.hpp index c1ccc5c5af..4b0d6ad160 100644 --- a/src/slic3r/GUI/TopBar.hpp +++ b/src/slic3r/GUI/TopBar.hpp @@ -50,12 +50,14 @@ class TopBarItemsCtrl : public wxControl wxMenu m_main_menu; wxMenu m_workspaces_menu; - wxMenu m_auth_menu; - // Prusa Account (Auth) menu items + wxMenu m_account_menu; + // Prusa Account menu items wxMenuItem* m_user_menu_item{ nullptr }; wxMenuItem* m_login_menu_item{ nullptr }; - //wxMenuItem* m_connect_dummy_menu_item{ nullptr }; - +#if 0 + wxMenuItem* m_connect_dummy_menu_item{ nullptr }; +#endif // 0 + ::TextInput* m_search{ nullptr }; public: @@ -77,8 +79,8 @@ public: void AppendMenuItem(wxMenu* menu, const wxString& title); void AppendMenuSeparaorItem(); void ApplyWorkspacesMenu(); - void CreateAuthMenu(); - void UpdateAuthMenu(bool avatar = false); + void CreateAccountMenu(); + void UpdateAccountMenu(bool avatar = false); void CreateSearch(); wxWindow* GetSearchCtrl() { return m_search->GetTextCtrl(); } @@ -88,7 +90,7 @@ private: wxFlexGridSizer* m_sizer; ButtonWithPopup* m_menu_btn {nullptr}; ButtonWithPopup* m_workspace_btn {nullptr}; - ButtonWithPopup* m_auth_btn {nullptr}; + ButtonWithPopup* m_account_btn {nullptr}; std::vector m_pageButtons; int m_selection {-1}; int m_btn_margin; diff --git a/src/slic3r/GUI/UserAccount.cpp b/src/slic3r/GUI/UserAccount.cpp index 8105b25f85..5501c55a00 100644 --- a/src/slic3r/GUI/UserAccount.cpp +++ b/src/slic3r/GUI/UserAccount.cpp @@ -13,7 +13,7 @@ namespace Slic3r { namespace GUI { UserAccount::UserAccount(wxEvtHandler* evt_handler, AppConfig* app_config) - : m_auth_communication(std::make_unique(evt_handler, app_config)) + : m_communication(std::make_unique(evt_handler, app_config)) {} UserAccount::~UserAccount() @@ -22,7 +22,7 @@ UserAccount::~UserAccount() void UserAccount::set_username(const std::string& username) { m_username = username; - m_auth_communication->set_username(username); + m_communication->set_username(username); } void UserAccount::clear() @@ -30,63 +30,63 @@ void UserAccount::clear() m_username = {}; m_user_data.clear(); m_printer_map.clear(); - m_auth_communication->do_clear(); + m_communication->do_clear(); } void UserAccount::set_remember_session(bool remember) { - m_auth_communication->set_remember_session(remember); + m_communication->set_remember_session(remember); } void UserAccount::toggle_remember_session() { - m_auth_communication->set_remember_session(!m_auth_communication->get_remember_session()); + m_communication->set_remember_session(!m_communication->get_remember_session()); } bool UserAccount::get_remember_session() { - return m_auth_communication->get_remember_session(); + return m_communication->get_remember_session(); } bool UserAccount::is_logged() { - return m_auth_communication->is_logged(); + return m_communication->is_logged(); } void UserAccount::do_login() { - m_auth_communication->do_login(); + m_communication->do_login(); } void UserAccount::do_logout() { - m_auth_communication->do_logout(); + m_communication->do_logout(); } std::string UserAccount::get_access_token() { - return m_auth_communication->get_access_token(); + return m_communication->get_access_token(); } #if 0 void UserAccount::enqueue_user_id_action() { - m_auth_communication->enqueue_user_id_action(); + m_communication->enqueue_user_id_action(); } void UserAccount::enqueue_connect_dummy_action() { - m_auth_communication->enqueue_connect_dummy_action(); + m_communication->enqueue_connect_dummy_action(); } #endif void UserAccount::enqueue_connect_printers_action() { - m_auth_communication->enqueue_connect_printers_action(); + m_communication->enqueue_connect_printers_action(); } void UserAccount::enqueue_avatar_action() { - m_auth_communication->enqueue_avatar_action(m_user_data["avatar"]); + m_communication->enqueue_avatar_action(m_user_data["avatar"]); } bool UserAccount::on_login_code_recieved(const std::string& url_message) { - m_auth_communication->on_login_code_recieved(url_message); + m_communication->on_login_code_recieved(url_message); return true; } @@ -134,7 +134,7 @@ void UserAccount::on_communication_fail() m_fail_counter++; if (m_fail_counter > 5) // there is no deeper reason why 5 { - m_auth_communication->enqueue_test_connection(); + m_communication->enqueue_test_connection(); m_fail_counter = 0; } } diff --git a/src/slic3r/GUI/UserAccount.hpp b/src/slic3r/GUI/UserAccount.hpp index 69fb47ea89..2a5365cd89 100644 --- a/src/slic3r/GUI/UserAccount.hpp +++ b/src/slic3r/GUI/UserAccount.hpp @@ -23,7 +23,7 @@ enum class ConnectPrinterState { typedef std::map> ConnectPrinterStateMap; // Class UserAccount should handle every request for entities outside PrusaSlicer like PrusaAuth or PrusaConnect. -// Outside communication is implemented in class PrusaAuthCommunication in Auth.hpp. +// Outside communication is implemented in class UserAccountCommunication that runs separate thread. Results come back in events to Plater. // All incoming data shoud be stored in UserAccount. class UserAccount { public: @@ -44,13 +44,13 @@ public: void enqueue_connect_printers_action(); void enqueue_avatar_action(); - // Functions called from UI where events emmited from AuthSession are binded + // Functions called from UI where events emmited from UserAccountSession are binded // Returns bool if data were correctly proccessed bool on_login_code_recieved(const std::string& url_message); bool on_user_id_success(const std::string data, std::string& out_username); - // Called on EVT_PRUSAAUTH_FAIL, triggers test after several calls + // Called on EVT_UA_FAIL, triggers test after several calls void on_communication_fail(); - // Clears all data and connections, called on logout or EVT_PRUSAAUTH_RESET + // Clears all data and connections, called on logout or EVT_UA_RESET void clear(); bool on_connect_printers_success(const std::string data, AppConfig* app_config, bool& out_printers_changed); @@ -68,7 +68,7 @@ private: void set_username(const std::string& username); - std::unique_ptr m_auth_communication; + std::unique_ptr m_communication; ConnectPrinterStateMap m_printer_map; std::map m_user_data;