From 70879d2d8cb6f4f137bd417788cee856e8822cc4 Mon Sep 17 00:00:00 2001 From: David Kocik Date: Thu, 19 Jan 2023 13:01:41 +0100 Subject: [PATCH] Fixes of AppUdpater fix of bug (1) - order of dialogs fix of bug (2) - show new version dialog when triggered by user fix of bug (3) - refresh value in preferences combobox when opening preferences fix of bug (4) - Use fwrite instead of stream to speedup saving. Do not show checkbox when triggered by user. --- src/slic3r/GUI/GUI_App.cpp | 14 ++++++++------ src/slic3r/GUI/Preferences.cpp | 7 +++++++ src/slic3r/GUI/UpdateDialogs.cpp | 10 +++++++--- src/slic3r/GUI/UpdateDialogs.hpp | 4 ++-- src/slic3r/Utils/AppUpdater.cpp | 17 +++++++++-------- 5 files changed, 33 insertions(+), 19 deletions(-) diff --git a/src/slic3r/GUI/GUI_App.cpp b/src/slic3r/GUI/GUI_App.cpp index d5b267927..12f3a82f0 100644 --- a/src/slic3r/GUI/GUI_App.cpp +++ b/src/slic3r/GUI/GUI_App.cpp @@ -811,13 +811,14 @@ void GUI_App::post_init() // preset_updater->sync downloads profile updates on background so it must begin after config wizard finished. bool cw_showed = this->config_wizard_startup(); this->preset_updater->sync(preset_bundle); - this->app_version_check(false); 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(); - } + show_send_system_info_dialog_if_needed(); + } + // app version check is asynchronous and triggers blocking dialog window, better call it last + this->app_version_check(false); }); } @@ -1245,7 +1246,7 @@ bool GUI_App::on_init_inner() preset_updater = new PresetUpdater(); Bind(EVT_SLIC3R_VERSION_ONLINE, &GUI_App::on_version_read, this); Bind(EVT_SLIC3R_EXPERIMENTAL_VERSION_ONLINE, [this](const wxCommandEvent& evt) { - if (this->plater_ != nullptr && app_config->get("notify_release") == "all") { + if (this->plater_ != nullptr && (m_app_updater->get_triggered_by_user() || app_config->get("notify_release") == "all")) { std::string evt_string = into_u8(evt.GetString()); if (*Semver::parse(SLIC3R_VERSION) < *Semver::parse(evt_string)) { auto notif_type = (evt_string.find("beta") != std::string::npos ? NotificationType::NewBetaAvailable : NotificationType::NewAlphaAvailable); @@ -3305,7 +3306,8 @@ void GUI_App::on_version_read(wxCommandEvent& evt) app_config->set("version_online", into_u8(evt.GetString())); app_config->save(); std::string opt = app_config->get("notify_release"); - if (this->plater_ == nullptr || (opt != "all" && opt != "release")) { + if (this->plater_ == nullptr || (!m_app_updater->get_triggered_by_user() && opt != "all" && opt != "release")) { + BOOST_LOG_TRIVIAL(info) << "Version online: " << evt.GetString() << ". User does not wish to be notified."; return; } if (*Semver::parse(SLIC3R_VERSION) >= *Semver::parse(into_u8(evt.GetString()))) { @@ -3355,7 +3357,7 @@ void GUI_App::app_updater(bool from_user) assert(!app_data.target_path.empty()); // dialog with new version info - AppUpdateAvailableDialog dialog(*Semver::parse(SLIC3R_VERSION), *app_data.version); + AppUpdateAvailableDialog dialog(*Semver::parse(SLIC3R_VERSION), *app_data.version, from_user); auto dialog_result = dialog.ShowModal(); // checkbox "do not show again" if (dialog.disable_version_check()) { diff --git a/src/slic3r/GUI/Preferences.cpp b/src/slic3r/GUI/Preferences.cpp index cc57bcffd..fc9ea1867 100644 --- a/src/slic3r/GUI/Preferences.cpp +++ b/src/slic3r/GUI/Preferences.cpp @@ -89,6 +89,13 @@ void PreferencesDialog::show(const std::string& highlight_opt_key /*= std::strin m_custom_toolbar_size = atoi(get_app_config()->get("custom_toolbar_size").c_str()); m_use_custom_toolbar_size = get_app_config()->get("use_custom_toolbar_size") == "1"; + // set Field for notify_release to its value + if (m_optgroup_gui && m_optgroup_gui->get_field("notify_release") != nullptr) { + boost::any val = s_keys_map_NotifyReleaseMode.at(wxGetApp().app_config->get("notify_release")); + m_optgroup_gui->get_field("notify_release")->set_value(val, false); + } + + if (wxGetApp().is_editor()) { auto app_config = get_app_config(); diff --git a/src/slic3r/GUI/UpdateDialogs.cpp b/src/slic3r/GUI/UpdateDialogs.cpp index e8edd5798..258a9c784 100644 --- a/src/slic3r/GUI/UpdateDialogs.cpp +++ b/src/slic3r/GUI/UpdateDialogs.cpp @@ -93,7 +93,7 @@ bool MsgUpdateSlic3r::disable_version_check() const wxSize AppUpdateAvailableDialog::AUAD_size; // AppUpdater -AppUpdateAvailableDialog::AppUpdateAvailableDialog(const Semver& ver_current, const Semver& ver_online) +AppUpdateAvailableDialog::AppUpdateAvailableDialog(const Semver& ver_current, const Semver& ver_online, bool from_user) : MsgDialog(nullptr, _(L("App Update available")), wxString::Format(_(L("New version of %s is available.\nDo you wish to download it?")), SLIC3R_APP_NAME)) { auto* versions = new wxFlexGridSizer(1, 0, VERT_SPACING); @@ -104,8 +104,10 @@ AppUpdateAvailableDialog::AppUpdateAvailableDialog(const Semver& ver_current, co content_sizer->Add(versions); content_sizer->AddSpacer(VERT_SPACING); - cbox = new wxCheckBox(this, wxID_ANY, _(L("Don't notify about new releases any more"))); - content_sizer->Add(cbox); + if(!from_user) { + cbox = new wxCheckBox(this, wxID_ANY, _(L("Don't notify about new releases any more"))); + content_sizer->Add(cbox); + } content_sizer->AddSpacer(VERT_SPACING); AUAD_size = content_sizer->GetSize(); @@ -125,6 +127,8 @@ AppUpdateAvailableDialog::~AppUpdateAvailableDialog() {} bool AppUpdateAvailableDialog::disable_version_check() const { + if (!cbox) + return false; return cbox->GetValue(); } diff --git a/src/slic3r/GUI/UpdateDialogs.hpp b/src/slic3r/GUI/UpdateDialogs.hpp index 2eb4ff8d4..0f5e1d6fb 100644 --- a/src/slic3r/GUI/UpdateDialogs.hpp +++ b/src/slic3r/GUI/UpdateDialogs.hpp @@ -42,7 +42,7 @@ private: class AppUpdateAvailableDialog : public MsgDialog { public: - AppUpdateAvailableDialog(const Semver& ver_current, const Semver& ver_online); + AppUpdateAvailableDialog(const Semver& ver_current, const Semver& ver_online, bool from_user); AppUpdateAvailableDialog(AppUpdateAvailableDialog&&) = delete; AppUpdateAvailableDialog(const AppUpdateAvailableDialog&) = delete; AppUpdateAvailableDialog& operator=(AppUpdateAvailableDialog&&) = delete; @@ -53,7 +53,7 @@ public: bool disable_version_check() const; static wxSize AUAD_size; private: - wxCheckBox* cbox; + wxCheckBox* cbox {nullptr}; }; class AppUpdateDownloadDialog : public MsgDialog diff --git a/src/slic3r/Utils/AppUpdater.cpp b/src/slic3r/Utils/AppUpdater.cpp index bd71e86ec..aa3339f1e 100644 --- a/src/slic3r/Utils/AppUpdater.cpp +++ b/src/slic3r/Utils/AppUpdater.cpp @@ -221,7 +221,7 @@ boost::filesystem::path AppUpdater::priv::download_file(const DownloadAppData& d } // progress event size_t gui_progress = progress.dltotal > 0 ? 100 * progress.dlnow / progress.dltotal : 0; - BOOST_LOG_TRIVIAL(error) << "App download " << gui_progress << "% " << progress.dlnow << " of " << progress.dltotal; + BOOST_LOG_TRIVIAL(debug) << "App download " << gui_progress << "% " << progress.dlnow << " of " << progress.dltotal; if (last_gui_progress < gui_progress && (last_gui_progress != 0 || gui_progress != 100)) { last_gui_progress = gui_progress; wxCommandEvent* evt = new wxCommandEvent(EVT_SLIC3R_APP_DOWNLOAD_PROGRESS); @@ -243,14 +243,15 @@ boost::filesystem::path AppUpdater::priv::download_file(const DownloadAppData& d tmp_path += format(".%1%%2%", get_current_pid(), ".download"); try { - boost::nowide::fstream file(tmp_path.string(), std::ios::out | std::ios::binary | std::ios::trunc); - file.write(body.c_str(), body.size()); - file.close(); + FILE* file; + file = fopen(tmp_path.string().c_str(), "wb"); + fwrite(body.c_str(), 1, body.size(), file); + fclose(file); boost::filesystem::rename(tmp_path, dest_path); } - catch (const std::exception&) + catch (const std::exception& e) { - error_message = GUI::format("Failed to write and move %1% to %2%", tmp_path, dest_path); + error_message = GUI::format("Failed to write and move %1% to %2%:/n%3%", tmp_path, dest_path, e.what()); return false; } return true; @@ -363,10 +364,10 @@ void AppUpdater::priv::parse_version_string(const std::string& body) if (data.first == "url") { new_data.url = data.second.data(); new_data.target_path = m_default_dest_folder / AppUpdater::get_filename_from_url(new_data.url); - BOOST_LOG_TRIVIAL(error) << format("parsing version string: url: %1%", new_data.url); + BOOST_LOG_TRIVIAL(info) << format("parsing version string: url: %1%", new_data.url); } else if (data.first == "size"){ new_data.size = std::stoi(data.second.data()); - BOOST_LOG_TRIVIAL(error) << format("parsing version string: expected size: %1%", new_data.size); + BOOST_LOG_TRIVIAL(info) << format("parsing version string: expected size: %1%", new_data.size); } } }