1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-07-13 15:17:42 +02:00

AudacityApp invokes Journal utility; new command line option -j

This commit is contained in:
Paul Licameli 2019-01-27 12:26:00 -05:00
parent 030574cdf8
commit 82d88b99e1
2 changed files with 52 additions and 4 deletions

View File

@ -82,6 +82,7 @@ It handles initialization and termination by subclassing wxApp.
#include "commands/AppCommandEvent.h" #include "commands/AppCommandEvent.h"
#include "widgets/ASlider.h" #include "widgets/ASlider.h"
#include "FFmpeg.h" #include "FFmpeg.h"
#include "Journal.h"
//#include "LangChoice.h" //#include "LangChoice.h"
#include "Languages.h" #include "Languages.h"
#include "Menus.h" #include "Menus.h"
@ -794,6 +795,8 @@ void AudacityApp::MacNewFile()
#define kAudacityAppTimerID 0 #define kAudacityAppTimerID 0
BEGIN_EVENT_TABLE(AudacityApp, wxApp) BEGIN_EVENT_TABLE(AudacityApp, wxApp)
EVT_IDLE( AudacityApp::OnIdle )
EVT_QUERY_END_SESSION(AudacityApp::OnQueryEndSession) EVT_QUERY_END_SESSION(AudacityApp::OnQueryEndSession)
EVT_END_SESSION(AudacityApp::OnEndSession) EVT_END_SESSION(AudacityApp::OnEndSession)
@ -986,10 +989,9 @@ bool AudacityApp::OnExceptionInMainLoop()
// Use CallAfter to delay this to the next pass of the event loop, // Use CallAfter to delay this to the next pass of the event loop,
// rather than risk doing it inside stack unwinding. // rather than risk doing it inside stack unwinding.
auto pProject = ::GetActiveProject(); auto pProject = ::GetActiveProject()->shared_from_this();
auto pException = std::current_exception(); auto pException = std::current_exception();
CallAfter( [=] // Capture pException by value! CallAfter( [pException, pProject] {
{
// Restore the state of the project to what it was before the // Restore the state of the project to what it was before the
// failed operation // failed operation
@ -1361,7 +1363,7 @@ bool AudacityApp::InitPart2()
// Parse command line and handle options that might require // Parse command line and handle options that might require
// immediate exit...no need to initialize all of the audio // immediate exit...no need to initialize all of the audio
// stuff to display the version string. // stuff to display the version string.
std::shared_ptr< wxCmdLineParser > parser{ ParseCommandLine().release() }; std::shared_ptr< wxCmdLineParser > parser{ ParseCommandLine() };
if (!parser) if (!parser)
{ {
// Either user requested help or a parsing error occurred // Either user requested help or a parsing error occurred
@ -1386,6 +1388,10 @@ bool AudacityApp::InitPart2()
Sequence::SetMaxDiskBlockSize(lval); Sequence::SetMaxDiskBlockSize(lval);
} }
wxString fileName;
if (parser->Found(wxT("j"), &fileName))
Journal::SetInputFileName( fileName );
// BG: Create a temporary window to set as the top window // BG: Create a temporary window to set as the top window
wxImage logoimage((const char **)AudacityLogoWithName_xpm); wxImage logoimage((const char **)AudacityLogoWithName_xpm);
logoimage.Rescale(logoimage.GetWidth() / 2, logoimage.GetHeight() / 2); logoimage.Rescale(logoimage.GetWidth() / 2, logoimage.GetHeight() / 2);
@ -1468,6 +1474,11 @@ bool AudacityApp::InitPart2()
temporarywindow.Show(false); temporarywindow.Show(false);
} }
// Must do this before creating the first project, else the early exit path
// may crash
if ( !Journal::Begin( FileNames::DataDir() ) )
return false;
// Workaround Bug 1377 - Crash after Audacity starts and low disk space warning appears // Workaround Bug 1377 - Crash after Audacity starts and low disk space warning appears
// The temporary splash window is closed AND cleaned up, before attempting to create // The temporary splash window is closed AND cleaned up, before attempting to create
// a project and possibly creating a modal warning dialog by doing so. // a project and possibly creating a modal warning dialog by doing so.
@ -1596,6 +1607,32 @@ bool AudacityApp::InitPart2()
return TRUE; return TRUE;
} }
int AudacityApp::OnRun()
{
// Returns 0 to the command line if the run completed normally
auto result = wxApp::OnRun();
if (result == 0)
// If not otherwise abnormal, report any journal sync failure
result = Journal::GetExitCode();
return result;
}
void AudacityApp::OnIdle( wxIdleEvent &evt )
{
evt.Skip();
try {
if ( Journal::Dispatch() )
evt.RequestMore();
}
catch( ... ) {
// Hmm, wxWidgets doesn't guard calls to the idle handler as for other
// events. So replicate some of the try-catch logic here.
OnExceptionInMainLoop();
// Fall through and return, allowing delayed handler action of
// AudacityException to clean up
}
}
void AudacityApp::InitCommandHandler() void AudacityApp::InitCommandHandler()
{ {
mCmdHandler = std::make_unique<CommandHandler>(); mCmdHandler = std::make_unique<CommandHandler>();
@ -2146,6 +2183,14 @@ std::unique_ptr<wxCmdLineParser> AudacityApp::ParseCommandLine()
parser->AddOption(wxT("b"), wxT("blocksize"), _("set max disk block size in bytes"), parser->AddOption(wxT("b"), wxT("blocksize"), _("set max disk block size in bytes"),
wxCMD_LINE_VAL_NUMBER); wxCMD_LINE_VAL_NUMBER);
const auto journalOptionDescription =
/*i18n-hint: brief help message for Audacity's command-line options
A journal contains a sequence of user interface interactions to be repeated
"log," "trail," "trace" have somewhat similar meanings */
_("replay a journal file");
parser->AddOption(wxT("j"), wxT("journal"), journalOptionDescription);
/*i18n-hint: This displays a list of available options */ /*i18n-hint: This displays a list of available options */
parser->AddSwitch(wxT("h"), wxT("help"), _("this help message"), parser->AddSwitch(wxT("h"), wxT("help"), _("this help message"),
wxCMD_LINE_OPTION_HELP); wxCMD_LINE_OPTION_HELP);

View File

@ -40,10 +40,13 @@ class AudacityApp final : public wxApp {
~AudacityApp(); ~AudacityApp();
bool OnInit(void) override; bool OnInit(void) override;
bool InitPart2(); bool InitPart2();
int OnRun() override;
int OnExit(void) override; int OnExit(void) override;
void OnFatalException() override; void OnFatalException() override;
bool OnExceptionInMainLoop() override; bool OnExceptionInMainLoop() override;
void OnIdle( wxIdleEvent & );
// These are currently only used on Mac OS, where it's // These are currently only used on Mac OS, where it's
// possible to have a menu bar but no windows open. It doesn't // possible to have a menu bar but no windows open. It doesn't
// hurt any other platforms, though. // hurt any other platforms, though.