Several fixes and improvements in SendSystemInfoDialog:

- do not show memory in MB, show it in GiB rounded to one decimal place
- when sending fails, the HTTP error code is not presented to the user (it is logged though)
- when the user cancels the sending, no extra "sending cancelled" message is shown
- in case there is no internet connection, the dialog is not shown at all
- a 6 second timeout for a case that connection is lost during sending
- the dialog is only shown when the wizard does not show on startup
This commit is contained in:
Lukas Matena 2021-10-08 12:23:02 +02:00
parent 8d115def76
commit 13ff92335b
4 changed files with 58 additions and 14 deletions

View file

@ -676,16 +676,18 @@ void GUI_App::post_init()
if (this->preset_updater) {
this->check_updates(false);
CallAfter([this] {
this->config_wizard_startup();
bool cw_showed = this->config_wizard_startup();
this->preset_updater->slic3r_update_notify();
this->preset_updater->sync(preset_bundle);
if (! cw_showed) {
// The CallAfter is needed as well, without it, GL extensions did not show.
// Also, we only want to show this when the wizard does not, so the new user
// sees something else than "we want something" on the first start.
show_send_system_info_dialog_if_needed();
}
});
}
// 'Send system info' dialog. Again, a CallAfter is needed on mac.
// Without it, GL extensions did not show.
CallAfter([] { show_send_system_info_dialog_if_needed(); });
#ifdef _WIN32
// Sets window property to mainframe so other instances can indentify it.
OtherInstanceMessageHandler::init_windows_properties(mainframe, m_instance_hash_int);

View file

@ -17,6 +17,7 @@
#include <boost/algorithm/hex.hpp>
#include <boost/algorithm/string/split.hpp>
#include <boost/algorithm/string/trim_all.hpp>
#include <boost/log/trivial.hpp>
#include <boost/property_tree/json_parser.hpp>
#include <boost/uuid/detail/md5.hpp>
@ -44,6 +45,8 @@
namespace Slic3r {
namespace GUI {
static const std::string SEND_SYSTEM_INFO_DOMAIN = "prusa3d.com";
static const std::string SEND_SYSTEM_INFO_URL = "https://files." + SEND_SYSTEM_INFO_DOMAIN + "/wp-json/v1/ps";
// Declaration of a free function defined in OpenGLManager.cpp:
@ -140,9 +143,24 @@ static bool should_dialog_be_shown()
// if (semver_current.prerelease() && std::string(semver_current.prerelease()) == "alpha")
// return false; // Don't show in alphas.
// Show the dialog if current > last, but they differ in more than just patch.
return ((semver_current.maj() > semver_last_sent.maj())
// New version means current > last, but they must differ in more than just patch.
bool new_version = ((semver_current.maj() > semver_last_sent.maj())
|| (semver_current.maj() == semver_last_sent.maj() && semver_current.min() > semver_last_sent.min() ));
if (! new_version)
return false;
std::cout << "Sending system info was not confirmed/declined in this version yet.\n"
"Pinging prusa3d.com to see if it can be offered now." << std::endl;
bool is_internet =
#ifdef _WIN32
std::system((std::string("ping /n 1 /w 1 ") + SEND_SYSTEM_INFO_DOMAIN).data()) == 0; // 1 packet, 1 sec timeout
#else
std::system((std::string("ping -c 1 -q -w 1 ") + SEND_SYSTEM_INFO_DOMAIN).data()) == 0; // 1 packet, quiet output, 1 sec timeout
#endif
std::cout << "Pinging prusa3d.com was " << (is_internet ? "" : "NOT ") << "successful." << std::endl;
return is_internet;
}
@ -364,9 +382,13 @@ static std::string generate_system_info_json()
data_node.put("SystemLanguage", sys_language);
data_node.put("TranslationLanguage: ", wxGetApp().app_config->get("translation_language"));
pt::ptree hw_node;
hw_node.put("ArchName", wxPlatformInfo::Get().GetArchName());
hw_node.put("RAM_MB", size_t(Slic3r::total_physical_memory()/1000000));
{
hw_node.put("ArchName", wxPlatformInfo::Get().GetArchName());
// Round MiB to hundreds,then present in GiB
hw_node.put("RAM_GiB", std::round(Slic3r::total_physical_memory()/104857600.)/10.);
}
// Now get some CPU info:
pt::ptree cpu_node;
@ -604,15 +626,16 @@ bool SendSystemInfoDialog::send_info()
} result; // No synchronization needed, UI thread reads only after worker is joined.
auto send = [&job_done, &result](const std::string& data) {
const std::string url = "https://files.prusa3d.com/wp-json/v1/ps";
Http http = Http::post(url);
Http http = Http::post(SEND_SYSTEM_INFO_URL);
http.header("Content-Type", "application/json")
.timeout_max(6) // seconds
.set_post_body(data)
.on_complete([&result](std::string body, unsigned status) {
result = { Result::Success, _L("System info sent successfully. Thank you.") };
})
.on_error([&result](std::string body, std::string error, unsigned status) {
result = { Result::Error, GUI::format_wxstr(_L("Sending system info failed! Status: %1%"), status) };
result = { Result::Error, _L("Sending system info failed!") };
BOOST_LOG_TRIVIAL(error) << "Sending system info failed! STATUS: " << status;
})
.on_progress([&job_done, &result](Http::Progress, bool &cancel) {
if (job_done) // UI thread wants us to cancel.
@ -634,8 +657,10 @@ bool SendSystemInfoDialog::send_info()
job_done = true; // In case the user closed the dialog, let the other thread know
sending_thread.join(); // and wait until it terminates.
InfoDialog info_dlg(wxGetApp().mainframe, wxEmptyString, result.str);
info_dlg.ShowModal();
if (result.value != Result::Cancelled) { // user knows he cancelled, no need to tell him.
InfoDialog info_dlg(wxGetApp().mainframe, wxEmptyString, result.str);
info_dlg.ShowModal();
}
return result.value == Result::Success;
}

View file

@ -104,6 +104,7 @@ struct Http::priv
{
enum {
DEFAULT_TIMEOUT_CONNECT = 10,
DEFAULT_TIMEOUT_MAX = 0,
DEFAULT_SIZE_LIMIT = 5 * 1024 * 1024,
};
@ -137,6 +138,7 @@ struct Http::priv
static size_t form_file_read_cb(char *buffer, size_t size, size_t nitems, void *userp);
void set_timeout_connect(long timeout);
void set_timeout_max(long timeout);
void form_add_file(const char *name, const fs::path &path, const char* filename);
void set_post_body(const fs::path &path);
void set_post_body(const std::string &body);
@ -163,6 +165,7 @@ Http::priv::priv(const std::string &url)
}
set_timeout_connect(DEFAULT_TIMEOUT_CONNECT);
set_timeout_max(DEFAULT_TIMEOUT_MAX);
::curl_easy_setopt(curl, CURLOPT_URL, url.c_str()); // curl makes a copy internally
::curl_easy_setopt(curl, CURLOPT_USERAGENT, SLIC3R_APP_NAME "/" SLIC3R_VERSION);
::curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, &error_buffer.front());
@ -253,6 +256,11 @@ void Http::priv::set_timeout_connect(long timeout)
::curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, timeout);
}
void Http::priv::set_timeout_max(long timeout)
{
::curl_easy_setopt(curl, CURLOPT_TIMEOUT, timeout);
}
void Http::priv::form_add_file(const char *name, const fs::path &path, const char* filename)
{
// We can't use CURLFORM_FILECONTENT, because curl doesn't support Unicode filenames on Windows
@ -409,6 +417,13 @@ Http& Http::timeout_connect(long timeout)
return *this;
}
Http& Http::timeout_max(long timeout)
{
if (timeout < 1) { timeout = priv::DEFAULT_TIMEOUT_MAX; }
if (p) { p->set_timeout_max(timeout); }
return *this;
}
Http& Http::size_limit(size_t sizeLimit)
{
if (p) { p->limit = sizeLimit; }

View file

@ -58,6 +58,8 @@ public:
// Sets a maximum connection timeout in seconds
Http& timeout_connect(long timeout);
// Sets a maximum total request timeout in seconds
Http& timeout_max(long timeout);
// Sets a maximum size of the data that can be received.
// A value of zero sets the default limit, which is is 5MB.
Http& size_limit(size_t sizeLimit);