From ca7fbbe176ca8e989daecf4ef6f35227b737d7f5 Mon Sep 17 00:00:00 2001 From: Seth Hillbrand Date: Fri, 9 May 2025 13:31:46 -0700 Subject: [PATCH] Add wait dialog when switching projects If we are in the middle of a git operation when switching projects, wait and show the user a dialog explaining what is going on --- common/git/kicad_git_common.h | 1 + kicad/project_tree_pane.cpp | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/common/git/kicad_git_common.h b/common/git/kicad_git_common.h index 62d49c025f..886526d3e6 100644 --- a/common/git/kicad_git_common.h +++ b/common/git/kicad_git_common.h @@ -163,6 +163,7 @@ protected: friend class GIT_PUSH_HANDLER; friend class GIT_PULL_HANDLER; friend class GIT_CLONE_HANDLER; + friend class PROJECT_TREE_PANE; private: void updatePublicKeys(); diff --git a/kicad/project_tree_pane.cpp b/kicad/project_tree_pane.cpp index 5b52d57807..70d26b801c 100644 --- a/kicad/project_tree_pane.cpp +++ b/kicad/project_tree_pane.cpp @@ -53,6 +53,7 @@ #include #include #include +#include #include #include @@ -1584,6 +1585,32 @@ void PROJECT_TREE_PANE::EmptyTreePrj() // Remove the git repository when the project is unloaded if( m_TreeProject->GetGitRepo() ) { + // We need to lock the mutex to ensure that no other thread is using the git repository + std::unique_lock lock( m_TreeProject->GitCommon()->m_gitActionMutex, std::try_to_lock ); + + if( !lock.owns_lock() ) + { + // Block until any in-flight Git actions complete, showing a pulsing progress dialog + { + wxProgressDialog progress( + _("Please wait"), + _("Waiting for Git operations to finish..."), + 100, + this, + wxPD_APP_MODAL | wxPD_AUTO_HIDE | wxPD_SMOOTH + ); + + // Keep trying to acquire the lock, pulsing the dialog every 100 ms + while ( !lock.try_lock() ) + { + progress.Pulse(); + std::this_thread::sleep_for( std::chrono::milliseconds(100) ); + // allow UI events to process so dialog remains responsive + wxYield(); + } + } + } + git_repository_free( m_TreeProject->GetGitRepo() ); m_TreeProject->SetGitRepo( nullptr ); }