diff --git a/lib/Slic3r.pm b/lib/Slic3r.pm index df04dc96..47442f64 100644 --- a/lib/Slic3r.pm +++ b/lib/Slic3r.pm @@ -60,7 +60,7 @@ use Slic3r::Print::Object; use Slic3r::Print::Region; use Slic3r::Surface; use Slic3r::TriangleMesh; -eval "use Slic3r::Build"; +our $build = eval "use Slic3r::Build; 1"; use constant SCALING_FACTOR => 0.000001; use constant RESOLUTION => 0.0125; diff --git a/lib/Slic3r/GUI.pm b/lib/Slic3r/GUI.pm index ceb6adbb..0f4957ca 100644 --- a/lib/Slic3r/GUI.pm +++ b/lib/Slic3r/GUI.pm @@ -37,6 +37,7 @@ use constant MI_TAB_PRINTER => &Wx::NewId; use constant MI_CONF_WIZARD => &Wx::NewId; use constant MI_WEBSITE => &Wx::NewId; +use constant MI_VERSIONCHECK => &Wx::NewId; use constant MI_DOCUMENTATION => &Wx::NewId; our $datadir; @@ -46,6 +47,7 @@ our $mode; our $Settings = { _ => { mode => 'simple', + version_check => 1, }, }; @@ -155,11 +157,14 @@ sub OnInit { $helpMenu->Append(MI_CONF_WIZARD, "&Configuration $Slic3r::GUI::ConfigWizard::wizard…", "Run Configuration $Slic3r::GUI::ConfigWizard::wizard"); $helpMenu->AppendSeparator(); $helpMenu->Append(MI_WEBSITE, "Slic3r &Website", 'Open the Slic3r website in your browser'); + my $versioncheck = $helpMenu->Append(MI_VERSIONCHECK, "Check for &Updates...", 'Check for new Slic3r versions'); + $versioncheck->Enable(Slic3r::GUI->have_version_check); $helpMenu->Append(MI_DOCUMENTATION, "&Documentation", 'Open the Slic3r documentation in your browser'); $helpMenu->AppendSeparator(); $helpMenu->Append(wxID_ABOUT, "&About Slic3r", 'Show about dialog'); EVT_MENU($frame, MI_CONF_WIZARD, sub { $self->{skeinpanel}->config_wizard }); EVT_MENU($frame, MI_WEBSITE, sub { Wx::LaunchDefaultBrowser('http://slic3r.org/') }); + EVT_MENU($frame, MI_VERSIONCHECK, sub { Slic3r::GUI->check_version(manual => 1) }); EVT_MENU($frame, MI_DOCUMENTATION, sub { Wx::LaunchDefaultBrowser('https://github.com/alexrj/Slic3r/wiki/Documentation') }); EVT_MENU($frame, wxID_ABOUT, \&about); } @@ -192,6 +197,11 @@ sub OnInit { $self->{skeinpanel}->config_wizard if $run_wizard; + Slic3r::GUI->check_version + if Slic3r::GUI->have_version_check + && ($Settings->{_}{version_check} // 1) + && (!$Settings->{_}{last_version_check} || (time - $Settings->{_}{last_version_check}) >= 86400); + return 1; } @@ -222,6 +232,12 @@ sub show_error { Wx::MessageDialog->new($self, $message, 'Error', wxOK | wxICON_ERROR)->ShowModal; } +sub show_info { + my $self = shift; + my ($message, $title) = @_; + Wx::MessageDialog->new($self, $message, $title || 'Notice', wxOK | wxICON_INFORMATION)->ShowModal; +} + sub fatal_error { my $self = shift; $self->show_error(@_); @@ -257,6 +273,37 @@ sub save_settings { Slic3r::Config->write_ini("$datadir/slic3r.ini", $Settings); } +sub have_version_check { + my $class = shift; + + return $Slic3r::have_threads && $Slic3r::build && eval "use LWP::UserAgent; 1"; +} + +sub check_version { + my $class = shift; + my %p = @_; + Slic3r::debugf "Checking for updates...\n"; + + threads->create(sub { + my $ua = LWP::UserAgent->new; + $ua->timeout(10); + my $response = $ua->get('http://slic3r.org/updatecheck'); + if ($response->is_success) { + if ($response->decoded_content =~ /^obsolete ?= ?([a-z0-9.-]+,)*\Q$Slic3r::VERSION\E(?:,|$)/) { + my $res = Wx::MessageDialog->new(undef, "A new version is available. Do you want to open the Slic3r website now?", + 'Update', wxYES_NO | wxCANCEL | wxYES_DEFAULT | wxICON_INFORMATION | wxICON_ERROR)->ShowModal; + Wx::LaunchDefaultBrowser('http://slic3r.org/') if $res == wxID_YES; + } else { + Slic3r::GUI::show_info(undef, "You're using the latest version. No updates are available.") if $p{manual}; + } + $Settings->{_}{last_version_check} = time(); + Slic3r::GUI->save_settings; + } else { + Slic3r::GUI::show_error(undef, "Failed to check for updates. Try later.") if $p{manual}; + } + })->detach; +} + package Slic3r::GUI::ProgressStatusBar; use Wx qw(:gauge :misc); use base 'Wx::StatusBar'; diff --git a/lib/Slic3r/GUI/OptionsGroup.pm b/lib/Slic3r/GUI/OptionsGroup.pm index 8734ff6f..b228ea59 100644 --- a/lib/Slic3r/GUI/OptionsGroup.pm +++ b/lib/Slic3r/GUI/OptionsGroup.pm @@ -180,6 +180,7 @@ sub _build_field { } elsif ($opt->{type} eq 'bool') { $field = Wx::CheckBox->new($self->parent, -1, ""); $field->SetValue($opt->{default}); + $field->Disable if $opt->{readonly}; EVT_CHECKBOX($self->parent, $field, sub { $self->_on_change($opt_key, $field->GetValue); }); $self->_setters->{$opt_key} = sub { $field->SetValue($_[0]) }; $tooltip .= " (default: " . ($opt->{default} ? 'yes' : 'no') . ")" if defined($opt->{default}); diff --git a/lib/Slic3r/GUI/Preferences.pm b/lib/Slic3r/GUI/Preferences.pm index 25ad5621..2ad5bd24 100644 --- a/lib/Slic3r/GUI/Preferences.pm +++ b/lib/Slic3r/GUI/Preferences.pm @@ -22,6 +22,14 @@ sub new { values => ['simple','expert'], default => $Slic3r::GUI::Settings->{_}{mode}, }, + { + opt_key => 'version_check', + type => 'bool', + label => 'Check for updates', + tooltip => 'If this is enabled, Slic3r will check for updates daily and display a reminder if a newer version is available.', + default => $Slic3r::GUI::Settings->{_}{version_check} // 1, + readonly => !Slic3r::GUI->have_version_check, + }, ], on_change => sub { $self->{values}{$_[0]} = $_[1] }, label_width => 100,