mirror of
https://git.mirrors.martin98.com/https://github.com/prusa3d/PrusaSlicer.git
synced 2025-08-16 15:16:03 +08:00
Calling archive database on startup
This commit is contained in:
parent
1cf8d0390d
commit
f1575584f2
@ -834,10 +834,10 @@ void GUI_App::post_init()
|
||||
return;
|
||||
#endif
|
||||
CallAfter([this] {
|
||||
// preset_updater->sync downloads profile updates on background so it must begin after config wizard finished.
|
||||
// its call was moved to start_preset_updater method
|
||||
bool cw_showed = this->config_wizard_startup();
|
||||
if (! cw_showed) {
|
||||
// preset_updater->sync downloads profile updates on background so it must begin after config wizard finished.
|
||||
this->preset_updater->sync(preset_bundle, this, plater()->get_preset_archive_database()->get_archive_repositories(), plater()->get_preset_archive_database()->get_selected_repositories_uuid());
|
||||
// The CallAfter is needed as well, without it, GL extensions did not show.
|
||||
// Also, we only want to show this when the wizard does not, so the new user
|
||||
// sees something else than "we want something" on the first start.
|
||||
@ -3161,6 +3161,8 @@ bool GUI_App::run_wizard(ConfigWizard::RunReason reason, ConfigWizard::StartPage
|
||||
plater()->get_preset_archive_database()->sync_blocking();
|
||||
}
|
||||
#endif // 0
|
||||
plater()->get_preset_archive_database()->set_wizard_lock(true);
|
||||
plater()->get_preset_archive_database()->sync_blocking();
|
||||
// Do blocking sync on every start of wizard, so user is always offered recent profiles.
|
||||
preset_updater->sync_blocking(preset_bundle, this, plater()->get_preset_archive_database()->get_archive_repositories(), plater()->get_preset_archive_database()->get_selected_repositories_uuid());
|
||||
// Offer update installation (of already installed profiles) only when run by user.
|
||||
@ -3187,7 +3189,7 @@ bool GUI_App::run_wizard(ConfigWizard::RunReason reason, ConfigWizard::StartPage
|
||||
if (preset_bundle->printers.get_edited_preset().printer_technology() == ptSLA)
|
||||
may_switch_to_SLA_preset(_L("Configuration is editing from ConfigWizard"));
|
||||
}
|
||||
|
||||
plater()->get_preset_archive_database()->set_wizard_lock(false);
|
||||
return res;
|
||||
}
|
||||
|
||||
@ -3873,7 +3875,7 @@ void GUI_App::show_printer_webview_tab()
|
||||
{
|
||||
mainframe->show_printer_webview_tab(preset_bundle->physical_printers.get_selected_printer_config());
|
||||
}
|
||||
|
||||
/*
|
||||
void GUI_App::start_preset_updater(bool forced)
|
||||
{
|
||||
if (m_started_preset_updater && !forced) {
|
||||
@ -3883,5 +3885,6 @@ void GUI_App::start_preset_updater(bool forced)
|
||||
this->preset_updater->sync(preset_bundle, this, plater()->get_preset_archive_database()->get_archive_repositories(), plater()->get_preset_archive_database()->get_selected_repositories_uuid());
|
||||
m_started_preset_updater = true;
|
||||
}
|
||||
*/
|
||||
} // GUI
|
||||
} //Slic3r
|
||||
|
@ -428,8 +428,6 @@ public:
|
||||
void request_open_project(std::string project_id) {}
|
||||
void request_remove_project(std::string project_id) {}
|
||||
|
||||
void start_preset_updater(bool forced);
|
||||
|
||||
private:
|
||||
bool on_init_inner();
|
||||
void init_app_config();
|
||||
@ -454,7 +452,6 @@ private:
|
||||
|
||||
bool m_wifi_config_dialog_shown { false };
|
||||
bool m_wifi_config_dialog_was_declined { false };
|
||||
bool m_started_preset_updater { false };
|
||||
// change to vector of items when adding more items that require update
|
||||
//wxMenuItem* m_login_config_menu_item { nullptr };
|
||||
std::map< ConfigMenuIDs, wxMenuItem*> m_config_menu_updatable_items;
|
||||
|
@ -906,8 +906,8 @@ Plater::priv::priv(Plater *q, MainFrame *main_frame)
|
||||
wxGetApp().update_login_dialog();
|
||||
#endif // 0
|
||||
this->show_action_buttons(this->ready_to_slice);
|
||||
preset_archive_database->set_token("ABCD");
|
||||
preset_archive_database->sync();
|
||||
preset_archive_database->set_access_token(user_account->get_access_token());
|
||||
|
||||
} else {
|
||||
// data were corrupt and username was not retrieved
|
||||
// procced as if EVT_UA_RESET was recieved
|
||||
@ -920,6 +920,7 @@ Plater::priv::priv(Plater *q, MainFrame *main_frame)
|
||||
this->main_frame->refresh_account_menu(true);
|
||||
// Update sidebar printer status
|
||||
sidebar->update_printer_presets_combobox();
|
||||
preset_archive_database->set_access_token({});
|
||||
}
|
||||
|
||||
});
|
||||
@ -933,9 +934,8 @@ Plater::priv::priv(Plater *q, MainFrame *main_frame)
|
||||
this->main_frame->refresh_account_menu(true);
|
||||
// Update sidebar printer status
|
||||
sidebar->update_printer_presets_combobox();
|
||||
preset_archive_database->set_token({});
|
||||
preset_archive_database->sync();
|
||||
});
|
||||
preset_archive_database->set_access_token({});
|
||||
});
|
||||
this->q->Bind(EVT_UA_FAIL, [this](UserAccountFailEvent& evt) {
|
||||
BOOST_LOG_TRIVIAL(error) << "Failed communication with Prusa Account: " << evt.data;
|
||||
user_account->on_communication_fail();
|
||||
@ -993,11 +993,6 @@ Plater::priv::priv(Plater *q, MainFrame *main_frame)
|
||||
});
|
||||
}
|
||||
|
||||
this->q->Bind(EVT_PRESET_ARCHIVE_DATABASE_SYNC_DONE, [this](Event<ArchiveRepositorySyncData>& evt) {
|
||||
preset_archive_database->read_server_manifest(evt.data.json);
|
||||
wxGetApp().start_preset_updater(evt.data.force_updater);
|
||||
});
|
||||
|
||||
wxGetApp().other_instance_message_handler()->init(this->q);
|
||||
|
||||
// collapse sidebar according to saved value
|
||||
|
@ -26,8 +26,6 @@ namespace fs = boost::filesystem;
|
||||
namespace Slic3r {
|
||||
namespace GUI {
|
||||
|
||||
wxDEFINE_EVENT(EVT_PRESET_ARCHIVE_DATABASE_SYNC_DONE, Event<ArchiveRepositorySyncData>);
|
||||
|
||||
static const char* TMP_EXTENSION = ".download";
|
||||
|
||||
namespace {
|
||||
@ -99,7 +97,6 @@ bool extract_repository_header(const pt::ptree& ptree, ArchiveRepository::Reposi
|
||||
}
|
||||
if (const auto visibility = ptree.get_optional<std::string>("visibility"); visibility) {
|
||||
data.visibility = *visibility;
|
||||
data.m_secret = data.visibility.empty();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@ -226,6 +223,7 @@ bool OnlineArchiveRepository::get_file_inner(const std::string& url, const fs::p
|
||||
auto http = Http::get(url);
|
||||
add_authorization_header(http);
|
||||
http
|
||||
.timeout_max(30)
|
||||
.on_progress([](Http::Progress, bool& cancel) {
|
||||
//if (cancel) { cancel = true; }
|
||||
})
|
||||
@ -626,7 +624,7 @@ std::string PresetArchiveDatabase::get_next_uuid()
|
||||
}
|
||||
|
||||
namespace {
|
||||
bool sync_inner(std::string& manifest)
|
||||
bool sync_inner(const std::string& token, std::string& manifest)
|
||||
{
|
||||
bool ret = false;
|
||||
#ifdef SLIC3R_REPO_URL
|
||||
@ -634,9 +632,11 @@ bool sync_inner(std::string& manifest)
|
||||
#else
|
||||
std::string url = "http://10.24.3.3:8001/v1/repos";
|
||||
#endif
|
||||
// TODO: use token
|
||||
auto http = Http::get(std::move(url));
|
||||
add_authorization_header(http);
|
||||
http
|
||||
.timeout_max(30)
|
||||
.on_error([&](std::string body, std::string error, unsigned http_status) {
|
||||
BOOST_LOG_TRIVIAL(error) << "Failed to get online archive repository manifests: "<< body << " ; " << error << " ; " << http_status;
|
||||
ret = false;
|
||||
@ -649,27 +649,33 @@ bool sync_inner(std::string& manifest)
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void PresetArchiveDatabase::sync()
|
||||
/*
|
||||
bool PresetArchiveDatabase::sync_blocking_with_token(const std::string& user_account_token)
|
||||
{
|
||||
|
||||
std::thread thread([this]() {
|
||||
std::string manifest;
|
||||
if (!sync_inner(manifest))
|
||||
return;
|
||||
// Force update when logged in (token not empty).
|
||||
wxQueueEvent(this->p_evt_handler, new Event<ArchiveRepositorySyncData>(EVT_PRESET_ARCHIVE_DATABASE_SYNC_DONE, {std::move(manifest), !m_token.empty()}));
|
||||
});
|
||||
thread.join();
|
||||
bool ret_val = m_token != user_account_token && !user_account_token.empty();
|
||||
m_token = user_account_token;
|
||||
sync_blocking();
|
||||
return ret_val;
|
||||
}
|
||||
|
||||
*/
|
||||
void PresetArchiveDatabase::sync_blocking()
|
||||
{
|
||||
if (m_wizard_lock) {
|
||||
m_staged_sync = true;
|
||||
}
|
||||
std::string manifest;
|
||||
if (!sync_inner(manifest))
|
||||
if (!sync_inner(m_token, manifest))
|
||||
return;
|
||||
read_server_manifest(std::move(manifest));
|
||||
}
|
||||
|
||||
void PresetArchiveDatabase::set_wizard_lock(bool lock)
|
||||
{
|
||||
m_wizard_lock = lock;
|
||||
if (m_staged_sync) {
|
||||
sync_blocking();
|
||||
}
|
||||
m_staged_sync = false;
|
||||
}
|
||||
|
||||
}} // Slic3r::GUI
|
@ -17,15 +17,6 @@ namespace Slic3r {
|
||||
class AppConfig;
|
||||
namespace GUI {
|
||||
|
||||
struct ArchiveRepositorySyncData
|
||||
{
|
||||
std::string json;
|
||||
bool force_updater;
|
||||
};
|
||||
|
||||
wxDECLARE_EVENT(EVT_PRESET_ARCHIVE_DATABASE_SYNC_DONE, Event<ArchiveRepositorySyncData>);
|
||||
|
||||
|
||||
struct ArchiveRepositoryGetFileArgs {
|
||||
boost::filesystem::path target_path;
|
||||
|
||||
@ -47,7 +38,6 @@ public:
|
||||
// not read from manifest json
|
||||
boost::filesystem::path tmp_path; // Where archive is unzziped. Created each app run.
|
||||
boost::filesystem::path source_path; // Path given by user. Stored between app runs.
|
||||
bool m_secret { false };
|
||||
};
|
||||
// Use std::move when calling constructor.
|
||||
ArchiveRepository(const std::string& uuid, RepositoryManifest&& data) : m_data(std::move(data)), m_uuid(uuid) {}
|
||||
@ -112,15 +102,19 @@ public:
|
||||
~PresetArchiveDatabase() {}
|
||||
|
||||
const ArchiveRepositoryVector& get_archive_repositories() const { return m_archive_repositories; }
|
||||
void sync();
|
||||
// Sync does download manifest for online repos.
|
||||
// returns true if preset update should be forced - if access token has changed, there might be new repositories or it is a first call
|
||||
//bool sync_blocking_with_token(const std::string& user_account_token);
|
||||
void set_access_token(const std::string& token) { m_token = token; }
|
||||
void sync_blocking();
|
||||
void set_token(const std::string token) { m_token = token; }
|
||||
//void set_local_archives(AppConfig* app_config);
|
||||
void read_server_manifest(const std::string& json_body);
|
||||
const std::map<std::string, bool>& get_selected_repositories_uuid() const { assert(m_selected_repositories_uuid.size() == m_archive_repositories.size()); return m_selected_repositories_uuid; }
|
||||
bool set_selected_repositories(const std::vector<std::string>& used_uuids, std::string& msg);
|
||||
std::string add_local_archive(const boost::filesystem::path path, std::string& msg);
|
||||
void remove_local_archive(const std::string& uuid);
|
||||
// should be called only from main UI thread.
|
||||
void set_wizard_lock(bool lock);
|
||||
private:
|
||||
void load_app_manifest_json();
|
||||
void save_app_manifest_json() const;
|
||||
@ -135,6 +129,8 @@ private:
|
||||
std::map<std::string, bool> m_selected_repositories_uuid;
|
||||
std::string m_token;
|
||||
boost::uuids::random_generator m_uuid_generator;
|
||||
bool m_wizard_lock { false };
|
||||
bool m_staged_sync { false };
|
||||
};
|
||||
|
||||
}} // Slic3r::GUI
|
||||
|
Loading…
x
Reference in New Issue
Block a user