FIX: presetupdater: fix the crash issue when exit app at the early stage

Change-Id: Ia6e6e56e09c5d3ebbdd7b9a8d0bb1b898d05935c
This commit is contained in:
lane.wei 2022-07-29 17:28:13 +08:00 committed by Lane.Wei
parent ab16d4c73e
commit fc659fcf2c
3 changed files with 57 additions and 39 deletions

View file

@ -1046,7 +1046,8 @@ void GUI_App::post_init()
bool cw_showed = this->config_wizard_startup();
std::string http_url = get_http_url(app_config->get_country_code());
this->preset_updater->sync(http_url, preset_bundle);
std::string language = GUI::into_u8(current_language_code());
this->preset_updater->sync(http_url, language, preset_bundle);
//BBS: check new version
this->check_new_version();

View file

@ -227,7 +227,7 @@ struct PresetUpdater::priv
void parse_version_string(const std::string& body) const;
void sync_resources(std::string http_url, std::map<std::string, Resource> &resources);
void sync_config(std::string http_url, const VendorMap vendors);
void sync_tooltip(std::string http_url);
void sync_tooltip(std::string http_url, std::string language);
//BBS: refine preset update logic
bool install_bundles_rsrc(std::vector<std::string> bundles, bool snapshot) const;
@ -278,8 +278,10 @@ bool PresetUpdater::priv::get_file(const std::string &url, const fs::path &targe
tmp_path.string());
Slic3r::Http::get(url)
.on_progress([](Slic3r::Http::Progress, bool &cancel) {
if (cancel) { cancel = true; }
.on_progress([this](Slic3r::Http::Progress, bool &cancel_http) {
if (cancel) {
cancel_http = true;
}
})
.on_error([&](std::string body, std::string error, unsigned http_status) {
(void)body;
@ -494,7 +496,12 @@ void PresetUpdater::priv::sync_resources(std::string http_url, std::map<std::str
std::string url = http_url;
url += query_params;
Slic3r::Http http = Slic3r::Http::get(url);
http.on_complete([this, &resource_list, resources](std::string body, unsigned) {
http.on_progress([this](Slic3r::Http::Progress, bool &cancel_http) {
if (cancel) {
cancel_http = true;
}
})
.on_complete([this, &resource_list, resources](std::string body, unsigned) {
try {
BOOST_LOG_TRIVIAL(trace) << "[BBL Updater]: request_resources, body=" << body;
@ -634,7 +641,12 @@ void PresetUpdater::priv::sync_config(std::string http_url, const VendorMap vend
std::string url = http_url;
url += query_params;
Slic3r::Http http = Slic3r::Http::get(url);
http.on_complete(
http.on_progress([this](Slic3r::Http::Progress, bool &cancel_http) {
if (cancel) {
cancel_http = true;
}
})
.on_complete(
[this, &vendor_list, &vendor_descriptions, vendors](std::string body, unsigned) {
try {
BOOST_LOG_TRIVIAL(trace) << "[BBL Updater]::body=" << body;
@ -778,10 +790,9 @@ void PresetUpdater::priv::sync_config(std::string http_url, const VendorMap vend
}
}
void PresetUpdater::priv::sync_tooltip(std::string http_url)
void PresetUpdater::priv::sync_tooltip(std::string http_url, std::string language)
{
try {
std::string language = GUI::into_u8(GUI::wxGetApp().current_language_code());
std::string common_version = "00.00.00.00";
std::string language_version = "00.00.00.00";
fs::path cache_root = fs::path(data_dir()) / "resources/tooltip";
@ -1054,7 +1065,7 @@ PresetUpdater::~PresetUpdater()
//BBS: change directories by design
//BBS: refine the preset updater logic
void PresetUpdater::sync(std::string http_url, PresetBundle *preset_bundle)
void PresetUpdater::sync(std::string http_url, std::string language, PresetBundle *preset_bundle)
{
//p->set_download_prefs(GUI::wxGetApp().app_config);
if (!p->enabled_version_check && !p->enabled_config_update) { return; }
@ -1064,11 +1075,17 @@ void PresetUpdater::sync(std::string http_url, PresetBundle *preset_bundle)
// into the closure (but perhaps the compiler can elide this).
VendorMap vendors = preset_bundle->vendors;
p->thread = std::thread([this, vendors, http_url]() {
p->thread = std::thread([this, vendors, http_url, language]() {
this->p->prune_tmps();
if (p->cancel)
return;
this->p->sync_version();
if (p->cancel)
return;
this->p->sync_config(http_url, std::move(vendors));
this->p->sync_tooltip(http_url);
if (p->cancel)
return;
this->p->sync_tooltip(http_url, language);
});
}

View file

@ -26,7 +26,7 @@ public:
~PresetUpdater();
// If either version check or config updating is enabled, get the appropriate data in the background and cache it.
void sync(std::string http_url, PresetBundle *preset_bundle);
void sync(std::string http_url, std::string language, PresetBundle *preset_bundle);
// If version check is enabled, check if chaced online slic3r version is newer, notify if so.
void slic3r_update_notify();