Merge branch 'lm_jb_osx_quick_quit_crash_fix' (SPE-2560)

This commit is contained in:
Lukas Matena 2024-11-20 07:52:28 +01:00
commit fac23c17d2
5 changed files with 90 additions and 58 deletions

View File

@ -714,9 +714,9 @@ void MainFrame::init_tabpanel()
});
m_plater = new Plater(this, this);
wxGetApp().plater_ = m_plater;
m_plater->Hide();
wxGetApp().plater_ = m_plater;
if (wxGetApp().is_editor())
create_preset_tabs();

View File

@ -182,12 +182,15 @@ std::string escape_path_by_element(const std::string& path_string)
return ret_val;
}
void add_authorization_header(Http& http)
bool add_authorization_header(Http& http)
{
if (wxApp::GetInstance() == nullptr || ! GUI::wxGetApp().plater())
return false;
const std::string access_token = GUI::wxGetApp().plater()->get_user_account()->get_access_token();
if (!access_token.empty()) {
http.header("Authorization", "Bearer " + access_token);
}
return true;
}
}
@ -204,7 +207,8 @@ bool OnlineArchiveRepository::get_file_inner(const std::string& url, const fs::p
tmp_path.string());
auto http = Http::get(url);
add_authorization_header(http);
if (!add_authorization_header(http))
return false;
http
.timeout_max(30)
.on_progress([](Http::Progress, bool& cancel) {
@ -881,7 +885,8 @@ bool sync_inner(std::string& manifest, PresetUpdaterUIStatus* ui_status)
bool ret = false;
std::string url = Utils::ServiceConfig::instance().preset_repo_repos_url();
auto http = Http::get(std::move(url));
add_authorization_header(http);
if (!add_authorization_header(http))
return false;
http
.timeout_max(30)
.on_error([&](std::string body, std::string error, unsigned http_status) {

View File

@ -46,9 +46,12 @@ void ProjectDirtyStateManager::update_from_presets()
void ProjectDirtyStateManager::update_from_preview()
{
if (wxApp::GetInstance() == nullptr || wxGetApp().plater() == nullptr)
return;
const bool is_dirty = m_initial_custom_gcode_per_print_z != wxGetApp().model().custom_gcode_per_print_z;
if (m_custom_gcode_per_print_z_dirty != is_dirty) {
m_custom_gcode_per_print_z_dirty = is_dirty;
if (wxApp::GetInstance() != nullptr)
wxGetApp().mainframe->update_title();
}
}

View File

@ -49,6 +49,7 @@ namespace {
BOOST_LOG_TRIVIAL(error) << full_message;
wxCommandEvent* evt = new wxCommandEvent(EVT_SLIC3R_APP_DOWNLOAD_FAILED);
evt->SetString(full_message);
if (wxApp::GetInstance() != nullptr)
GUI::wxGetApp().QueueEvent(evt);
}
return res;
@ -215,6 +216,7 @@ boost::filesystem::path AppUpdater::priv::download_file(const DownloadAppData& d
BOOST_LOG_TRIVIAL(error) << message;
wxCommandEvent* evt = new wxCommandEvent(EVT_SLIC3R_APP_DOWNLOAD_FAILED);
evt->SetString(message);
if (wxApp::GetInstance() != nullptr)
GUI::wxGetApp().QueueEvent(evt);
return boost::filesystem::path();
}
@ -229,9 +231,11 @@ boost::filesystem::path AppUpdater::priv::download_file(const DownloadAppData& d
std::string line2 = GUI::format(_u8L("Can't create file at %1%"), tmp_path.string());
std::string message = GUI::format("%1%\n%2%", line1, line2);
BOOST_LOG_TRIVIAL(error) << message;
wxCommandEvent* evt = new wxCommandEvent(EVT_SLIC3R_APP_DOWNLOAD_FAILED);
if (wxApp::GetInstance() != nullptr) {
wxCommandEvent *evt = new wxCommandEvent(EVT_SLIC3R_APP_DOWNLOAD_FAILED);
evt->SetString(message);
GUI::wxGetApp().QueueEvent(evt);
}
return boost::filesystem::path();
}
@ -243,9 +247,11 @@ boost::filesystem::path AppUpdater::priv::download_file(const DownloadAppData& d
if (progress.dltotal > 0 && progress.dltotal > expected_size) {
std::string message = GUI::format("Downloading new %1% has failed. The file has incorrect file size. Aborting download.\nExpected size: %2%\nDownload size: %3%", SLIC3R_APP_NAME, expected_size, progress.dltotal);
BOOST_LOG_TRIVIAL(error) << message;
wxCommandEvent* evt = new wxCommandEvent(EVT_SLIC3R_APP_DOWNLOAD_FAILED);
if (wxApp::GetInstance() != nullptr) {
wxCommandEvent *evt = new wxCommandEvent(EVT_SLIC3R_APP_DOWNLOAD_FAILED);
evt->SetString(message);
GUI::wxGetApp().QueueEvent(evt);
}
return false;
} else if (progress.dltotal > 0 && progress.dltotal < expected_size) {
// This is possible error, but we cannot know until the download is finished. Somehow the total size can grow during the download.
@ -256,9 +262,11 @@ boost::filesystem::path AppUpdater::priv::download_file(const DownloadAppData& d
BOOST_LOG_TRIVIAL(debug) << "App download " << gui_progress << "% " << progress.dlnow << " of " << progress.dltotal;
if (last_gui_progress < gui_progress && (last_gui_progress != 0 || gui_progress != 100)) {
last_gui_progress = gui_progress;
wxCommandEvent* evt = new wxCommandEvent(EVT_SLIC3R_APP_DOWNLOAD_PROGRESS);
if (wxApp::GetInstance() != nullptr) {
wxCommandEvent *evt = new wxCommandEvent(EVT_SLIC3R_APP_DOWNLOAD_PROGRESS);
evt->SetString(GUI::from_u8(std::to_string(gui_progress)));
GUI::wxGetApp().QueueEvent(evt);
}
}
return true;
}
@ -293,18 +301,23 @@ boost::filesystem::path AppUpdater::priv::download_file(const DownloadAppData& d
{
if (m_cancel) {
BOOST_LOG_TRIVIAL(info) << error_message;
wxCommandEvent* evt = new wxCommandEvent(EVT_SLIC3R_APP_DOWNLOAD_FAILED); // FAILED with empty msg only closes progress notification
if (wxApp::GetInstance() != nullptr) {
wxCommandEvent *evt = new wxCommandEvent(EVT_SLIC3R_APP_DOWNLOAD_FAILED
); // FAILED with empty msg only closes progress notification
GUI::wxGetApp().QueueEvent(evt);
}
} else {
std::string message = (error_message.empty()
? std::string()
: GUI::format(_u8L("Downloading new %1% has failed:\n%2%"), SLIC3R_APP_NAME, error_message));
wxCommandEvent* evt = new wxCommandEvent(EVT_SLIC3R_APP_DOWNLOAD_FAILED);
if (wxApp::GetInstance() != nullptr) {
wxCommandEvent *evt = new wxCommandEvent(EVT_SLIC3R_APP_DOWNLOAD_FAILED);
if (!message.empty()) {
BOOST_LOG_TRIVIAL(error) << message;
evt->SetString(message);
}
GUI::wxGetApp().QueueEvent(evt);
}
}
return boost::filesystem::path();
}
@ -336,7 +349,7 @@ void AppUpdater::priv::version_check(const std::string& version_check_url)
if (!res) {
std::string message = GUI::format("Downloading %1% version file has failed:\n%2%", SLIC3R_APP_NAME, error_message);
BOOST_LOG_TRIVIAL(error) << message;
if (m_triggered_by_user) {
if (m_triggered_by_user && wxApp::GetInstance() != nullptr) {
wxCommandEvent* evt = new wxCommandEvent(EVT_SLIC3R_APP_DOWNLOAD_FAILED);
evt->SetString(message);
GUI::wxGetApp().QueueEvent(evt);
@ -356,9 +369,11 @@ void AppUpdater::priv::parse_version_string(const std::string& body)
BOOST_LOG_TRIVIAL(error) << "Could not find property tree in version file. Checking for application update has failed.";
// Lets send event with current version, this way if user triggered this check, it will notify him about no new version online.
std::string version = Semver().to_string();
wxCommandEvent* evt = new wxCommandEvent(EVT_SLIC3R_VERSION_ONLINE);
if (wxApp::GetInstance() != nullptr) {
wxCommandEvent *evt = new wxCommandEvent(EVT_SLIC3R_VERSION_ONLINE);
evt->SetString(GUI::from_u8(version));
GUI::wxGetApp().QueueEvent(evt);
}
return;
}
std::string tree_string = body.substr(start);
@ -444,7 +459,7 @@ void AppUpdater::priv::parse_version_string(const std::string& body)
}
}
// send prerelease version to UI layer
if (recent_version) {
if (recent_version && wxApp::GetInstance() != nullptr) {
BOOST_LOG_TRIVIAL(info) << format("Got %1% online version: `%2%`. Sending to GUI thread...", SLIC3R_APP_NAME, version_string);
wxCommandEvent* evt = new wxCommandEvent(EVT_SLIC3R_EXPERIMENTAL_VERSION_ONLINE);
evt->SetString(GUI::from_u8(version_string));
@ -459,9 +474,11 @@ void AppUpdater::priv::parse_version_string(const std::string& body)
// send
std::string version = new_data.version.get().to_string();
BOOST_LOG_TRIVIAL(info) << format("Got %1% online version: `%2%`. Sending to GUI thread...", SLIC3R_APP_NAME, version);
wxCommandEvent* evt = new wxCommandEvent(EVT_SLIC3R_VERSION_ONLINE);
if (wxApp::GetInstance() != nullptr) {
wxCommandEvent *evt = new wxCommandEvent(EVT_SLIC3R_VERSION_ONLINE);
evt->SetString(GUI::from_u8(version));
GUI::wxGetApp().QueueEvent(evt);
}
}
#if 0 //lm:is this meant to be ressurected? //dk: it is code that parses PrusaSlicer.version2 in 2.4.0, It was deleted from PresetUpdater.cpp and I would keep it here for possible reference.
@ -481,9 +498,11 @@ void AppUpdater::priv::parse_version_string_old(const std::string& body) const
return;
}
BOOST_LOG_TRIVIAL(info) << format("Got %1% online version: `%2%`. Sending to GUI thread...", SLIC3R_APP_NAME, version);
if (wxApp::GetInstance() != nullptr) {
wxCommandEvent* evt = new wxCommandEvent(EVT_SLIC3R_VERSION_ONLINE);
evt->SetString(GUI::from_u8(version));
GUI::wxGetApp().QueueEvent(evt);
}
// alpha / beta version
std::vector<std::string> prerelease_versions;
@ -525,7 +544,7 @@ void AppUpdater::priv::parse_version_string_old(const std::string& body) const
version = ver_string;
}
}
if (recent_version) {
if (recent_version && wxApp::GetInstance() != nullptr) {
BOOST_LOG_TRIVIAL(info) << format("Got %1% online version: `%2%`. Sending to GUI thread...", SLIC3R_APP_NAME, version);
wxCommandEvent* evt = new wxCommandEvent(EVT_SLIC3R_EXPERIMENTAL_VERSION_ONLINE);
evt->SetString(GUI::from_u8(version));

View File

@ -1186,6 +1186,11 @@ PresetUpdater::UpdateResult PresetUpdater::config_update(const Semver& old_slic3
}
}
if (!wxApp::GetInstance() || ! GUI::wxGetApp().plater()) {
// The main thread might have start killing the UI.
return R_NOOP;
}
// regular update
if (params == UpdateParams::SHOW_NOTIFICATION) {
p->set_waiting_updates(updates);