NEW: Support beta version update

jira: STUDIO-7392

Change-Id: Iea71823295669c56e2550e1c61bf782e611a2daa
(cherry picked from commit f6f87cd36fece5df8e9a63e229a6f2c965b2b417)
This commit is contained in:
hang.xu 2024-09-02 20:45:26 +08:00 committed by Lane.Wei
parent 9096b2403c
commit dbeed95448
3 changed files with 91 additions and 3 deletions

View File

@ -4474,7 +4474,7 @@ void GUI_App::reset_to_active()
last_active_point = std::chrono::system_clock::now();
}
void GUI_App::check_update(bool show_tips, int by_user)
void GUI_App::check_update(bool show_tips, int by_user, VersionUpdateType type)
{
if (version_info.version_str.empty()) return;
if (version_info.url.empty()) return;
@ -4495,9 +4495,18 @@ void GUI_App::check_update(bool show_tips, int by_user)
}
} else {
wxGetApp().app_config->set("upgrade", "force_upgrade", false);
if (show_tips)
if (app_config->get("enable_beta_version_update") == "true"){
if (type == ReleaseVersionUpdate){
check_beta_version(show_tips, by_user);
}
else if (type == BetaVersionUpdate){
this->no_new_version();
}
}
else{
this->no_new_version();
}
}
}
void GUI_App::check_new_version(bool show_tips, int by_user)
@ -4562,6 +4571,76 @@ void GUI_App::check_new_version(bool show_tips, int by_user)
}).perform();
}
void GUI_App::check_beta_version(bool show_tips, int by_user) {
std::string platform = "windows";
#ifdef __WINDOWS__
platform = "windows";
#endif
#ifdef __APPLE__
platform = "macos";
#endif
#ifdef __LINUX__
platform = "linux";
#endif
std::string repoOwner = "bambulab"; // The owner of repository
std::string repoName = "BambuStudio"; // The name of repository
//"https://api.github.com/repos/bambulab/BambuStudio/releases"
std::string url = "https://api.github.com/repos/" + repoOwner + "/" + repoName + "/releases";
Slic3r::Http http = Slic3r::Http::get(url);
http.header("accept", "application/json")
.timeout_connect(TIMEOUT_CONNECT)
.timeout_max(TIMEOUT_RESPONSE)
.on_complete([this, show_tips, by_user, platform](std::string body, unsigned) {
try {
json versions = json::parse(body, nullptr, false);
for (auto version : versions){
if (version.contains("prerelease") && version.contains("assets") && version.contains("tag_name") && version.contains("html_url")) {
bool is_beta_version = version["prerelease"];
if (is_beta_version){
std::regex version_regex(R"((\d+)\.(\d+)\.(\d+)\.(\d+))");
std::smatch match;
std::string version_str = "";
std::string tag_name = version["tag_name"];
if (std::regex_search(tag_name, match, version_regex)) {
version_str = match[0];
}
version_info.version_str = version_str;
auto assets = version["assets"];
for (auto asset : assets){
if (asset.contains("browser_download_url")){
std::string url = asset["browser_download_url"];
if ((platform == "windows" && url.find(".exe") != std::string::npos)
|| (platform == "linux" && url.find(".AppImage") != std::string::npos)
|| (platform == "macos" && url.find(".dmg") != std::string::npos))
{
version_info.url = url;
version_info.description = "###" + std::string(version["html_url"]) + "###";
version_info.force_upgrade = false;
CallAfter([this, show_tips, by_user]() {
this->check_update(show_tips, by_user, BetaVersionUpdate);
});
return;
}
}
}
}
}
}
}
catch (...) {
;
}
})
.on_error([this](std::string body, std::string error, unsigned int status) {
handle_http_error(status, body);
BOOST_LOG_TRIVIAL(error) << "check new version error" << body;
}).perform();
}
//BBS pop up a dialog and download files
void GUI_App::request_new_version(int by_user)

View File

@ -134,6 +134,12 @@ enum CameraMenuIDs {
wxID_CAMERA_COUNT,
};
enum VersionUpdateType
{
ReleaseVersionUpdate,
BetaVersionUpdate
};
class Tab;
class ConfigWizard;
@ -455,8 +461,9 @@ public:
bool m_studio_active = true;
std::chrono::system_clock::time_point last_active_point;
void check_update(bool show_tips, int by_user);
void check_update(bool show_tips, int by_user, VersionUpdateType = ReleaseVersionUpdate);
void check_new_version(bool show_tips = false, int by_user = 0);
void check_beta_version(bool show_tips = false, int by_user = 0);
void request_new_version(int by_user);
void enter_force_upgrade();
void set_skip_version(bool skip = true);

View File

@ -1125,6 +1125,7 @@ wxWindow* PreferencesDialog::create_general_page()
auto item_calc_mode = create_item_checkbox(_L("Flushing volumes: Auto-calculate every time when the color is changed."), page, _L("If enabled, auto-calculate every time when the color is changed."), 50, "auto_calculate");
auto item_calc_in_long_retract = create_item_checkbox(_L("Flushing volumes: Auto-calculate every time when the filament is changed."), page, _L("If enabled, auto-calculate every time when filament is changed"), 50, "auto_calculate_when_filament_change");
auto item_multi_machine = create_item_checkbox(_L("Multi-device Management(Take effect after restarting Studio)."), page, _L("With this option enabled, you can send a task to multiple devices at the same time and manage multiple devices."), 50, "enable_multi_machine");
auto item_beta_version_update = create_item_checkbox(_L("Support beta version update."), page, _L("With this option enabled, you can receive beta version updates."), 50, "enable_beta_version_update");
auto _3d_settings = create_item_title(_L("3D Settings"), page, _L("3D Settings"));
auto item_mouse_zoom_settings = create_item_checkbox(_L("Zoom to mouse position"), page,
_L("Zoom in towards the mouse pointer's position in the 3D view, rather than the 2D window center."), 50,
@ -1211,6 +1212,7 @@ wxWindow* PreferencesDialog::create_general_page()
sizer_page->Add(item_calc_mode, 0, wxTOP, FromDIP(3));
sizer_page->Add(item_calc_in_long_retract, 0, wxTOP, FromDIP(3));
sizer_page->Add(item_multi_machine, 0, wxTOP, FromDIP(3));
sizer_page->Add(item_beta_version_update, 0, wxTOP, FromDIP(3));
sizer_page->Add(_3d_settings, 0, wxTOP | wxEXPAND, FromDIP(20));
sizer_page->Add(item_mouse_zoom_settings, 0, wxTOP, FromDIP(3));
sizer_page->Add(enable_lod_settings, 0, wxTOP, FromDIP(3));