diff --git a/common/background_jobs_monitor.cpp b/common/background_jobs_monitor.cpp index 5eab24eaeb..470789a2bd 100644 --- a/common/background_jobs_monitor.cpp +++ b/common/background_jobs_monitor.cpp @@ -266,7 +266,11 @@ void BACKGROUND_JOBS_MONITOR::Remove( std::shared_ptr<BACKGROUND_JOB> aJob ) return job == aJob; } ) ); - if( m_jobs.size() == 0 ) + if( m_jobs.size() > 0 ) + { + jobUpdated( m_jobs.front() ); + } + else { for( KISTATUSBAR* statusBar : m_statusBars ) { diff --git a/kicad/update_manager.cpp b/kicad/update_manager.cpp index 239b60e3ab..d854a73a75 100644 --- a/kicad/update_manager.cpp +++ b/kicad/update_manager.cpp @@ -86,6 +86,19 @@ UPDATE_MANAGER::UPDATE_MANAGER() : m_working( false ) } +UPDATE_MANAGER::~UPDATE_MANAGER() +{ + if( m_updateBackgroundJob ) + { + if( m_updateBackgroundJob->m_reporter ) + m_updateBackgroundJob->m_reporter->Cancel(); + + if( m_updateTask.valid() ) + m_updateTask.wait(); + } +} + + int UPDATE_MANAGER::PostRequest( const wxString& aUrl, std::string aRequestBody, std::ostream* aOutput, PROGRESS_REPORTER* aReporter, const size_t aSizeLimit ) @@ -165,12 +178,14 @@ void UPDATE_MANAGER::CheckForUpdate( wxWindow* aNoticeParent ) auto update_check = [aNoticeParent, this]() -> void { + std::shared_ptr<BACKGROUND_JOB_REPORTER> reporter = m_updateBackgroundJob->m_reporter; + std::stringstream update_json_stream; std::stringstream request_json_stream; wxString aUrl = UPDATE_QUERY_ENDPOINT; - m_updateBackgroundJob->m_reporter->SetNumPhases( 1 ); - m_updateBackgroundJob->m_reporter->Report( _( "Requesting update info" ) ); + reporter->SetNumPhases( 1 ); + reporter->Report( _( "Requesting update info" ) ); UPDATE_REQUEST requestContent; @@ -209,8 +224,8 @@ void UPDATE_MANAGER::CheckForUpdate( wxWindow* aNoticeParent ) nlohmann::json requestJson = nlohmann::json( requestContent ); request_json_stream << requestJson; - int responseCode = - PostRequest( aUrl, request_json_stream.str(), &update_json_stream, NULL, 20480 ); + int responseCode = PostRequest( aUrl, request_json_stream.str(), &update_json_stream, + reporter.get(), 20480 ); // Check that the response is 200 (content provided) // We can also return 204 for no update @@ -262,5 +277,5 @@ void UPDATE_MANAGER::CheckForUpdate( wxWindow* aNoticeParent ) }; thread_pool& tp = GetKiCadThreadPool(); - tp.push_task( update_check ); + m_updateTask = tp.submit( update_check ); } diff --git a/kicad/update_manager.h b/kicad/update_manager.h index b641870798..3355c59aee 100644 --- a/kicad/update_manager.h +++ b/kicad/update_manager.h @@ -25,6 +25,7 @@ #include <wx/string.h> #include <atomic> #include <memory> +#include <future> class PROGRESS_REPORTER; struct BACKGROUND_JOB; @@ -35,6 +36,7 @@ class UPDATE_MANAGER { public: UPDATE_MANAGER(); + ~UPDATE_MANAGER(); void CheckForUpdate( wxWindow* aNoticeParent ); int PostRequest( const wxString& aUrl, std::string aRequestBody, std::ostream* aOutput, @@ -43,4 +45,5 @@ public: private: std::atomic<bool> m_working; std::shared_ptr<BACKGROUND_JOB> m_updateBackgroundJob; + std::future<void> m_updateTask; }; \ No newline at end of file