configuration updater

forced update dialog
check for updates button
check address when downloading bundles
This commit is contained in:
David Kocik 2020-02-04 15:24:35 +01:00
parent 617912ecc1
commit 65b9ef6636
9 changed files with 257 additions and 39 deletions

View file

@ -278,34 +278,23 @@ bool GUI_App::on_init_inner()
RemovableDriveManager::get_instance().update(wxGetLocalTime(), true);
#endif
// Preset updating & Configwizard are done after the above initializations,
// and after MainFrame is created & shown.
// The extra CallAfter() is needed because of Mac, where this is the only way
// to popup a modal dialog on start without screwing combo boxes.
// This is ugly but I honestly found no better way to do it.
// Neither wxShowEvent nor wxWindowCreateEvent work reliably.
// Preset updating & Configwizard are done after the above initializations,
// and after MainFrame is created & shown.
// The extra CallAfter() is needed because of Mac, where this is the only way
// to popup a modal dialog on start without screwing combo boxes.
// This is ugly but I honestly found no better way to do it.
// Neither wxShowEvent nor wxWindowCreateEvent work reliably.
static bool once = true;
if (once) {
once = false;
check_updates(false);
PresetUpdater::UpdateResult updater_result;
try {
updater_result = preset_updater->config_update(app_config->orig_version());
if (updater_result == PresetUpdater::R_INCOMPAT_EXIT) {
mainframe->Close();
} else if (updater_result == PresetUpdater::R_INCOMPAT_CONFIGURED) {
app_conf_exists = true;
}
} catch (const std::exception &ex) {
show_error(nullptr, from_u8(ex.what()));
}
CallAfter([this] {
config_wizard_startup();
preset_updater->slic3r_update_notify();
preset_updater->sync(preset_bundle);
});
CallAfter([this] {
config_wizard_startup();
preset_updater->slic3r_update_notify();
preset_updater->sync(preset_bundle);
});
}
});
@ -810,7 +799,7 @@ void GUI_App::add_config_menu(wxMenuBar *menu)
local_menu->Append(config_id_base + ConfigMenuWizard, config_wizard_name + dots, config_wizard_tooltip);
local_menu->Append(config_id_base + ConfigMenuSnapshots, _(L("&Configuration Snapshots")) + dots, _(L("Inspect / activate configuration snapshots")));
local_menu->Append(config_id_base + ConfigMenuTakeSnapshot, _(L("Take Configuration &Snapshot")), _(L("Capture a configuration snapshot")));
// local_menu->Append(config_id_base + ConfigMenuUpdate, _(L("Check for updates")), _(L("Check for configuration updates")));
local_menu->Append(config_id_base + ConfigMenuUpdate, _(L("Check for updates")), _(L("Check for configuration updates")));
local_menu->AppendSeparator();
local_menu->Append(config_id_base + ConfigMenuPreferences, _(L("&Preferences")) + dots +
#ifdef __APPLE__
@ -841,6 +830,9 @@ void GUI_App::add_config_menu(wxMenuBar *menu)
case ConfigMenuWizard:
run_wizard(ConfigWizard::RR_USER);
break;
case ConfigMenuUpdate:
check_updates(true);
break;
case ConfigMenuTakeSnapshot:
// Take a configuration snapshot.
if (check_unsaved_changes()) {
@ -1230,6 +1222,30 @@ bool GUI_App::config_wizard_startup()
return false;
}
void GUI_App::check_updates(const bool verbose)
{
PresetUpdater::UpdateResult updater_result;
try {
updater_result = preset_updater->config_update(app_config->orig_version());
if (updater_result == PresetUpdater::R_INCOMPAT_EXIT) {
mainframe->Close();
}
else if (updater_result == PresetUpdater::R_INCOMPAT_CONFIGURED) {
app_conf_exists = true;
}
else if(verbose && updater_result == PresetUpdater::R_NOOP)
{
MsgNoUpdates dlg;
dlg.ShowModal();
}
}
catch (const std::exception & ex) {
show_error(nullptr, from_u8(ex.what()));
}
}
// static method accepting a wxWindow object as first parameter
// void warning_catcher{
// my($self, $message_dialog) = @_;

View file

@ -200,6 +200,7 @@ private:
bool select_language();
bool config_wizard_startup();
void check_updates(const bool verbose);
#ifdef __WXMSW__
void associate_3mf_files();

View file

@ -5375,6 +5375,13 @@ void Plater::on_config_change(const DynamicPrintConfig &config)
this->p->schedule_background_process();
}
void Plater::set_bed_shape() const
{
p->set_bed_shape(p->config->option<ConfigOptionPoints>("bed_shape")->values,
p->config->option<ConfigOptionString>("bed_custom_texture")->value,
p->config->option<ConfigOptionString>("bed_custom_model")->value);
}
void Plater::force_filament_colors_update()
{
bool update_scheduled = false;

View file

@ -284,6 +284,8 @@ public:
const Mouse3DController& get_mouse3d_controller() const;
Mouse3DController& get_mouse3d_controller();
void set_bed_shape() const;
// ROII wrapper for suppressing the Undo / Redo snapshot to be taken.
class SuppressSnapshots
{

View file

@ -142,6 +142,71 @@ MsgUpdateConfig::MsgUpdateConfig(const std::vector<Update> &updates) :
MsgUpdateConfig::~MsgUpdateConfig() {}
//MsgUpdateForced
MsgUpdateForced::MsgUpdateForced(const std::vector<Update>& updates) :
MsgDialog(nullptr, wxString::Format(_(L("%s incompatibility")), SLIC3R_APP_NAME), _(L("Configuration update is necessary to install")), wxID_NONE)
{
auto* text = new wxStaticText(this, wxID_ANY, wxString::Format(_(L(
"%s will now start updates. Otherwise it won't be able to start.\n\n"
"Note that a full configuration snapshot will be created first. It can then be restored at any time "
"should there be a problem with the new version.\n\n"
"Updated configuration bundles:"
)), SLIC3R_APP_NAME));
logo->SetBitmap(create_scaled_bitmap("PrusaSlicer_192px_grayscale.png", this, 192));
text->Wrap(CONTENT_WIDTH * wxGetApp().em_unit());
content_sizer->Add(text);
content_sizer->AddSpacer(VERT_SPACING);
const auto lang_code = wxGetApp().current_language_code_safe().ToStdString();
auto* versions = new wxBoxSizer(wxVERTICAL);
for (const auto& update : updates) {
auto* flex = new wxFlexGridSizer(2, 0, VERT_SPACING);
auto* text_vendor = new wxStaticText(this, wxID_ANY, update.vendor);
text_vendor->SetFont(boldfont);
flex->Add(text_vendor);
flex->Add(new wxStaticText(this, wxID_ANY, update.version.to_string()));
if (!update.comment.empty()) {
flex->Add(new wxStaticText(this, wxID_ANY, _(L("Comment:"))), 0, wxALIGN_RIGHT);
auto* update_comment = new wxStaticText(this, wxID_ANY, from_u8(update.comment));
update_comment->Wrap(CONTENT_WIDTH * wxGetApp().em_unit());
flex->Add(update_comment);
}
versions->Add(flex);
if (!update.changelog_url.empty() && update.version.prerelease() == nullptr) {
auto* line = new wxBoxSizer(wxHORIZONTAL);
auto changelog_url = (boost::format(update.changelog_url) % lang_code).str();
line->AddSpacer(3 * VERT_SPACING);
line->Add(new wxHyperlinkCtrl(this, wxID_ANY, _(L("Open changelog page")), changelog_url));
versions->Add(line);
}
}
content_sizer->Add(versions);
content_sizer->AddSpacer(2 * VERT_SPACING);
auto* btn_exit = new wxButton(this, wxID_EXIT, wxString::Format(_(L("Exit %s")), SLIC3R_APP_NAME));
btn_sizer->Add(btn_exit);
btn_sizer->AddSpacer(HORIZ_SPACING);
auto* btn_ok = new wxButton(this, wxID_OK);
btn_sizer->Add(btn_ok);
btn_ok->SetFocus();
auto exiter = [this](const wxCommandEvent& evt) { this->EndModal(evt.GetId()); };
btn_exit->Bind(wxEVT_BUTTON, exiter);
btn_ok->Bind(wxEVT_BUTTON, exiter);
Fit();
}
MsgUpdateForced::~MsgUpdateForced() {}
// MsgDataIncompatible
@ -157,7 +222,7 @@ MsgDataIncompatible::MsgDataIncompatible(const std::unordered_map<std::string, w
"You may either exit %s and try again with a newer version, or you may re-run the initial configuration. "
"Doing so will create a backup snapshot of the existing configuration before installing files compatible with this %s.")) + "\n",
SLIC3R_APP_NAME, SLIC3R_APP_NAME, SLIC3R_APP_NAME, SLIC3R_APP_NAME));
SLIC3R_APP_NAME, SLIC3R_APP_NAME, SLIC3R_APP_NAME, SLIC3R_APP_NAME));
text->Wrap(CONTENT_WIDTH * wxGetApp().em_unit());
content_sizer->Add(text);
@ -236,5 +301,28 @@ MsgDataLegacy::MsgDataLegacy() :
MsgDataLegacy::~MsgDataLegacy() {}
// MsgNoUpdate
MsgNoUpdates::MsgNoUpdates() :
MsgDialog(nullptr, _(L("Configuration updates")), _(L("No updates aviable")))
{
auto* text = new wxStaticText(this, wxID_ANY, wxString::Format(
_(L(
"%s has no configuration updates aviable."
)),
SLIC3R_APP_NAME, ConfigWizard::name()
));
text->Wrap(CONTENT_WIDTH * wxGetApp().em_unit());
content_sizer->Add(text);
content_sizer->AddSpacer(VERT_SPACING);
logo->SetBitmap(create_scaled_bitmap("PrusaSlicer_192px_grayscale.png", this, 192));
Fit();
}
MsgNoUpdates::~MsgNoUpdates() {}
}
}

View file

@ -62,6 +62,33 @@ public:
~MsgUpdateConfig();
};
// Informs about currently installed bundles not being compatible with the running Slic3r. Asks about action.
class MsgUpdateForced : public MsgDialog
{
public:
struct Update
{
std::string vendor;
Semver version;
std::string comment;
std::string changelog_url;
Update(std::string vendor, Semver version, std::string comment, std::string changelog_url)
: vendor(std::move(vendor))
, version(std::move(version))
, comment(std::move(comment))
, changelog_url(std::move(changelog_url))
{}
};
MsgUpdateForced(const std::vector<Update>& updates);
MsgUpdateForced(MsgUpdateForced&&) = delete;
MsgUpdateForced(const MsgUpdateForced&) = delete;
MsgUpdateForced& operator=(MsgUpdateForced&&) = delete;
MsgUpdateForced& operator=(const MsgUpdateForced&) = delete;
~MsgUpdateForced();
};
// Informs about currently installed bundles not being compatible with the running Slic3r. Asks about action.
class MsgDataIncompatible : public MsgDialog
{
@ -87,6 +114,17 @@ public:
~MsgDataLegacy();
};
// Informs about absence of bundles requiring update.
class MsgNoUpdates : public MsgDialog
{
public:
MsgNoUpdates();
MsgNoUpdates(MsgNoUpdates&&) = delete;
MsgNoUpdates(const MsgNoUpdates&) = delete;
MsgNoUpdates& operator=(MsgNoUpdates&&) = delete;
MsgNoUpdates& operator=(const MsgNoUpdates&) = delete;
~MsgNoUpdates();
};
}
}