mirror of
https://git.mirrors.martin98.com/https://github.com/prusa3d/PrusaSlicer.git
synced 2025-08-16 18:15:59 +08:00
Use only uuid from Connect request and get rest of the data from endpoint
This commit is contained in:
parent
98ec4e808d
commit
65a581a026
@ -3727,11 +3727,29 @@ bool GUI_App::select_filament_preset(const Preset* preset, size_t extruder_index
|
||||
}
|
||||
void GUI_App::search_and_select_filaments(const std::string& material, size_t extruder_index, std::string& out_message)
|
||||
{
|
||||
const DynamicPrintConfig& config = preset_bundle->extruders_filaments[extruder_index].get_selected_preset()->config;
|
||||
const Preset* preset = preset_bundle->extruders_filaments[extruder_index].get_selected_preset();
|
||||
// selected is ok
|
||||
if (config.has("filament_type") && config.option("filament_type")->serialize() == material) {
|
||||
if (!preset->is_default && preset->config.has("filament_type") && preset->config.option("filament_type")->serialize() == material) {
|
||||
return;
|
||||
}
|
||||
// find installed compatible filament that is Prusa with suitable type and select it
|
||||
for (const auto& filament : preset_bundle->extruders_filaments[extruder_index]) {
|
||||
if (filament.is_compatible
|
||||
&& !filament.preset->is_default
|
||||
&& filament.preset->is_visible
|
||||
&& (!filament.preset->vendor || !filament.preset->vendor->templates_profile)
|
||||
&& filament.preset->config.has("filament_type")
|
||||
&& filament.preset->config.option("filament_type")->serialize() == material
|
||||
&& filament.preset->name.compare(0, 9, "Prusament") == 0
|
||||
&& select_filament_preset(filament.preset, extruder_index)
|
||||
)
|
||||
{
|
||||
out_message += /*(extruder_count == 1)
|
||||
? GUI::format(_L("Selected Filament:\n%1%"), filament_preset.preset->name)
|
||||
: */GUI::format(_L("Extruder %1%: Selected Filament %2%\n"), extruder_index + 1, filament.preset->name);
|
||||
return;
|
||||
}
|
||||
}
|
||||
// find first installed compatible filament with suitable type and select it
|
||||
for (const auto& filament : preset_bundle->extruders_filaments[extruder_index]) {
|
||||
if (filament.is_compatible
|
||||
@ -3800,7 +3818,15 @@ void GUI_App::select_filament_from_connect(const std::string& msg)
|
||||
}
|
||||
}
|
||||
|
||||
void GUI_App::handle_connect_request_printer_pick(const std::string& msg)
|
||||
void GUI_App::handle_connect_request_printer_select(const std::string& msg)
|
||||
{
|
||||
// Here comes code from ConnectWebViewPanel
|
||||
// It only contains uuid of a printer to be selected
|
||||
// Lets queue it and wait on result. The result is send via event to plater, where it is send to handle_connect_request_printer_select_inner
|
||||
std::string uuid = plater()->get_user_account()->get_keyword_from_json(msg, "uuid");
|
||||
plater()->get_user_account()->enqueue_printer_data_action(uuid);
|
||||
}
|
||||
void GUI_App::handle_connect_request_printer_select_inner(const std::string & msg)
|
||||
{
|
||||
BOOST_LOG_TRIVIAL(debug) << "Handling web request: " << msg;
|
||||
// return to plater
|
||||
|
@ -413,7 +413,8 @@ public:
|
||||
int request_user_unbind(std::string dev_id) { return 0; }
|
||||
bool select_printer_from_connect(const std::string& cmd);
|
||||
void select_filament_from_connect(const std::string& cmd);
|
||||
void handle_connect_request_printer_pick(const std::string& cmd);
|
||||
void handle_connect_request_printer_select(const std::string& cmd);
|
||||
void handle_connect_request_printer_select_inner(const std::string& cmd);
|
||||
void show_printer_webview_tab();
|
||||
// return true if preset vas invisible and we have to installed it to make it selectable
|
||||
bool select_printer_preset(const Preset* printer_preset);
|
||||
|
@ -975,6 +975,16 @@ Plater::priv::priv(Plater *q, MainFrame *main_frame)
|
||||
wxGetApp().update_login_dialog();
|
||||
#endif // 0
|
||||
});
|
||||
this->q->Bind(EVT_UA_PRUSACONNECT_PRINTER_DATA_SUCCESS, [this](UserAccountSuccessEvent& evt) {
|
||||
wxGetApp().handle_connect_request_printer_select_inner(evt.data);
|
||||
});
|
||||
this->q->Bind(EVT_UA_PRUSACONNECT_PRINTER_DATA_FAIL, [this](UserAccountFailEvent& evt) {
|
||||
BOOST_LOG_TRIVIAL(error) << "Failed communication with Prusa Account: " << evt.data;
|
||||
user_account->on_communication_fail();
|
||||
std::string msg = _u8L("Failed to select printer from PrusaConnect.");
|
||||
this->notification_manager->close_notification_of_type(NotificationType::SelectFilamentFromConnect);
|
||||
this->notification_manager->push_notification(NotificationType::SelectFilamentFromConnect, NotificationManager::NotificationLevel::WarningNotificationLevel, msg);
|
||||
});
|
||||
}
|
||||
|
||||
wxGetApp().other_instance_message_handler()->init(this->q);
|
||||
|
@ -97,6 +97,10 @@ void UserAccount::enqueue_avatar_action()
|
||||
{
|
||||
m_communication->enqueue_avatar_action(m_account_user_data["avatar"]);
|
||||
}
|
||||
void UserAccount::enqueue_printer_data_action(const std::string& uuid)
|
||||
{
|
||||
m_communication->enqueue_printer_data_action(uuid);
|
||||
}
|
||||
|
||||
bool UserAccount::on_login_code_recieved(const std::string& url_message)
|
||||
{
|
||||
|
@ -45,7 +45,7 @@ public:
|
||||
void enqueue_connect_status_action();
|
||||
void enqueue_connect_printer_models_action();
|
||||
void enqueue_avatar_action();
|
||||
|
||||
void enqueue_printer_data_action(const std::string& uuid);
|
||||
// Clears all data and connections, called on logout or EVT_UA_RESET
|
||||
void clear();
|
||||
|
||||
@ -74,6 +74,7 @@ public:
|
||||
|
||||
void set_current_printer_uuid_from_connect(const std::string& uuid) { m_current_printer_uuid_from_connect = uuid; }
|
||||
std::string get_current_printer_uuid_from_connect() const { return m_current_printer_uuid_from_connect; }
|
||||
|
||||
private:
|
||||
void set_username(const std::string& username);
|
||||
|
||||
|
@ -333,6 +333,21 @@ void UserAccountCommunication::enqueue_avatar_action(const std::string& url)
|
||||
}
|
||||
wakeup_session_thread();
|
||||
}
|
||||
|
||||
void UserAccountCommunication::enqueue_printer_data_action(const std::string& uuid)
|
||||
{
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_session_mutex);
|
||||
if (!m_session->is_initialized()) {
|
||||
BOOST_LOG_TRIVIAL(error) << "Connect Printers endpoint connection failed - Not Logged in.";
|
||||
return;
|
||||
}
|
||||
m_session->enqueue_action(UserAccountActionID::USER_ACCOUNT_ACTION_CONNECT_DATA_FROM_UUID, nullptr, nullptr, uuid);
|
||||
}
|
||||
wakeup_session_thread();
|
||||
}
|
||||
|
||||
|
||||
void UserAccountCommunication::init_session_thread()
|
||||
{
|
||||
m_thread = std::thread([this]() {
|
||||
|
@ -43,6 +43,7 @@ public:
|
||||
void enqueue_connect_printer_models_action();
|
||||
void enqueue_avatar_action(const std::string& url);
|
||||
void enqueue_test_connection();
|
||||
void enqueue_printer_data_action(const std::string& uuid);
|
||||
|
||||
// Callbacks - called from UI after receiving Event from Session thread. Some might use Session thread.
|
||||
//
|
||||
|
@ -25,8 +25,10 @@ wxDEFINE_EVENT(EVT_UA_SUCCESS, UserAccountSuccessEvent);
|
||||
wxDEFINE_EVENT(EVT_UA_PRUSACONNECT_STATUS_SUCCESS, UserAccountSuccessEvent);
|
||||
wxDEFINE_EVENT(EVT_UA_PRUSACONNECT_PRINTER_MODELS_SUCCESS, UserAccountSuccessEvent);
|
||||
wxDEFINE_EVENT(EVT_UA_AVATAR_SUCCESS, UserAccountSuccessEvent);
|
||||
wxDEFINE_EVENT(EVT_UA_PRUSACONNECT_PRINTER_DATA_SUCCESS, UserAccountSuccessEvent);
|
||||
wxDEFINE_EVENT(EVT_UA_FAIL, UserAccountFailEvent);
|
||||
wxDEFINE_EVENT(EVT_UA_RESET, UserAccountFailEvent);
|
||||
wxDEFINE_EVENT(EVT_UA_PRUSACONNECT_PRINTER_DATA_FAIL, UserAccountFailEvent);
|
||||
|
||||
void UserActionPost::perform(/*UNUSED*/ wxEvtHandler* evt_handler, /*UNUSED*/ const std::string& access_token, UserActionSuccessFn success_callback, UserActionFailFn fail_callback, const std::string& input) const
|
||||
{
|
||||
|
@ -23,8 +23,10 @@ wxDECLARE_EVENT(EVT_UA_SUCCESS, UserAccountSuccessEvent);
|
||||
wxDECLARE_EVENT(EVT_UA_PRUSACONNECT_STATUS_SUCCESS, UserAccountSuccessEvent);
|
||||
wxDECLARE_EVENT(EVT_UA_PRUSACONNECT_PRINTER_MODELS_SUCCESS, UserAccountSuccessEvent);
|
||||
wxDECLARE_EVENT(EVT_UA_AVATAR_SUCCESS, UserAccountSuccessEvent);
|
||||
wxDECLARE_EVENT(EVT_UA_PRUSACONNECT_PRINTER_DATA_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
|
||||
wxDECLARE_EVENT(EVT_UA_PRUSACONNECT_PRINTER_DATA_FAIL, UserAccountFailEvent); // Failed to get data for printer to select, soft fail, action does not repeat
|
||||
|
||||
|
||||
typedef std::function<void(const std::string& body)> UserActionSuccessFn;
|
||||
@ -41,6 +43,7 @@ enum class UserAccountActionID {
|
||||
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,
|
||||
USER_ACCOUNT_ACTION_CONNECT_DATA_FROM_UUID,
|
||||
};
|
||||
class UserAction
|
||||
{
|
||||
@ -115,6 +118,7 @@ public:
|
||||
m_actions[UserAccountActionID::USER_ACCOUNT_ACTION_CONNECT_STATUS] = std::make_unique<UserActionGetWithEvent>("CONNECT_STATUS", "https://connect.prusa3d.com/slicer/status", EVT_UA_PRUSACONNECT_STATUS_SUCCESS, EVT_UA_FAIL);
|
||||
m_actions[UserAccountActionID::USER_ACCOUNT_ACTION_CONNECT_PRINTER_MODELS] = std::make_unique<UserActionGetWithEvent>("CONNECT_PRINTER_MODELS", "https://connect.prusa3d.com/slicer/printer_list", EVT_UA_PRUSACONNECT_PRINTER_MODELS_SUCCESS, EVT_UA_FAIL);
|
||||
m_actions[UserAccountActionID::USER_ACCOUNT_ACTION_AVATAR] = std::make_unique<UserActionGetWithEvent>("AVATAR", "https://media.printables.com/media/", EVT_UA_AVATAR_SUCCESS, EVT_UA_FAIL);
|
||||
m_actions[UserAccountActionID::USER_ACCOUNT_ACTION_CONNECT_DATA_FROM_UUID] = std::make_unique<UserActionGetWithEvent>("USER_ACCOUNT_ACTION_CONNECT_DATA_FROM_UUID", "https://connect.prusa3d.com/app/printers/", EVT_UA_PRUSACONNECT_PRINTER_DATA_SUCCESS, EVT_UA_FAIL);
|
||||
}
|
||||
~UserAccountSession()
|
||||
{
|
||||
@ -126,6 +130,7 @@ public:
|
||||
m_actions[UserAccountActionID::USER_ACCOUNT_ACTION_TEST_CONNECTION].reset(nullptr);
|
||||
m_actions[UserAccountActionID::USER_ACCOUNT_ACTION_CONNECT_STATUS].reset(nullptr);
|
||||
m_actions[UserAccountActionID::USER_ACCOUNT_ACTION_AVATAR].reset(nullptr);
|
||||
m_actions[UserAccountActionID::USER_ACCOUNT_ACTION_CONNECT_DATA_FROM_UUID].reset(nullptr);
|
||||
}
|
||||
void clear() {
|
||||
m_access_token.clear();
|
||||
|
@ -570,7 +570,7 @@ void ConnectWebViewPanel::sys_color_changed()
|
||||
void ConnectWebViewPanel::on_request_update_selected_printer_action()
|
||||
{
|
||||
assert(!m_message_data.empty());
|
||||
wxGetApp().handle_connect_request_printer_pick(m_message_data);
|
||||
wxGetApp().handle_connect_request_printer_select(m_message_data);
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user