From aef0c489e31ad4916b5e93dfb7b17e0200184868 Mon Sep 17 00:00:00 2001 From: Vojtech Kral Date: Wed, 6 Jun 2018 10:52:19 +0200 Subject: [PATCH] Fix: Dialog initialization ordering on OS X Perform update_check after MainFrame is created --- lib/Slic3r/GUI.pm | 27 ++++++++++++++++----------- xs/src/slic3r/GUI/GUI.cpp | 15 ++++++++++----- xs/src/slic3r/GUI/GUI.hpp | 3 +++ xs/src/slic3r/GUI/PresetBundle.cpp | 1 + xs/src/slic3r/Utils/PresetUpdater.cpp | 10 ++++++++-- 5 files changed, 38 insertions(+), 18 deletions(-) diff --git a/lib/Slic3r/GUI.pm b/lib/Slic3r/GUI.pm index 04dc80323..f2bf3baf8 100644 --- a/lib/Slic3r/GUI.pm +++ b/lib/Slic3r/GUI.pm @@ -105,15 +105,6 @@ sub OnInit { $self->{preset_updater} = Slic3r::PresetUpdater->new($VERSION_ONLINE_EVENT); Slic3r::GUI::set_preset_updater($self->{preset_updater}); - eval { - if (! $self->{preset_updater}->config_update()) { - exit 0; - } - }; - if ($@) { - warn $@ . "\n"; - fatal_error(undef, $@); - } Slic3r::GUI::load_language(); @@ -137,6 +128,7 @@ sub OnInit { ); $self->SetTopWindow($frame); + # This makes CallAfter() work EVT_IDLE($self->{mainframe}, sub { while (my $cb = shift @cb) { $cb->(); @@ -144,8 +136,21 @@ sub OnInit { $self->{app_config}->save if $self->{app_config}->dirty; }); - # On OSX the UI was not initialized correctly if the wizard was called - # before the UI was up and running. + # On OS X the UI tends to freeze in weird ways if modal dialogs (config wizard, update notifications, ...) + # are shown before or in the same event callback with the main frame creation. + # Therefore we schedule them for later using CallAfter. + $self->CallAfter(sub { + eval { + if (! $self->{preset_updater}->config_update()) { + exit 0; + } + }; + if ($@) { + warn $@ . "\n"; + fatal_error(undef, $@); + } + }); + $self->CallAfter(sub { if (! Slic3r::GUI::config_wizard_startup($app_conf_exists)) { # Only notify if there was not wizard so as not to bother too much ... diff --git a/xs/src/slic3r/GUI/GUI.cpp b/xs/src/slic3r/GUI/GUI.cpp index d42fd3538..d54a5683b 100644 --- a/xs/src/slic3r/GUI/GUI.cpp +++ b/xs/src/slic3r/GUI/GUI.cpp @@ -356,8 +356,7 @@ void add_config_menu(wxMenuBar *menu, int event_preferences_changed, int event_l Config::SnapshotDB::singleton().restore_snapshot(dlg.snapshot_to_activate(), *g_AppConfig).id); g_PresetBundle->load_presets(*g_AppConfig); // Load the currently selected preset into the GUI, update the preset selection box. - for (Tab *tab : g_tabs_list) - tab->load_current_preset(); + load_current_presets(); } } break; @@ -451,9 +450,8 @@ void config_wizard(int reason) show_error(nullptr, e.what()); } - // Load the currently selected preset into the GUI, update the preset selection box. - for (Tab *tab : g_tabs_list) - tab->load_current_preset(); + // Load the currently selected preset into the GUI, update the preset selection box. + load_current_presets(); } void open_preferences_dialog(int event_preferences) @@ -605,6 +603,13 @@ void add_created_tab(Tab* panel) g_wxTabPanel->AddPage(panel, panel->title()); } +void load_current_presets() +{ + for (Tab *tab : g_tabs_list) { + tab->load_current_preset(); + } +} + void show_error(wxWindow* parent, const wxString& message) { ErrorDialog msg(parent, message); msg.ShowModal(); diff --git a/xs/src/slic3r/GUI/GUI.hpp b/xs/src/slic3r/GUI/GUI.hpp index 4deee1910..31cf83731 100644 --- a/xs/src/slic3r/GUI/GUI.hpp +++ b/xs/src/slic3r/GUI/GUI.hpp @@ -116,6 +116,9 @@ void add_created_tab(Tab* panel); // Change option value in config void change_opt_value(DynamicPrintConfig& config, const t_config_option_key& opt_key, const boost::any& value, int opt_index = 0); +// Update UI / Tabs to reflect changes in the currently loaded presets +void load_current_presets(); + void show_error(wxWindow* parent, const wxString& message); void show_error_id(int id, const std::string& message); // For Perl void show_info(wxWindow* parent, const wxString& message, const wxString& title); diff --git a/xs/src/slic3r/GUI/PresetBundle.cpp b/xs/src/slic3r/GUI/PresetBundle.cpp index 98d351069..d36ef7b6f 100644 --- a/xs/src/slic3r/GUI/PresetBundle.cpp +++ b/xs/src/slic3r/GUI/PresetBundle.cpp @@ -101,6 +101,7 @@ PresetBundle::~PresetBundle() void PresetBundle::reset(bool delete_files) { // Clear the existing presets, delete their respective files. + this->vendors.clear(); this->prints .reset(delete_files); this->filaments.reset(delete_files); this->printers .reset(delete_files); diff --git a/xs/src/slic3r/Utils/PresetUpdater.cpp b/xs/src/slic3r/Utils/PresetUpdater.cpp index 9a4d1048f..dd46c43fe 100644 --- a/xs/src/slic3r/Utils/PresetUpdater.cpp +++ b/xs/src/slic3r/Utils/PresetUpdater.cpp @@ -162,7 +162,7 @@ bool PresetUpdater::priv::get_file(const std::string &url, const fs::path &targe % http_status % error; }) - .on_complete([&](std::string body, unsigned http_status) { + .on_complete([&](std::string body, unsigned /* http_status */) { fs::fstream file(tmp_path, std::ios::out | std::ios::binary | std::ios::trunc); file.write(body.c_str(), body.size()); file.close(); @@ -204,7 +204,7 @@ void PresetUpdater::priv::sync_version() const % http_status % error; }) - .on_complete([&](std::string body, unsigned http_status) { + .on_complete([&](std::string body, unsigned /* http_status */) { boost::trim(body); BOOST_LOG_TRIVIAL(info) << boost::format("Got Slic3rPE online version: `%1%`. Sending to GUI thread...") % body; wxCommandEvent* evt = new wxCommandEvent(version_online_event); @@ -553,6 +553,12 @@ bool PresetUpdater::config_update() const if (res == wxID_OK) { BOOST_LOG_TRIVIAL(debug) << "User agreed to perform the update"; p->perform_updates(std::move(updates)); + + // Reload global configuration + auto *app_config = GUI::get_app_config(); + app_config->reset_selections(); + GUI::get_preset_bundle()->load_presets(*app_config); + GUI::load_current_presets(); } else { BOOST_LOG_TRIVIAL(info) << "User refused the update"; }