mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-10-20 15:21:21 -06:00
ENH: adjust user preset handling
1. async fetch user presets from server (in thread) 2. always load default user presets 3. load user presets from cache immediately 4. not remove user presets cache 5. hide some loading ui Change-Id: I1d29ed18e09606d0b2f69a69eea2eb5042c26223
This commit is contained in:
parent
dbb5ec9115
commit
a4cf284c3d
7 changed files with 99 additions and 68 deletions
|
@ -2354,8 +2354,9 @@ bool GUI_App::on_init_inner()
|
|||
|
||||
if (app_config->get("sync_user_preset") == "true") {
|
||||
//BBS loading user preset
|
||||
BOOST_LOG_TRIVIAL(info) << "Loading user presets...";
|
||||
scrn->SetText(_L("Loading user presets..."));
|
||||
// Always async, not such startup step
|
||||
//BOOST_LOG_TRIVIAL(info) << "Loading user presets...";
|
||||
//scrn->SetText(_L("Loading user presets..."));
|
||||
if (m_agent) {
|
||||
start_sync_user_preset();
|
||||
}
|
||||
|
@ -3339,12 +3340,9 @@ void GUI_App::request_user_logout()
|
|||
|
||||
m_agent->user_logout();
|
||||
m_agent->set_user_selected_machine("");
|
||||
BOOST_LOG_TRIVIAL(info) << "preset_folder: set to empty, user_logout";
|
||||
enable_user_preset_folder(false);
|
||||
/* delete old user settings */
|
||||
m_device_manager->clean_user_info();
|
||||
GUI::wxGetApp().sidebar().load_ams_list({});
|
||||
GUI::wxGetApp().remove_user_presets();
|
||||
GUI::wxGetApp().stop_sync_user_preset();
|
||||
|
||||
#ifdef __WINDOWS__
|
||||
|
@ -3894,14 +3892,15 @@ void GUI_App::reload_settings()
|
|||
}
|
||||
}
|
||||
|
||||
//BBS reload when login
|
||||
//BBS reload when logout
|
||||
void GUI_App::remove_user_presets()
|
||||
{
|
||||
if (preset_bundle && m_agent) {
|
||||
preset_bundle->remove_users_preset(*app_config);
|
||||
|
||||
std::string user_id = m_agent->get_user_id();
|
||||
preset_bundle->remove_user_presets_directory(user_id);
|
||||
// Not remove user preset cache
|
||||
//std::string user_id = m_agent->get_user_id();
|
||||
//preset_bundle->remove_user_presets_directory(user_id);
|
||||
|
||||
//update ui
|
||||
mainframe->update_side_preset_ui();
|
||||
|
@ -4015,42 +4014,61 @@ void GUI_App::sync_preset(Preset* preset)
|
|||
}
|
||||
}
|
||||
|
||||
void GUI_App::start_sync_user_preset(bool with_progress_dlg)
|
||||
void GUI_App::start_sync_user_preset(bool load_immediately, bool with_progress_dlg)
|
||||
{
|
||||
if (!m_agent) return;
|
||||
if (!m_agent || !m_agent->is_user_login()) return;
|
||||
|
||||
enable_user_preset_folder(m_agent->is_user_login());
|
||||
enable_user_preset_folder(true);
|
||||
|
||||
// has already start sync
|
||||
if (enable_sync)
|
||||
return;
|
||||
|
||||
if (m_agent->is_user_login()) {
|
||||
// get setting list, update setting list
|
||||
std::string version = preset_bundle->get_vendor_profile_version(PresetBundle::BBL_BUNDLE).to_string();
|
||||
if (with_progress_dlg) {
|
||||
ProgressDialog dlg(_L("Loading"), "", 100, this->mainframe, wxPD_AUTO_HIDE | wxPD_APP_MODAL | wxPD_CAN_ABORT);
|
||||
dlg.Update(0, _L("Loading user preset"));
|
||||
m_agent->get_setting_list(version,
|
||||
[this, &dlg](int percent){
|
||||
dlg.Update(percent, _L("Loading user preset"));
|
||||
},
|
||||
[this, &dlg]() {
|
||||
dlg.GetValue();
|
||||
bool cont = dlg.Update(dlg.GetValue(), _L("Loading user preset"));
|
||||
return !cont;
|
||||
});
|
||||
} else {
|
||||
m_agent->get_setting_list(version);
|
||||
}
|
||||
GUI::wxGetApp().reload_settings();
|
||||
if (load_immediately) {
|
||||
preset_bundle->load_user_presets(m_agent->get_user_id(), ForwardCompatibilitySubstitutionRule::Enable);
|
||||
mainframe->update_side_preset_ui();
|
||||
}
|
||||
|
||||
ProgressFn progressFn;
|
||||
WasCancelledFn cancelFn;
|
||||
std::function<void()> finishFn;
|
||||
|
||||
if (with_progress_dlg) {
|
||||
auto dlg = new ProgressDialog(_L("Loading"), "", 100, this->mainframe, wxPD_AUTO_HIDE | wxPD_APP_MODAL | wxPD_CAN_ABORT);
|
||||
dlg->Update(0, _L("Loading user preset"));
|
||||
progressFn = [this, dlg](int percent) {
|
||||
CallAfter([=]{
|
||||
dlg->Update(percent, _L("Loading user preset"));
|
||||
});
|
||||
};
|
||||
cancelFn = [dlg]() {
|
||||
return dlg->WasCanceled();
|
||||
};
|
||||
finishFn = [this, dlg] {
|
||||
CallAfter([=]{
|
||||
dlg->Destroy();
|
||||
reload_settings();
|
||||
});
|
||||
};
|
||||
}
|
||||
else {
|
||||
finishFn = [this] {
|
||||
CallAfter([=] {
|
||||
reload_settings();
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
BOOST_LOG_TRIVIAL(info) << "start_sync_service...";
|
||||
//BBS
|
||||
enable_sync = true;
|
||||
m_sync_update_thread = Slic3r::create_thread(
|
||||
[this] {
|
||||
[this, progressFn, cancelFn, finishFn] {
|
||||
// get setting list, update setting list
|
||||
std::string version = preset_bundle->get_vendor_profile_version(PresetBundle::BBL_BUNDLE).to_string();
|
||||
m_agent->get_setting_list(version, progressFn, cancelFn);
|
||||
finishFn();
|
||||
|
||||
int count = 0, sync_count = 0;
|
||||
std::vector<Preset> presets_to_sync;
|
||||
while (enable_sync) {
|
||||
|
@ -4111,6 +4129,7 @@ void GUI_App::start_sync_user_preset(bool with_progress_dlg)
|
|||
|
||||
void GUI_App::stop_sync_user_preset()
|
||||
{
|
||||
remove_user_presets();
|
||||
enable_user_preset_folder(false);
|
||||
|
||||
if (!enable_sync)
|
||||
|
|
|
@ -421,7 +421,7 @@ public:
|
|||
void reload_settings();
|
||||
void remove_user_presets();
|
||||
void sync_preset(Preset* preset);
|
||||
void start_sync_user_preset(bool with_progress_dlg = false);
|
||||
void start_sync_user_preset(bool load_immediately = false, bool with_progress_dlg = false);
|
||||
void stop_sync_user_preset();
|
||||
|
||||
static bool catch_error(std::function<void()> cb, const std::string& err);
|
||||
|
|
|
@ -3139,7 +3139,7 @@ void MainFrame::on_select_default_preset(SimpleEvent& evt)
|
|||
{
|
||||
case wxID_YES: {
|
||||
wxGetApp().app_config->set_bool("sync_user_preset", true);
|
||||
wxGetApp().start_sync_user_preset(true);
|
||||
wxGetApp().start_sync_user_preset(true, true);
|
||||
break;
|
||||
}
|
||||
case wxID_NO:
|
||||
|
|
|
@ -608,6 +608,8 @@ bool ProgressDialog::Pulse(const wxString &newmsg, bool *skip)
|
|||
return m_state != Canceled;
|
||||
}
|
||||
|
||||
bool ProgressDialog::WasCanceled() const { return m_state == Canceled; }
|
||||
|
||||
bool ProgressDialog::DoBeforeUpdate(bool *skip)
|
||||
{
|
||||
// we have to yield because not only we want to update the display but
|
||||
|
|
|
@ -36,6 +36,7 @@ public:
|
|||
|
||||
virtual bool Update(int value, const wxString &newmsg = wxEmptyString, bool *skip = NULL);
|
||||
virtual bool Pulse(const wxString &newmsg = wxEmptyString, bool *skip = NULL);
|
||||
bool WasCanceled() const;
|
||||
|
||||
virtual void Resume();
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue