diff --git a/src/libslic3r/AppConfig.cpp b/src/libslic3r/AppConfig.cpp index ba0d363f7c..cf6cd95b40 100644 --- a/src/libslic3r/AppConfig.cpp +++ b/src/libslic3r/AppConfig.cpp @@ -42,7 +42,8 @@ using namespace nlohmann; namespace Slic3r { -static const std::string VERSION_CHECK_URL = "https://api.github.com/repos/softfever/OrcaSlicer/releases/latest"; +static const std::string VERSION_CHECK_URL_STABLE = "https://api.github.com/repos/softfever/OrcaSlicer/releases/latest"; +static const std::string VERSION_CHECK_URL = "https://api.github.com/repos/softfever/OrcaSlicer/releases"; static const std::string MODELS_STR = "models"; const std::string AppConfig::SECTION_FILAMENTS = "filaments"; @@ -240,6 +241,10 @@ void AppConfig::set_defaults() set_bool("stealth_mode", false); } + if(get("check_stable_update_only").empty()) { + set_bool("check_stable_update_only", false); + } + // Orca if(get("show_splash_screen").empty()) { set_bool("show_splash_screen", true); @@ -1253,10 +1258,10 @@ std::string AppConfig::config_path() return path; } -std::string AppConfig::version_check_url() const +std::string AppConfig::version_check_url(bool stable_only/* = false*/) const { auto from_settings = get("version_check_url"); - return from_settings.empty() ? VERSION_CHECK_URL : from_settings; + return from_settings.empty() ? stable_only ? VERSION_CHECK_URL_STABLE : VERSION_CHECK_URL : from_settings; } bool AppConfig::exists() diff --git a/src/libslic3r/AppConfig.hpp b/src/libslic3r/AppConfig.hpp index 1219adec9e..b785ebf8af 100644 --- a/src/libslic3r/AppConfig.hpp +++ b/src/libslic3r/AppConfig.hpp @@ -247,7 +247,7 @@ public: // Get the Slic3r version check url. // This returns a hardcoded string unless it is overriden by "version_check_url" in the ini file. - std::string version_check_url() const; + std::string version_check_url(bool stable_only = false) const; // Returns the original Slic3r version found in the ini file before it was overwritten // by the current version diff --git a/src/slic3r/GUI/GUI_App.cpp b/src/slic3r/GUI/GUI_App.cpp index 1f1efd0862..157b1e7dbb 100644 --- a/src/slic3r/GUI/GUI_App.cpp +++ b/src/slic3r/GUI/GUI_App.cpp @@ -4,6 +4,7 @@ #include "GUI_ObjectList.hpp" #include "GUI_Factories.hpp" #include "format.hpp" +#include "libslic3r_version.h" // Localization headers: include libslic3r version first so everything in this file // uses the slic3r/GUI version (the macros will take precedence over the functions). @@ -4290,7 +4291,8 @@ Semver get_version(const std::string& str, const std::regex& regexp) { void GUI_App::check_new_version_sf(bool show_tips, int by_user) { AppConfig* app_config = wxGetApp().app_config; - auto version_check_url = app_config->version_check_url(); + bool check_stable_only = app_config->get_bool("check_stable_update_only"); + auto version_check_url = app_config->version_check_url(check_stable_only); Http::get(version_check_url) .on_error([&](std::string body, std::string error, unsigned http_status) { (void)body; @@ -4298,25 +4300,22 @@ void GUI_App::check_new_version_sf(bool show_tips, int by_user) error); }) .timeout_connect(1) - .on_complete([this,by_user](std::string body, unsigned http_status) { + .on_complete([this,by_user, check_stable_only](std::string body, unsigned http_status) { // Http response OK if (http_status != 200) return; try { boost::trim(body); - // SoftFever: parse github release, ported from SS - + // Orca: parse github release, inspired by SS boost::property_tree::ptree root; - std::stringstream json_stream(body); boost::property_tree::read_json(json_stream, root); - bool i_am_pre = false; // at least two number, use '.' as separator. can be followed by -Az23 for prereleased and +Az42 for // metadata std::regex matcher("[0-9]+\\.[0-9]+(\\.[0-9]+)*(-[A-Za-z0-9]+)?(\\+[A-Za-z0-9]+)?"); - Semver current_version = get_version(SoftFever_VERSION, matcher); + Semver current_version = get_version(SoftFever_VERSION, matcher); Semver best_pre(1, 0, 0); Semver best_release(1, 0, 0); std::string best_pre_url; @@ -4324,56 +4323,73 @@ void GUI_App::check_new_version_sf(bool show_tips, int by_user) std::string best_release_content; std::string best_pre_content; const std::regex reg_num("([0-9]+)"); - std::string tag = root.get("tag_name"); - if (tag[0] == 'v') - tag.erase(0, 1); - for (std::regex_iterator it = std::sregex_iterator(tag.begin(), tag.end(), reg_num); - it != std::sregex_iterator(); ++it) { - } - Semver tag_version = get_version(tag, matcher); - if (current_version == tag_version) - i_am_pre = root.get("prerelease"); - if (root.get("prerelease")) { - if (best_pre < tag_version) { - best_pre = tag_version; - best_pre_url = root.get("html_url"); - best_pre_content = root.get("body"); - best_pre.set_prerelease("Preview"); - } + if (check_stable_only) { + std::string tag = root.get("tag_name"); + if (tag[0] == 'v') + tag.erase(0, 1); + for (std::regex_iterator it = std::sregex_iterator(tag.begin(), tag.end(), reg_num); it != std::sregex_iterator(); ++it) {} + Semver tag_version = get_version(tag, matcher); + if (root.get("prerelease")) { + if (best_pre < tag_version) { + best_pre = tag_version; + best_pre_url = root.get("html_url"); + best_pre_content = root.get("body"); + best_pre.set_prerelease("Preview"); + } + } else { + if (best_release < tag_version) { + best_release = tag_version; + best_release_url = root.get("html_url"); + best_release_content = root.get("body"); + } + } } else { - if (best_release < tag_version) { - best_release = tag_version; - best_release_url = root.get("html_url"); - best_release_content = root.get("body"); - } + for (auto json_version : root) { + std::string tag = json_version.second.get("tag_name"); + if (tag[0] == 'v') + tag.erase(0, 1); + for (std::regex_iterator it = std::sregex_iterator(tag.begin(), tag.end(), reg_num); it != std::sregex_iterator(); + ++it) {} + Semver tag_version = get_version(tag, matcher); + if (json_version.second.get("prerelease")) { + if (best_pre < tag_version) { + best_pre = tag_version; + best_pre_url = json_version.second.get("html_url"); + best_pre_content = json_version.second.get("body"); + best_pre.set_prerelease("Preview"); + } + } else { + if (best_release < tag_version) { + best_release = tag_version; + best_release_url = json_version.second.get("html_url"); + best_release_content = json_version.second.get("body"); + } + } + } } // if release is more recent than beta, use release anyway if (best_pre < best_release) { - best_pre = best_release; - best_pre_url = best_release_url; - best_pre_content = best_release_content; + best_pre = best_release; + best_pre_url = best_release_url; + best_pre_content = best_release_content; } // if we're the most recent, don't do anything - if ((i_am_pre ? best_pre : best_release) <= current_version) { - if (by_user != 0) - this->no_new_version(); - return; + if ((check_stable_only ? best_release : best_pre) <= current_version) { + if (by_user != 0) + this->no_new_version(); + return; } - // BOOST_LOG_TRIVIAL(info) << format("Got %1% online version: `%2%`. Sending to GUI thread...", - // SLIC3R_APP_NAME, i_am_pre ? best_pre.to_string(): best_release.to_string()); - - version_info.url = i_am_pre ? best_pre_url : best_release_url; - version_info.version_str = i_am_pre ? best_pre.to_string() : best_release.to_string_sf(); - version_info.description = i_am_pre ? best_pre_content : best_release_content; + version_info.url = check_stable_only ? best_release_url : best_pre_url; + version_info.version_str = check_stable_only ? best_release.to_string_sf() : best_pre.to_string(); + version_info.description = check_stable_only ? best_release_content : best_pre_content; version_info.force_upgrade = false; - wxCommandEvent *evt = new wxCommandEvent(EVT_SLIC3R_VERSION_ONLINE); - evt->SetString((i_am_pre ? best_pre : best_release).to_string()); + wxCommandEvent* evt = new wxCommandEvent(EVT_SLIC3R_VERSION_ONLINE); + evt->SetString((check_stable_only ? best_release : best_pre).to_string()); GUI::wxGetApp().QueueEvent(evt); - } catch (...) { - } + } catch (...) {} }) .perform(); } @@ -4591,8 +4607,7 @@ void GUI_App::sync_preset(Preset* preset) if (http_code >= 400) { result = 0; updated_info = "hold"; - } - else + } else result = -1; } } @@ -4614,8 +4629,7 @@ void GUI_App::sync_preset(Preset* preset) auto update_time_str = values_map[BBL_JSON_KEY_UPDATE_TIME]; if (!update_time_str.empty()) update_time = std::atoll(update_time_str.c_str()); - } - else { + } else { BOOST_LOG_TRIVIAL(trace) << "[sync_preset]create: request_setting_id failed, http code "<= 400 if (http_code >= 400) { @@ -4625,12 +4639,10 @@ void GUI_App::sync_preset(Preset* preset) else result = -1; } - } - else { + } else { BOOST_LOG_TRIVIAL(trace) << "[sync_preset]create: can not generate differed preset"; } - } - else if (preset->sync_info.compare("update") == 0) { + } else if (preset->sync_info.compare("update") == 0) { if (!setting_id.empty()) { int ret = preset_bundle->get_differed_values_to_update(*preset, values_map); if (!ret) { @@ -5028,7 +5040,7 @@ bool GUI_App::select_language() // 3) new_language_info->CanonicalName is a safe bet. It points to a valid dictionary name. app_config->set("language", new_language_info->CanonicalName.ToUTF8().data()); return true; - } + } } return false; @@ -5936,18 +5948,15 @@ void GUI_App::MacOpenFiles(const wxArrayString &fileNames) input_files.push_back(non_gcode_files[i]); } this->plater()->load_files(input_files); - } - else { + } else { for (size_t i = 0; i < files.size(); ++i) { this->init_params->input_files.emplace_back(files[i]); } } - } - else { + } else { if (m_post_initialized) { this->plater()->load_gcode(gcode_files.front()); - } - else { + } else { this->init_params->input_gcode = true; this->init_params->input_files = { into_u8(gcode_files.front()) }; } @@ -6296,8 +6305,7 @@ void GUI_App::gcode_thumbnails_debug() width = 0; height = 0; rows.clear(); - } - else if (reading_image) + } else if (reading_image) row += gcode_line.substr(2); } } diff --git a/src/slic3r/GUI/Preferences.cpp b/src/slic3r/GUI/Preferences.cpp index e722d90858..a4b4edf5a1 100644 --- a/src/slic3r/GUI/Preferences.cpp +++ b/src/slic3r/GUI/Preferences.cpp @@ -996,6 +996,7 @@ wxWindow* PreferencesDialog::create_general_page() auto item_region= create_item_region_combobox(_L("Login Region"), page, _L("Login Region"), Regions); auto item_stealth_mode = create_item_checkbox(_L("Stealth Mode"), page, _L("Stealth Mode"), 50, "stealth_mode"); + auto item_check_stable_version_only = create_item_checkbox(_L("Check for stable updates only"), page, _L("Check for stable updates only"), 50, "check_stable_update_only"); std::vector Units = {_L("Metric") + " (mm, g)", _L("Imperial") + " (in, oz)"}; auto item_currency = create_item_combobox(_L("Units"), page, _L("Units"), "use_inches", Units); @@ -1072,6 +1073,7 @@ wxWindow* PreferencesDialog::create_general_page() sizer_page->Add(item_hints, 0, wxTOP, FromDIP(3)); sizer_page->Add(title_presets, 0, wxTOP | wxEXPAND, FromDIP(20)); sizer_page->Add(item_stealth_mode, 0, wxTOP, FromDIP(3)); + sizer_page->Add(item_check_stable_version_only, 0, wxTOP, FromDIP(3)); sizer_page->Add(item_calc_mode, 0, wxTOP, FromDIP(3)); sizer_page->Add(item_user_sync, 0, wxTOP, FromDIP(3)); sizer_page->Add(item_system_sync, 0, wxTOP, FromDIP(3)); diff --git a/src/slic3r/GUI/ReleaseNote.cpp b/src/slic3r/GUI/ReleaseNote.cpp index b94e1bf5c3..539f9c08e9 100644 --- a/src/slic3r/GUI/ReleaseNote.cpp +++ b/src/slic3r/GUI/ReleaseNote.cpp @@ -23,6 +23,7 @@ #include #include "Plater.hpp" #include "BitmapCache.hpp" +#include "slic3r/GUI/GUI_App.hpp" namespace Slic3r { namespace GUI { @@ -293,7 +294,8 @@ UpdateVersionDialog::UpdateVersionDialog(wxWindow *parent) m_vebview_release_note->Bind(wxEVT_WEBVIEW_NAVIGATING,[=](wxWebViewEvent& event){ static bool load_url_first = false; if(load_url_first){ - wxLaunchDefaultBrowser(url_line); + // Orca: not used in Orca Slicer + // wxLaunchDefaultBrowser(url_line); event.Veto(); }else{ load_url_first = true; @@ -317,11 +319,6 @@ UpdateVersionDialog::UpdateVersionDialog(wxWindow *parent) - m_bitmap_open_in_browser = new wxStaticBitmap(this, wxID_ANY, create_scaled_bitmap("open_in_browser", this, 12), wxDefaultPosition, wxDefaultSize, 0 ); - m_link_open_in_browser = new wxHyperlinkCtrl(this, wxID_ANY, "Open in browser", ""); - m_link_open_in_browser->SetFont(Label::Body_12); - - auto sizer_button = new wxBoxSizer(wxHORIZONTAL); @@ -357,6 +354,17 @@ UpdateVersionDialog::UpdateVersionDialog(wxWindow *parent) EndModal(wxID_NO); }); + m_cb_stable_only = new CheckBox(this); + m_cb_stable_only->SetValue(wxGetApp().app_config->get_bool("check_stable_update_only")); + m_cb_stable_only->Bind(wxEVT_TOGGLEBUTTON, [this](wxCommandEvent& e) { + wxGetApp().app_config->set_bool("check_stable_update_only", m_cb_stable_only->GetValue()); + e.Skip(); + }); + + auto stable_only_label = new Label(this, _L("Check for stable updates only")); + stable_only_label->SetFont(Label::Body_13); + stable_only_label->SetForegroundColour(wxColour(38, 46, 48)); + stable_only_label->SetFont(Label::Body_12); m_button_cancel = new Button(this, _L("Cancel")); m_button_cancel->SetBackgroundColor(btn_bg_white); @@ -372,10 +380,10 @@ UpdateVersionDialog::UpdateVersionDialog(wxWindow *parent) m_sizer_main->Add(m_line_top, 0, wxEXPAND | wxBOTTOM, 0); - sizer_button->Add(m_bitmap_open_in_browser, 0, wxALIGN_CENTER | wxLEFT, FromDIP(7)); - sizer_button->Add(m_link_open_in_browser, 0, wxALIGN_CENTER| wxLEFT, FromDIP(3)); //sizer_button->Add(m_remind_choice, 0, wxALL | wxEXPAND, FromDIP(5)); sizer_button->AddStretchSpacer(); + sizer_button->Add(stable_only_label, 0, wxALIGN_CENTER | wxLEFT, FromDIP(7)); + sizer_button->Add(m_cb_stable_only, 0, wxALIGN_CENTER | wxLEFT, FromDIP(5)); sizer_button->Add(m_button_download, 0, wxALL, FromDIP(5)); sizer_button->Add(m_button_skip_version, 0, wxALL, FromDIP(5)); sizer_button->Add(m_button_cancel, 0, wxALL, FromDIP(5)); @@ -510,7 +518,6 @@ void UpdateVersionDialog::update_version_info(wxString release_note, wxString ve m_text_up_info->Hide(); m_simplebook_release_note->SetSelection(1); m_vebview_release_note->LoadURL(from_u8(url_line)); - m_link_open_in_browser->SetURL(url_line); } else { m_simplebook_release_note->SetMaxSize(wxSize(FromDIP(560), FromDIP(430))); diff --git a/src/slic3r/GUI/ReleaseNote.hpp b/src/slic3r/GUI/ReleaseNote.hpp index a6deabdf27..98d42b964c 100644 --- a/src/slic3r/GUI/ReleaseNote.hpp +++ b/src/slic3r/GUI/ReleaseNote.hpp @@ -99,8 +99,8 @@ public: wxBoxSizer * sizer_text_release_note{nullptr}; Label * m_staticText_release_note{nullptr}; wxStaticBitmap* m_bitmap_open_in_browser; - wxHyperlinkCtrl* m_link_open_in_browser; Button* m_button_skip_version; + CheckBox* m_cb_stable_only; Button* m_button_download; Button* m_button_cancel; std::string url_line;