From 2d12c61ea0886903014cff36a1693297e05b71a0 Mon Sep 17 00:00:00 2001 From: David Kocik Date: Wed, 8 Jan 2025 13:20:02 +0100 Subject: [PATCH] Mockup of UI notification when http communication performs retry. --- src/slic3r/GUI/NotificationManager.hpp | 2 ++ src/slic3r/GUI/Plater.cpp | 16 ++++++++++++++++ src/slic3r/GUI/UserAccountCommunication.cpp | 2 +- src/slic3r/GUI/UserAccountSession.cpp | 2 ++ src/slic3r/GUI/UserAccountSession.hpp | 3 +++ 5 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/slic3r/GUI/NotificationManager.hpp b/src/slic3r/GUI/NotificationManager.hpp index 5f352b814c..215aae7b5e 100644 --- a/src/slic3r/GUI/NotificationManager.hpp +++ b/src/slic3r/GUI/NotificationManager.hpp @@ -144,6 +144,8 @@ enum class NotificationType WipeTowerNozzleDiameterDiffer, // Notification about using supports with different nozzle diameters. SupportNozzleDiameterDiffer, + // Transient error on Prusa Account communication - user is informed and has option to cancel (logout) + AccountTransientRetry, }; class NotificationManager diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index a7f0b8ee3b..1a99e84dcf 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -1078,6 +1078,22 @@ void Plater::priv::init() } this->q->printables_to_connect_gcode(into_u8(evt.GetString())); }); + + this->q->Bind(EVT_UA_RETRY_NOTIFY, [this](UserAccountFailEvent& evt) { + this->notification_manager->close_notification_of_type(NotificationType::AccountTransientRetry); + this->notification_manager->push_notification(NotificationType::AccountTransientRetry + , NotificationManager::NotificationLevel::RegularNotificationLevel + , evt.data + , _u8L("Stop now.") + , [this](wxEvtHandler* ) { + this->user_account->do_logout(); + return true; + }); + + }); + this->q->Bind(EVT_UA_CLOSE_RETRY_NOTIFICATION, [this](SimpleEvent& evt) { + this->notification_manager->close_notification_of_type(NotificationType::AccountTransientRetry); + }); } wxGetApp().other_instance_message_handler()->init(this->q); diff --git a/src/slic3r/GUI/UserAccountCommunication.cpp b/src/slic3r/GUI/UserAccountCommunication.cpp index 9afe5635bd..382ad50c53 100644 --- a/src/slic3r/GUI/UserAccountCommunication.cpp +++ b/src/slic3r/GUI/UserAccountCommunication.cpp @@ -315,7 +315,7 @@ void UserAccountCommunication::set_username(const std::string& username) BOOST_LOG_TRIVIAL(error) << "Failed to write tokens to the secret store."; } } else { -//#ifdef __linux__ +#ifdef __linux__ // If we can't store the tokens in secret store, store them in file with chmod 600 boost::filesystem::path target(boost::filesystem::path(Slic3r::data_dir()) / "UserAccount.dat") ; std::string data = "||||"; diff --git a/src/slic3r/GUI/UserAccountSession.cpp b/src/slic3r/GUI/UserAccountSession.cpp index 5e0fb6fa15..418889e4ce 100644 --- a/src/slic3r/GUI/UserAccountSession.cpp +++ b/src/slic3r/GUI/UserAccountSession.cpp @@ -32,6 +32,8 @@ wxDEFINE_EVENT(EVT_UA_RACE_LOST, UserAccountFailEvent); wxDEFINE_EVENT(EVT_UA_PRUSACONNECT_PRINTER_DATA_FAIL, UserAccountFailEvent); wxDEFINE_EVENT(EVT_UA_REFRESH_TIME, UserAccountTimeEvent); wxDEFINE_EVENT(EVT_UA_ENQUEUED_REFRESH, SimpleEvent); +wxDEFINE_EVENT(EVT_UA_RETRY_NOTIFY, UserAccountFailEvent); +wxDEFINE_EVENT(EVT_UA_CLOSE_RETRY_NOTIFICATION, SimpleEvent); void UserActionPost::perform(/*UNUSED*/ wxEvtHandler* evt_handler, /*UNUSED*/ const std::string& access_token, UserActionSuccessFn success_callback, UserActionFailFn fail_callback, const std::string& input) const { diff --git a/src/slic3r/GUI/UserAccountSession.hpp b/src/slic3r/GUI/UserAccountSession.hpp index 317047ea9f..aa516ed9c5 100644 --- a/src/slic3r/GUI/UserAccountSession.hpp +++ b/src/slic3r/GUI/UserAccountSession.hpp @@ -32,6 +32,9 @@ wxDECLARE_EVENT(EVT_UA_RACE_LOST, UserAccountFailEvent); // Hard fail - clears a wxDECLARE_EVENT(EVT_UA_PRUSACONNECT_PRINTER_DATA_FAIL, UserAccountFailEvent); // Failed to get data for printer to select, soft fail, action does not repeat wxDECLARE_EVENT(EVT_UA_REFRESH_TIME, UserAccountTimeEvent); wxDECLARE_EVENT(EVT_UA_ENQUEUED_REFRESH, SimpleEvent); +wxDECLARE_EVENT(EVT_UA_RETRY_NOTIFY, UserAccountFailEvent); // Not fail yet, just retry attempt. string is message to ui. +wxDECLARE_EVENT(EVT_UA_CLOSE_RETRY_NOTIFICATION, SimpleEvent); + typedef std::function UserActionSuccessFn; typedef std::function UserActionFailFn;