From 617b909e1e2c1ecd6cc2497f0a7056404eef9a80 Mon Sep 17 00:00:00 2001 From: David Capello Date: Mon, 14 Nov 2016 17:01:41 -0300 Subject: [PATCH] Fix bug closing the app when it's saving (fix #1326) --- src/app/commands/cmd_exit.cpp | 6 ++++++ src/app/job.cpp | 14 +++++++++++++- src/app/job.h | 2 ++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/app/commands/cmd_exit.cpp b/src/app/commands/cmd_exit.cpp index b462e231f..27a1913bb 100644 --- a/src/app/commands/cmd_exit.cpp +++ b/src/app/commands/cmd_exit.cpp @@ -13,6 +13,7 @@ #include "app/commands/commands.h" #include "app/context.h" #include "app/document.h" +#include "app/job.h" #include "app/ui/main_window.h" #include "ui/alert.h" @@ -36,6 +37,11 @@ ExitCommand::ExitCommand() void ExitCommand::onExecute(Context* ctx) { + // Ignore ExitCommand when we are saving documents or doing a + // background task + if (Job::runningJobs() > 0) + return; + if (ctx->hasModifiedDocuments()) { Command* closeAll = CommandsModule::instance()->getCommandByName(CommandId::CloseAllFiles); Params params; diff --git a/src/app/job.cpp b/src/app/job.cpp index 804b8a5a5..2038ca0f9 100644 --- a/src/app/job.cpp +++ b/src/app/job.cpp @@ -19,10 +19,19 @@ #include "ui/widget.h" #include "ui/window.h" +#include + static const int kMonitoringPeriod = 100; +static std::atomic g_runningJobs(0); namespace app { +// static +int Job::runningJobs() +{ + return g_runningJobs; +} + Job::Job(const char* jobName) { m_mutex = NULL; @@ -60,6 +69,7 @@ Job::~Job() void Job::startJob() { m_thread = new base::thread(&Job::thread_proc, this); + ++g_runningJobs; if (m_alert_window) { m_alert_window->openWindowInForeground(); @@ -93,7 +103,9 @@ void Job::waitJob() if (m_thread) { m_thread->join(); delete m_thread; - m_thread = NULL; + m_thread = nullptr; + + --g_runningJobs; } } diff --git a/src/app/job.h b/src/app/job.h index d75b88cc2..e639249c2 100644 --- a/src/app/job.h +++ b/src/app/job.h @@ -24,6 +24,8 @@ namespace app { class Job { public: + static int runningJobs(); + Job(const char* jobName); virtual ~Job();