7
mirror of https://gitlab.com/kicad/code/kicad.git synced 2025-03-30 06:06:55 +00:00

Fix crash when closing project manager during KiCad update check.

Also: allow to terminate the KiCad update check.
Also: update the status label when jobs are removed.
(cherry picked from commit 19890b7f99)
This commit is contained in:
Alex Shvartzkop 2025-01-22 19:35:26 +03:00
parent e19bce2f93
commit 88b56413d5
3 changed files with 28 additions and 6 deletions

View File

@ -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 )
{

View File

@ -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 );
}

View File

@ -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;
};