Checkpoint of app-specific single-instance checking.

(I'm about to nuke single-instance checking entirely, but wanted to
make sure this was captured in GIT somewhere.)
This commit is contained in:
Jeff Young 2021-06-20 20:06:59 +01:00
parent 8631d670a4
commit 3d7e18561d
3 changed files with 23 additions and 8 deletions

View File

@ -206,7 +206,7 @@ const wxString PGM_BASE::AskUserForPreferredEditor( const wxString& aDefaultEdit
bool PGM_BASE::InitPgm( bool aHeadless ) bool PGM_BASE::InitPgm( bool aHeadless )
{ {
wxFileName pgm_name( App().argv[0] ); wxString pgm_name = wxFileName( App().argv[0] ).GetName().Lower();
wxInitAllImageHandlers(); wxInitAllImageHandlers();
@ -219,15 +219,30 @@ bool PGM_BASE::InitPgm( bool aHeadless )
} }
#endif #endif
m_pgm_checker = new wxSingleInstanceChecker( pgm_name.GetName().Lower() + wxT( "-" ) + m_pgm_checker = new wxSingleInstanceChecker( pgm_name + wxT( "-" ) +
wxGetUserId(), GetKicadLockFilePath() ); wxGetUserId(), GetKicadLockFilePath() );
// It'd be nice to export this processing to the individual apps, but the current linkage
// makes that surprisingly difficult.
if( m_pgm_checker->IsAnotherRunning() ) if( m_pgm_checker->IsAnotherRunning() )
{ {
if( !IsOK( NULL, wxString::Format( _( "%s is already running. Continue?" ), if( pgm_name == "pcb_calculator"
App().GetAppDisplayName() ) ) ) || pgm_name == "gerbview"
|| pgm_name == "bitmap2component" )
{ {
return false; // no warning
}
else
{
if( !IsOK( NULL, wxString::Format( _( "%s is already running. Continue?\n\n"
"Saving files from more than one %s instance may "
"cause the project file to get out of sync." ),
App().GetAppDisplayName(),
App().GetAppDisplayName() ) ) )
{
return false;
}
} }
} }
@ -246,7 +261,7 @@ bool PGM_BASE::InitPgm( bool aHeadless )
// Init parameters for configuration // Init parameters for configuration
App().SetVendorName( "KiCad" ); App().SetVendorName( "KiCad" );
App().SetAppName( pgm_name.GetName().Lower() ); App().SetAppName( pgm_name );
// Install some image handlers, mainly for help // Install some image handlers, mainly for help
if( wxImage::FindHandler( wxBITMAP_TYPE_PNG ) == NULL ) if( wxImage::FindHandler( wxBITMAP_TYPE_PNG ) == NULL )

View File

@ -39,7 +39,7 @@ int main( int argc, char** argv )
{ {
wxInitialize( argc, argv ); wxInitialize( argc, argv );
Pgm().InitPgm(); Pgm().InitPgm( true );
PROPERTY_MANAGER& propMgr = PROPERTY_MANAGER::Instance(); PROPERTY_MANAGER& propMgr = PROPERTY_MANAGER::Instance();
propMgr.Rebuild(); propMgr.Rebuild();

View File

@ -254,7 +254,7 @@ int main( int argc, char** argv )
{ {
wxInitialize( argc, argv ); wxInitialize( argc, argv );
Pgm().InitPgm(); Pgm().InitPgm( true );
auto ret = wxEntry( argc, argv ); auto ret = wxEntry( argc, argv );